Skip to content

Commit 280ddf0

Browse files
feat(memtrack): record per-benchmark pid in execution timestamps
Memory mode tracks the whole runner process tree, so between Start/StopProfiler the harness parent and sibling worker processes emit allocation events into every measured region. The CurrentBenchmark FIFO command already carries the pid that ran each benchmark; capture it alongside the uri in ExecutionTimestamps.bench_pid_by_ts (serde-default for artifacts written before this field) so the parser can scope events to the benchmarking process.
1 parent 5c27231 commit 280ddf0

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use libc::pid_t;
12
use serde::{Deserialize, Serialize};
23

34
use crate::fifo::MarkerType;
@@ -6,14 +7,25 @@ use crate::fifo::MarkerType;
67
pub struct ExecutionTimestamps {
78
pub uri_by_ts: Vec<(u64, String)>,
89
pub markers: Vec<MarkerType>,
10+
/// PID of the process that ran each benchmark, keyed by the timestamp of its
11+
/// `CurrentBenchmark` command (the same timestamp used in `uri_by_ts`).
12+
/// Consumers pair it positionally with `uri_by_ts` once both are sorted by
13+
/// timestamp. Empty for artifacts written before pid capture existed.
14+
#[serde(default)]
15+
pub bench_pid_by_ts: Vec<(u64, pid_t)>,
916
}
1017
impl super::ArtifactExt for ExecutionTimestamps {}
1118

1219
impl ExecutionTimestamps {
13-
pub fn new(uri_by_ts: &[(u64, String)], markers: &[crate::fifo::MarkerType]) -> Self {
20+
pub fn new(
21+
uri_by_ts: &[(u64, String)],
22+
markers: &[crate::fifo::MarkerType],
23+
bench_pid_by_ts: &[(u64, pid_t)],
24+
) -> Self {
1425
Self {
1526
uri_by_ts: uri_by_ts.to_vec(),
1627
markers: markers.to_vec(),
28+
bench_pid_by_ts: bench_pid_by_ts.to_vec(),
1729
}
1830
}
1931
}

src/executor/shared/fifo.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl RunnerFifo {
170170
std::process::ExitStatus,
171171
)> {
172172
let mut bench_order_by_timestamp = Vec::<(u64, String)>::new();
173+
let mut bench_pid_by_ts = Vec::<(u64, pid_t)>::new();
173174
let mut bench_pids = HashSet::<pid_t>::new();
174175
let mut markers = Vec::<MarkerType>::new();
175176

@@ -206,7 +207,9 @@ impl RunnerFifo {
206207
// Fall through to shared implementation for standard commands
207208
match &cmd {
208209
FifoCommand::CurrentBenchmark { pid, uri } => {
209-
bench_order_by_timestamp.push((get_current_time(), uri.to_string()));
210+
let ts = get_current_time();
211+
bench_order_by_timestamp.push((ts, uri.to_string()));
212+
bench_pid_by_ts.push((ts, *pid));
210213
bench_pids.insert(*pid);
211214
self.send_cmd(FifoCommand::Ack).await?;
212215
}
@@ -273,8 +276,11 @@ impl RunnerFifo {
273276
debug!(
274277
"Process terminated with status: {exit_status}, stopping the command handler"
275278
);
276-
let marker_result =
277-
ExecutionTimestamps::new(&bench_order_by_timestamp, &markers);
279+
let marker_result = ExecutionTimestamps::new(
280+
&bench_order_by_timestamp,
281+
&markers,
282+
&bench_pid_by_ts,
283+
);
278284
let fifo_data = FifoBenchmarkData {
279285
integration,
280286
bench_pids,

0 commit comments

Comments
 (0)