in src/data/perf_profile.rs [79:128]
fn finish_data_collection(&mut self, params: &CollectorParams) -> Result<()> {
let mut child = PERF_CHILD.lock().unwrap();
match child.as_ref() {
None => return Ok(()),
Some(_) => {}
}
signal::kill(
Pid::from_raw(child.as_mut().unwrap().id() as i32),
params.signal,
)?;
trace!("Waiting for perf profile collection to complete...");
match child.as_mut().unwrap().wait() {
Err(e) => {
error!("'perf' did not exit successfully: {}", e);
return Ok(());
}
Ok(_) => trace!("'perf record' executed successfully."),
}
let mut top_functions_file =
fs::File::create(params.data_dir.join(PERF_TOP_FUNCTIONS_FILE_NAME))?;
let out = Command::new("perf")
.args([
"report",
"--stdio",
"--percent-limit",
"1",
"-i",
¶ms.data_file_path.display().to_string(),
])
.output();
match out {
Err(e) => {
let out = format!("Skipped processing profiling data due to : {}", e);
error!("{}", out);
write!(top_functions_file, "{}", out)?;
}
Ok(v) => {
let mut top_functions = "No data collected";
if !v.stdout.is_empty() {
top_functions = std::str::from_utf8(&v.stdout)?;
}
write!(top_functions_file, "{}", top_functions)?;
}
}
Ok(())
}