Skip to content

Commit

Permalink
Merge pull request #48 from alexmaco/grace
Browse files Browse the repository at this point in the history
Implement grace period for process selection
  • Loading branch information
bvaisvil committed Jun 5, 2020
2 parents 2aff776 + 5f67069 commit d022282
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 197 deletions.
32 changes: 17 additions & 15 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ pub struct CPUTimeApp {
pub network_interfaces: Vec<NetworkInterface>,
pub sensors: Vec<Sensor>,
pub gfx_devices: Vec<GFXDevice>,
pub tick: Duration,
pub processor_name: String,
pub started: chrono::DateTime<chrono::Local>,
pub selected_process: Option<ZProcess>,
Expand All @@ -404,7 +403,6 @@ impl CPUTimeApp {
let histogram_map = HistogramMap::new(Duration::from_secs(60 * 60 * 24), tick, db);
let mut s = CPUTimeApp {
histogram_map,
tick,
cpus: vec![],
system: System::new(),
cpu_utilization: 0,
Expand Down Expand Up @@ -493,7 +491,7 @@ impl CPUTimeApp {
debug!("Updating Network Interfaces");
self.network_interfaces.clear();
let nics = net::nic().await;
match nics{
match nics {
Ok(nics) => {
::futures::pin_mut!(nics);
while let Some(n) = nics.next().await {
Expand All @@ -512,8 +510,8 @@ impl CPUTimeApp {
Address::Inet(n) => n.to_string(),
_ => format!(""),
}
.trim_end_matches(":0")
.to_string();
.trim_end_matches(":0")
.to_string();
if ip.is_empty() {
continue;
}
Expand All @@ -533,11 +531,9 @@ impl CPUTimeApp {
Err(_) => println!("Couldn't get information on a nic"),
}
}
},
Err(_) => {debug!("Couldn't get nic information")}
}
Err(_) => debug!("Couldn't get nic information"),
}


}

#[cfg(not(all(target_os = "linux", feature = "nvidia")))]
Expand Down Expand Up @@ -680,9 +676,8 @@ impl CPUTimeApp {
}
}

fn update_process_list(&mut self) {
fn update_process_list(&mut self, keep_order: bool) {
debug!("Updating Process List");
self.processes.clear();
let process_list = self.system.get_process_list();
let mut current_pids: HashSet<i32> = HashSet::with_capacity(process_list.len());
let mut top_pid: Option<i32> = None;
Expand Down Expand Up @@ -774,10 +769,15 @@ impl CPUTimeApp {
}
self.process_map.insert(zprocess.pid, zprocess);
}
self.processes.push(*pid);
current_pids.insert(*pid);
}

if keep_order {
self.processes.retain(|pid| current_pids.contains(pid));
} else {
self.processes = current_pids.iter().cloned().collect();
}

// remove pids that are gone
self.process_map.retain(|&k, _| current_pids.contains(&k));

Expand Down Expand Up @@ -822,7 +822,9 @@ impl CPUTimeApp {
}
}

self.sort_process_table();
if !keep_order {
self.sort_process_table();
}
}

pub fn sort_process_table(&mut self) {
Expand Down Expand Up @@ -972,7 +974,7 @@ impl CPUTimeApp {
.add_value_to("cpu_usage_histogram", self.cpu_utilization);
}

pub async fn update(&mut self, width: u16) {
pub async fn update(&mut self, width: u16, keep_order: bool) {
debug!("Updating Metrics");
self.system.refresh_all();
self.update_cpu().await;
Expand All @@ -998,7 +1000,7 @@ impl CPUTimeApp {
self.net_out = net.get_outcome();
self.histogram_map.add_value_to("net_in", self.net_in);
self.histogram_map.add_value_to("net_out", self.net_out);
self.update_process_list();
self.update_process_list(keep_order);
self.update_frequency().await;
self.update_disk(width);
self.get_platform().await;
Expand Down

0 comments on commit d022282

Please sign in to comment.