Skip to content

Commit

Permalink
Merge pull request #198 from hubblo-org/fix/#131-thread-main-panicked…
Browse files Browse the repository at this point in the history
…-at-trick-if-you-are-running-on-a-vm-when-machine-is-not-a-vm

fix: first implem of fallback to using only socket powercap folders a…
  • Loading branch information
bpetit authored Aug 10, 2022
2 parents 25e2a69 + 56d2c1a commit 42acdaf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 31 deletions.
64 changes: 33 additions & 31 deletions src/exporters/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f64>().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()
Expand All @@ -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::<f32>()
.unwrap()
/ 1000000.0
);
} else {
to_print.push_str("---");
}
false
}) {
let _ = write!(
to_print,
"{} W\t",
current_domain
.metric_value
.to_string()
.parse::<f32>()
.unwrap()
/ 1000000.0
);
} else {
to_print.push_str("---");
}
println!("{}\n", to_print);
}

println!("{}\n", to_print);
}

let consumers: Vec<(IProcess, f64)>;
Expand Down
28 changes: 28 additions & 0 deletions src/sensors/powercap_rapl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 42acdaf

Please sign in to comment.