Skip to content

Commit fc2b18e

Browse files
committed
fix: match perf's jit_detect() pattern for jitdump paths
Only match basenames of the form jit-<digits>.dump instead of any .dump suffix. This matches the validation in perf's jit_detect().
1 parent eaf949b commit fc2b18e

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/executor/wall_time/perf/parse_perf_file.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ pub fn parse_for_memmap2<P: AsRef<Path>>(
110110

111111
// Collect jitdump file paths before the PROT_EXEC filter in process_mmap2_record
112112
// skips them. JIT runtimes mmap the jitdump file so perf records it.
113-
if mmap2_record.path.as_slice().ends_with(b".dump") {
113+
// Match perf's jit_detect(): basename must be `jit-<pid>.dump`.
114+
if is_jit_dump_path(&mmap2_record.path.as_slice()) {
114115
let path = PathBuf::from(
115116
String::from_utf8_lossy(&mmap2_record.path.as_slice()).into_owned(),
116117
);
@@ -179,6 +180,23 @@ impl PidFilter {
179180
}
180181
}
181182

183+
/// Returns true if the path basename matches perf's jitdump pattern: `jit-<digits>.dump`.
184+
fn is_jit_dump_path(path: &[u8]) -> bool {
185+
let basename = match path.iter().rposition(|&b| b == b'/') {
186+
Some(pos) => &path[pos + 1..],
187+
None => return false,
188+
};
189+
let rest = match basename.strip_prefix(b"jit-") {
190+
Some(rest) => rest,
191+
None => return false,
192+
};
193+
let rest = match rest.strip_suffix(b".dump") {
194+
Some(rest) => rest,
195+
None => return false,
196+
};
197+
!rest.is_empty() && rest.iter().all(|b| b.is_ascii_digit())
198+
}
199+
182200
/// Process a single MMAP2 record and add it to the symbols and unwind data maps
183201
fn process_mmap2_record(
184202
record: linux_perf_data::linux_perf_event_reader::Mmap2Record,

0 commit comments

Comments
 (0)