Skip to content

Commit bfe5aee

Browse files
committed
refactor(runner-shared): move the module event filter next to the decoder
The runner filtered the full memtrack event stream down to the Mapping, Fork and Exec events inside read_mappings_from_artifact. Moving that filter into MemtrackArtifact::decode_module_events puts it next to the decoder, so it can be benchmarked and optimized in one place without changing the runner's fork/exec replay.
1 parent 24f182e commit bfe5aee

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎crates/runner-shared/src/artifacts/memtrack/mod.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ impl MemtrackArtifact {
3636
})
3737
}
3838

39+
/// Stream only the events that place modules in processes: executable
40+
/// mappings, and the forks and execs that inherit or drop them. Offline
41+
/// stack attribution needs these few events out of the whole artifact.
42+
pub fn decode_module_events<R: std::io::Read>(
43+
reader: R,
44+
) -> anyhow::Result<impl Iterator<Item = MemtrackEvent>> {
45+
Ok(Self::decode_streamed(reader)?.filter(|event| {
46+
matches!(
47+
event.kind,
48+
MemtrackEventKind::Mapping { .. }
49+
| MemtrackEventKind::Fork { .. }
50+
| MemtrackEventKind::Exec
51+
)
52+
}))
53+
}
54+
3955
pub fn is_empty<R: std::io::Read>(reader: R) -> bool {
4056
let Ok(mut stream) = MemtrackArtifact::decode_streamed(BufReader::new(reader)) else {
4157
return true;

‎src/executor/memory/module_artifacts.rs‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,7 @@ fn read_mappings(results_folder: &Path) -> Result<Vec<ProcessMapping>> {
103103
/// Reconstruct mappings across forks because inherited perf events do not
104104
/// synthesize mappings that already existed when a child was forked.
105105
fn read_mappings_from_artifact<R: std::io::Read>(reader: R) -> Result<Vec<ProcessMapping>> {
106-
let mut timeline = MemtrackArtifact::decode_streamed(reader)?
107-
.filter(|event| {
108-
matches!(
109-
&event.kind,
110-
MemtrackEventKind::Exec
111-
| MemtrackEventKind::Mapping { .. }
112-
| MemtrackEventKind::Fork { .. }
113-
)
114-
})
115-
.collect::<Vec<_>>();
106+
let mut timeline = MemtrackArtifact::decode_module_events(reader)?.collect::<Vec<_>>();
116107

117108
// Ties break so exec purges before mapping, while fork inherits that mapping.
118109
timeline.sort_by_key(|event| {

0 commit comments

Comments
 (0)