Skip to content

Commit

Permalink
fix: too much processes where deleted at once
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetit committed Dec 22, 2020
1 parent 6e48e95 commit 33a451c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async fn show_metrics(data: web::Data<PowerMetrics>) -> impl Responder {
String::from(metric_name),
format_metric(metric_name, &metric_value.to_string(), None),
);
}
}

let metric_gathering = procfs::process::Process::myself().unwrap().statm();
if let Ok(metric_value) = metric_gathering {
Expand Down Expand Up @@ -270,8 +270,7 @@ async fn show_metrics(data: web::Data<PowerMetrics>) -> impl Responder {
body,
String::from("Number of energy consumption Records stored for each socket"),
String::from("gauge"),
String::from(metric_name),
format_metric(
String::from(metric_name), format_metric(
metric_name,
&s.record_buffer.len().to_string(),
Some(&labels),
Expand Down
5 changes: 2 additions & 3 deletions src/sensors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,9 @@ impl Topology {
//trace!("Topology stats measured diff: {:?}", topo_stats_diff);
let process_total_time =
last.total_time_jiffies() - previous.total_time_jiffies();

//trace!("process_total_time: {}", process_total_time);
let topo_total_time = topo_stats_diff.total_time_jiffies()
* procfs::ticks_per_second().unwrap() as f32;
let usage_percent = process_total_time as f64 / topo_total_time as f64;
//trace!("usage_percent: {}", usage_percent.to_string());
let topo_conso = self.get_records_diff_power_microwatts();
if let Some(val) = &topo_conso {
//trace!("topo conso: {}", val);
Expand All @@ -485,6 +482,8 @@ impl Topology {
}
}
}
} else {
trace!("Couldn't find records for PID: {}", pid);
}
None
}
Expand Down
23 changes: 14 additions & 9 deletions src/sensors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl ProcessTracker {
/// in order for the vector length to match self.max_records_per_process.
fn clean_old_process_records(records: &mut Vec<ProcessRecord>, max_records_per_process: u16) {
if records.len() > max_records_per_process as usize {
trace!("Cleaning process record: {:?}", records);
let diff = records.len() - max_records_per_process as usize;
for _ in 0..diff {
records.sort_by(|a, b| b.timestamp.cmp(&a.timestamp));
Expand All @@ -94,12 +93,16 @@ impl ProcessTracker {
/// Returns a Some(ref to vector of ProcessRecords) if the pid is found
/// in self.procs. Returns None otherwise.
pub fn find_records(&self, pid: i32) -> Option<&Vec<ProcessRecord>> {
let mut refer = None;
for v in &self.procs {
if !v.is_empty() && v[0].process.pid == pid {
return Some(&v);
if refer.is_some() {
warn!("ISSUE: PID {} spread in proc tracker", pid);
}
refer = Some(v);
}
}
None
refer
}

/// Returns the result of the substraction of utime between last and
Expand Down Expand Up @@ -286,12 +289,14 @@ impl ProcessTracker {
/// Removes empty Vectors from self.procs
fn drop_empty_process_records_vectors(&mut self) {
let procs = &mut self.procs;
let mut todroplist: Vec<usize> = vec![];
for (counter, _todrop) in procs.iter_mut().filter(|x| x.is_empty()).enumerate() {
todroplist.push(counter);
}
for i in todroplist {
procs.remove(i);
if !procs.is_empty() {
for i in 0..(procs.len()-1) {
if let Some(v) = procs.get(i) {
if v.is_empty() {
procs.remove(i);
}
}
}
}
}
}
Expand Down

0 comments on commit 33a451c

Please sign in to comment.