Fix for cleaning times, as well as made it not run every loop.

This commit is contained in:
ClementTsang 2019-10-09 19:19:39 -04:00
parent f55d2fff3f
commit 2d20ec7f6f
5 changed files with 62 additions and 61 deletions

View File

@ -22,6 +22,8 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
## Less important ## Less important
- Ellipsis
- Rebalance cpu usage in process by using current value (it's currently just summing to 100%) - Rebalance cpu usage in process by using current value (it's currently just summing to 100%)
- Tests - Tests

View File

@ -44,6 +44,7 @@ pub struct DataState {
prev_idle : f64, prev_idle : f64,
prev_non_idle : f64, prev_non_idle : f64,
temperature_type : temperature::TemperatureType, temperature_type : temperature::TemperatureType,
last_clean : Instant, // Last time stale data was cleared
} }
impl Default for DataState { impl Default for DataState {
@ -57,6 +58,7 @@ impl Default for DataState {
prev_idle : 0_f64, prev_idle : 0_f64,
prev_non_idle : 0_f64, prev_non_idle : 0_f64,
temperature_type : temperature::TemperatureType::Celsius, temperature_type : temperature::TemperatureType::Celsius,
last_clean : Instant::now(),
} }
} }
} }
@ -113,6 +115,7 @@ impl DataState {
// Filter out stale timed entries // Filter out stale timed entries
let current_instant = std::time::Instant::now(); let current_instant = std::time::Instant::now();
if current_instant.duration_since(self.last_clean).as_secs() > self.stale_max_seconds {
let stale_list : Vec<_> = self let stale_list : Vec<_> = self
.prev_pid_stats .prev_pid_stats
.iter() .iter()
@ -120,7 +123,6 @@ impl DataState {
.map(|(k, _)| k.clone()) .map(|(k, _)| k.clone())
.collect(); .collect();
for stale in stale_list { for stale in stale_list {
debug!("Removing: {:?}", self.prev_pid_stats[&stale]);
self.prev_pid_stats.remove(&stale); self.prev_pid_stats.remove(&stale);
} }
@ -164,13 +166,8 @@ impl DataState {
.filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// self.data.list_of_physical_io = self self.last_clean = current_instant;
// .data }
// .list_of_physical_io
// .iter()
// .cloned()
// .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds)
// .collect::<Vec<_>>();
debug!("End updating..."); debug!("End updating...");
} }

View File

@ -40,6 +40,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
let border_style : Style = Style::default().fg(BORDER_STYLE_COLOUR); let border_style : Style = Style::default().fg(BORDER_STYLE_COLOUR);
let highlighted_border_style : Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR); let highlighted_border_style : Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
terminal.autoresize()?;
terminal.draw(|mut f| { terminal.draw(|mut f| {
//debug!("Drawing!"); //debug!("Drawing!");
let vertical_chunks = Layout::default() let vertical_chunks = Layout::default()
@ -129,8 +130,8 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]); let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
let y_axis = Axis::default() let y_axis = Axis::default()
.style(Style::default().fg(GRAPH_COLOUR)) .style(Style::default().fg(GRAPH_COLOUR))
.bounds([-0.5, 100.5]) .bounds([-0.5, 100.5]) // Offset as the zero value isn't drawn otherwise...
.labels(&["0%", "100%"]); // Offset as the zero value isn't drawn otherwise... .labels(&["0%", "100%"]);
let mem_name = "RAM:".to_string() let mem_name = "RAM:".to_string()
+ &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)) + &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
@ -139,7 +140,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
canvas_data.mem_values[0].0 as f64 / 1024.0, canvas_data.mem_values[0].0 as f64 / 1024.0,
canvas_data.mem_values[0].1 as f64 / 1024.0 canvas_data.mem_values[0].1 as f64 / 1024.0
); );
let swap_name; let swap_name : String;
let mut mem_canvas_vec : Vec<Dataset> = vec![Dataset::default() let mut mem_canvas_vec : Vec<Dataset> = vec![Dataset::default()
.name(&mem_name) .name(&mem_name)

View File

@ -1,4 +1,5 @@
// TODO: Store like three minutes of data, then change how much is shown based on scaling! // TODO: Store like three minutes of data, then change how much is shown based on scaling!
pub const STALE_MAX_MILLISECONDS : u64 = 60 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable. pub const STALE_MAX_MILLISECONDS : u64 = 60 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable.
pub const _TIME_STARTS_FROM : u64 = 60 * 1000;
pub const TICK_RATE_IN_MILLISECONDS : u64 = 200; // We use this as it's a good value to work with. pub const TICK_RATE_IN_MILLISECONDS : u64 = 200; // We use this as it's a good value to work with.
pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000; pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000;

View File

@ -154,7 +154,7 @@ fn main() -> error::Result<()> {
// Event loop // Event loop
let mut data_state = data_collection::DataState::default(); let mut data_state = data_collection::DataState::default();
data_state.init(); data_state.init();
data_state.set_stale_max_seconds(STALE_MAX_MILLISECONDS); data_state.set_stale_max_seconds(STALE_MAX_MILLISECONDS / 1000);
data_state.set_temperature_type(app.temperature_type.clone()); data_state.set_temperature_type(app.temperature_type.clone());
{ {
let tx = tx.clone(); let tx = tx.clone();