Skip to content

Commit 6279c9b

Browse files
refactor: move common perf-map utility outside of valgrind helpers
1 parent c1a2af2 commit 6279c9b

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::prelude::*;
2+
use std::collections::HashSet;
3+
use std::fs;
4+
use std::path::{Path, PathBuf};
5+
6+
pub async fn harvest_perf_maps_for_pids(
7+
profile_folder: &Path,
8+
pids: &HashSet<libc::pid_t>,
9+
) -> Result<()> {
10+
let perf_maps = pids
11+
.iter()
12+
.map(|pid| format!("perf-{pid}.map"))
13+
.map(|file_name| {
14+
(
15+
PathBuf::from("/tmp").join(&file_name),
16+
profile_folder.join(&file_name),
17+
)
18+
})
19+
.filter(|(src_path, _)| src_path.exists())
20+
.collect::<Vec<_>>();
21+
debug!("Found {} perf maps", perf_maps.len());
22+
23+
for (src_path, dst_path) in perf_maps {
24+
fs::copy(&src_path, &dst_path).map_err(|e| {
25+
anyhow!(
26+
"Failed to copy perf map file: {:?} to {}: {}",
27+
src_path.file_name(),
28+
profile_folder.display(),
29+
e
30+
)
31+
})?;
32+
}
33+
34+
Ok(())
35+
}

src/executor/helpers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod apt;
22
pub mod command;
33
pub mod env;
44
pub mod get_bench_command;
5+
pub mod harvest_perf_maps_for_pids;
56
pub mod introspected_golang;
67
pub mod introspected_nodejs;
78
pub mod profile_folder;
Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use crate::executor::helpers::harvest_perf_maps_for_pids::harvest_perf_maps_for_pids;
12
use crate::prelude::*;
23
use std::collections::HashSet;
34
use std::fs;
4-
use std::path::{Path, PathBuf};
5+
use std::path::Path;
56

67
pub async fn harvest_perf_maps(profile_folder: &Path) -> Result<()> {
78
// Get profile files (files with .out extension)
@@ -20,34 +21,3 @@ pub async fn harvest_perf_maps(profile_folder: &Path) -> Result<()> {
2021

2122
harvest_perf_maps_for_pids(profile_folder, &pids).await
2223
}
23-
24-
pub async fn harvest_perf_maps_for_pids(
25-
profile_folder: &Path,
26-
pids: &HashSet<libc::pid_t>,
27-
) -> Result<()> {
28-
let perf_maps = pids
29-
.iter()
30-
.map(|pid| format!("perf-{pid}.map"))
31-
.map(|file_name| {
32-
(
33-
PathBuf::from("/tmp").join(&file_name),
34-
profile_folder.join(&file_name),
35-
)
36-
})
37-
.filter(|(src_path, _)| src_path.exists())
38-
.collect::<Vec<_>>();
39-
debug!("Found {} perf maps", perf_maps.len());
40-
41-
for (src_path, dst_path) in perf_maps {
42-
fs::copy(&src_path, &dst_path).map_err(|e| {
43-
anyhow!(
44-
"Failed to copy perf map file: {:?} to {}: {}",
45-
src_path.file_name(),
46-
profile_folder.display(),
47-
e
48-
)
49-
})?;
50-
}
51-
52-
Ok(())
53-
}

src/executor/wall_time/perf/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use crate::cli::UnwindingMode;
44
use crate::executor::Config;
55
use crate::executor::helpers::command::CommandBuilder;
66
use crate::executor::helpers::env::is_codspeed_debug_enabled;
7+
use crate::executor::helpers::harvest_perf_maps_for_pids::harvest_perf_maps_for_pids;
78
use crate::executor::helpers::run_command_with_log_pipe::run_command_with_log_pipe_and_callback;
89
use crate::executor::helpers::run_with_sudo::run_with_sudo;
910
use crate::executor::helpers::run_with_sudo::wrap_with_sudo;
1011
use crate::executor::shared::fifo::FifoBenchmarkData;
1112
use crate::executor::shared::fifo::RunnerFifo;
1213
use crate::executor::valgrind::helpers::ignored_objects_path::get_objects_path_to_ignore;
13-
use crate::executor::valgrind::helpers::perf_maps::harvest_perf_maps_for_pids;
1414
use crate::executor::wall_time::perf::debug_info::ProcessDebugInfo;
1515
use crate::executor::wall_time::perf::jit_dump::harvest_perf_jit_for_pids;
1616
use crate::executor::wall_time::perf::perf_executable::get_working_perf_executable;

0 commit comments

Comments
 (0)