Skip to content

Commit 388622f

Browse files
committed
chore: dont use regex in perf map harvest
1 parent d853ce3 commit 388622f

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

src/run/runner/valgrind/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Executor for ValgrindExecutor {
4141
_system_info: &SystemInfo,
4242
run_data: &RunData,
4343
) -> Result<()> {
44-
harvest_perf_maps(&run_data.profile_folder)?;
44+
harvest_perf_maps(&run_data.profile_folder).await?;
4545

4646
Ok(())
4747
}

src/run/runner/valgrind/helpers/perf_maps.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
use crate::prelude::*;
2-
use lazy_static::lazy_static;
3-
use regex::Regex;
42
use std::collections::HashSet;
53
use std::fs;
6-
use std::path::Path;
4+
use std::path::{Path, PathBuf};
75

8-
lazy_static! {
9-
static ref PERF_MAP_REGEX: Regex = Regex::new(r"perf-(\d+)\.map").unwrap();
10-
}
11-
12-
pub fn harvest_perf_maps(profile_folder: &Path) -> Result<()> {
6+
pub async fn harvest_perf_maps(profile_folder: &Path) -> Result<()> {
137
// Get profile files (files with .out extension)
148
let profile_files = fs::read_dir(profile_folder)?
159
.filter_map(|entry| entry.ok())
@@ -21,27 +15,31 @@ pub fn harvest_perf_maps(profile_folder: &Path) -> Result<()> {
2115
.iter()
2216
.filter_map(|path| path.file_stem())
2317
.map(|pid| pid.to_str().unwrap())
18+
.filter_map(|pid| pid.parse().ok())
2419
.collect::<HashSet<_>>();
2520

26-
let perf_map_files = fs::read_dir("/tmp")?
27-
.filter_map(|entry| entry.ok())
28-
.map(|entry| entry.path())
29-
.filter(|path| {
30-
path.file_name()
31-
.and_then(|name| name.to_str())
32-
.and_then(|name| PERF_MAP_REGEX.captures(name))
33-
.and_then(|captures| captures.get(1))
34-
.map(|pid| pids.contains(pid.as_str()))
35-
.unwrap_or(false)
36-
});
21+
harvest_perf_maps_for_pids(profile_folder, &pids).await
22+
}
23+
24+
pub async fn harvest_perf_maps_for_pids(profile_folder: &Path, pids: &HashSet<i32>) -> Result<()> {
25+
let perf_maps = pids
26+
.iter()
27+
.map(|pid| format!("perf-{}.map", pid))
28+
.map(|file_name| {
29+
(
30+
PathBuf::from("/tmp").join(&file_name),
31+
profile_folder.join(&file_name),
32+
)
33+
})
34+
.filter(|(src_path, _)| src_path.exists())
35+
.collect::<Vec<_>>();
36+
debug!("Found {} perf maps", perf_maps.len());
3737

38-
for perf_map_file in perf_map_files {
39-
let source_path = perf_map_file.clone();
40-
let dest_path = profile_folder.join(perf_map_file.file_name().unwrap());
41-
fs::copy(source_path, dest_path).map_err(|e| {
38+
for (src_path, dst_path) in perf_maps {
39+
fs::copy(&src_path, &dst_path).map_err(|e| {
4240
anyhow!(
43-
"Failed to copy perf map file: {} to {}: {}",
44-
perf_map_file.display(),
41+
"Failed to copy perf map file: {:?} to {}: {}",
42+
src_path.file_name(),
4543
profile_folder.display(),
4644
e
4745
)

0 commit comments

Comments
 (0)