diff --git a/src/exporters/stdout.rs b/src/exporters/stdout.rs index 3afba1f3..55a4af80 100644 --- a/src/exporters/stdout.rs +++ b/src/exporters/stdout.rs @@ -172,18 +172,19 @@ impl StdoutExporter { None => MetricValueType::Text("0".to_string()), }; - let mut domain_names = vec![]; - - if let Some(domains) = metric_generator.topology.domains_names.as_ref() { - info!("domain_name: {:?}", domains); - domain_names = domains.clone(); + let domain_names = metric_generator.topology.domains_names.as_ref(); + if domain_names.is_some() { + info!("domain_names: {:?}", domain_names.unwrap()); } println!( "Host:\t{} W", (format!("{}", host_power).parse::().unwrap() / 1000000.0) ); - println!("\tpackage \t{}", domain_names.join("\t\t")); + + if domain_names.is_some() { + println!("\tpackage \t{}", domain_names.unwrap().join("\t\t")); + } for s in metrics .iter() @@ -203,35 +204,36 @@ impl StdoutExporter { && x.attributes.get("socket_id").unwrap() == &socket_id }); - for d in &domain_names { - info!("current domain : {}", d); - info!("domains size : {}", &domains.clone().count()); - if let Some(current_domain) = domains.clone().find(|x| { - info!("looking for domain metrics for d == {}", d); - info!("current metric analyzed : {:?}", x); - if let Some(domain_name_result) = x.attributes.get("domain_name") { - if domain_name_result == d { - return true; + if let Some(domain_names) = domain_names { + for d in domain_names { + info!("current domain : {}", d); + info!("domains size : {}", &domains.clone().count()); + if let Some(current_domain) = domains.clone().find(|x| { + info!("looking for domain metrics for d == {}", d); + info!("current metric analyzed : {:?}", x); + if let Some(domain_name_result) = x.attributes.get("domain_name") { + if domain_name_result == d { + return true; + } } + false + }) { + let _ = write!( + to_print, + "{} W\t", + current_domain + .metric_value + .to_string() + .parse::() + .unwrap() + / 1000000.0 + ); + } else { + to_print.push_str("---"); } - false - }) { - let _ = write!( - to_print, - "{} W\t", - current_domain - .metric_value - .to_string() - .parse::() - .unwrap() - / 1000000.0 - ); - } else { - to_print.push_str("---"); } + println!("{}\n", to_print); } - - println!("{}\n", to_print); } let consumers: Vec<(IProcess, f64)>; diff --git a/src/sensors/powercap_rapl.rs b/src/sensors/powercap_rapl.rs index 4ddbdfe8..52ff03f3 100644 --- a/src/sensors/powercap_rapl.rs +++ b/src/sensors/powercap_rapl.rs @@ -109,11 +109,14 @@ impl Sensor for PowercapRAPLSensor { warn!("Couldn't find intel_rapl modules."); } let mut topo = Topology::new(); + let re_socket = Regex::new(r"^.*/intel-rapl:\d+$").unwrap(); let re_domain = Regex::new(r"^.*/intel-rapl:\d+:\d+$").unwrap(); + let mut re_domain_matched = false; for folder in fs::read_dir(&self.base_path).unwrap() { let folder_name = String::from(folder.unwrap().path().to_str().unwrap()); // let's catch domain folders if re_domain.is_match(&folder_name) { + re_domain_matched = true; // let's get the second number of the intel-rapl:X:X string let mut splitted = folder_name.split(':'); let _ = splitted.next(); @@ -155,6 +158,31 @@ impl Sensor for PowercapRAPLSensor { } } } + if !re_domain_matched { + warn!("Couldn't find domain folders from powercap. Fallback on socket folders."); + warn!("Scaphandre will not be able to provide per-domain data."); + for folder in fs::read_dir(&self.base_path).unwrap() { + let folder_name = String::from(folder.unwrap().path().to_str().unwrap()); + if re_socket.is_match(&folder_name) { + let mut splitted = folder_name.split(':'); + let _ = splitted.next(); + let socket_id = String::from(splitted.next().unwrap()).parse().unwrap(); + let mut sensor_data_for_socket = HashMap::new(); + sensor_data_for_socket.insert( + String::from("source_file"), + format!("{}/intel-rapl:{}/energy_uj", self.base_path, socket_id), + ); + topo.safe_add_socket( + socket_id, + vec![], + vec![], + format!("{}/intel-rapl:{}/energy_uj", self.base_path, socket_id), + self.buffer_per_socket_max_kbytes, + sensor_data_for_socket, + ) + } + } + } topo.add_cpu_cores(); Ok(topo) }