Skip to content

Commit 4b475d4

Browse files
committed
fix: use upper limit to count pid freq
1 parent 990a79b commit 4b475d4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/run/runner/wall_time/perf/helpers.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ pub fn find_pid<P: AsRef<std::path::Path>>(path: P) -> anyhow::Result<i32> {
1313
} = PerfFileReader::parse_file(reader)?;
1414

1515
let mut pid_freq = HashMap::new();
16+
17+
// Only consider the first N events to reduce the performance impact. Certain benchmark libraries can generate
18+
// more than 100k for each benchmark, which can slow down the runner a lot. The highest chance of finding
19+
// different pids is in the first few events, where there's a possible overlap.
20+
const COUNT_FIRST_N: usize = 1000;
21+
let mut i = 0;
22+
1623
while let Some(record) = record_iter.next_record(&mut perf_file)? {
1724
let PerfFileRecord::EventRecord { record, .. } = record else {
1825
continue;
@@ -33,6 +40,11 @@ pub fn find_pid<P: AsRef<std::path::Path>>(path: P) -> anyhow::Result<i32> {
3340

3441
if let Some(pid) = event.pid {
3542
*pid_freq.entry(pid).or_insert(0) += 1;
43+
44+
i += 1;
45+
if i >= COUNT_FIRST_N {
46+
break;
47+
}
3648
}
3749
}
3850

0 commit comments

Comments
 (0)