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
- Ellipsis
- Rebalance cpu usage in process by using current value (it's currently just summing to 100%)
- Tests

View File

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

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 highlighted_border_style : Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
terminal.autoresize()?;
terminal.draw(|mut f| {
//debug!("Drawing!");
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 y_axis = Axis::default()
.style(Style::default().fg(GRAPH_COLOUR))
.bounds([-0.5, 100.5])
.labels(&["0%", "100%"]); // Offset as the zero value isn't drawn otherwise...
.bounds([-0.5, 100.5]) // Offset as the zero value isn't drawn otherwise...
.labels(&["0%", "100%"]);
let mem_name = "RAM:".to_string()
+ &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].1 as f64 / 1024.0
);
let swap_name;
let swap_name : String;
let mut mem_canvas_vec : Vec<Dataset> = vec![Dataset::default()
.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!
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 DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000;

View File

@ -154,7 +154,7 @@ fn main() -> error::Result<()> {
// Event loop
let mut data_state = data_collection::DataState::default();
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());
{
let tx = tx.clone();