Skip to content

Commit 6740e30

Browse files
committed
chore: wip [skip ci]
1 parent 72543e9 commit 6740e30

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

crates/runner-shared/src/fifo.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,29 @@ pub enum MarkerType {
1515
BenchmarkEnd(u64),
1616
}
1717

18-
// TODO: Maybe refactor this totally. Always send the pid and tid.
19-
// TODO: Add a version number to the protocol.
20-
2118
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
2219
pub enum Command {
2320
CurrentBenchmark { pid: u32, uri: String },
2421
StartBenchmark,
2522
StopBenchmark,
2623
Ack,
27-
PingPerf, // TODO:: This can be removed, we don't need this anymore
24+
PingPerf,
2825
SetIntegration { name: String, version: String },
2926
Err,
3027
AddMarker { pid: u32, marker: MarkerType },
3128
}
29+
30+
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
31+
struct CommandV2 {
32+
version: u32,
33+
pid: u32,
34+
command: CommandInfo,
35+
}
36+
37+
enum CommandInfo {
38+
Ack,
39+
Err,
40+
PingPerf,
41+
ExecutedBenchmark { uri: String },
42+
AddMarker { marker: MarkerType },
43+
}

crates/runner-shared/src/metadata.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub const PERF_METADATA_CURRENT_VERSION: u64 = 1;
1313

1414
#[derive(Serialize, Deserialize)]
1515
pub struct PerfMetadata {
16+
/// The version of this metadata format.
17+
/// Only available in version 1+
1618
#[serde(default)]
1719
pub version: u64,
1820

@@ -26,9 +28,9 @@ pub struct PerfMetadata {
2628
pub ignored_modules: Vec<(String, u64, u64)>,
2729

2830
/// Marker for certain regions in the profiling data
29-
/// Only available in version 2+
31+
/// Only available in version 1+
3032
#[serde(default)]
31-
pub markers_by_pid: HashMap<u32, Vec<MarkerType>>,
33+
pub markers: Vec<MarkerType>,
3234
}
3335

3436
impl PerfMetadata {

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl PerfRunner {
159159
// maps from /tmp to the profile folder. We have to write our own perf
160160
// maps to these files AFTERWARDS, otherwise it'll be overwritten!
161161
let bench_pids = bench_data
162-
.markers_by_pid
162+
.bench_order_by_pid
163163
.keys()
164164
.map(|pid| *pid as i32)
165165
.collect::<HashSet<_>>();
@@ -261,7 +261,7 @@ impl PerfRunner {
261261
let mut bench_order_by_pid = HashMap::<u32, Vec<String>>::new();
262262
let mut symbols_by_pid = HashMap::<u32, ProcessSymbols>::new();
263263
let mut unwind_data_by_pid = HashMap::<u32, Vec<UnwindData>>::new();
264-
let mut markers_by_pid = HashMap::<u32, Vec<MarkerType>>::new();
264+
let mut markers = Vec::<MarkerType>::new();
265265

266266
let mut integration = None;
267267
let mut perf_ping_timeout = 5;
@@ -300,10 +300,21 @@ impl PerfRunner {
300300
runner_fifo.send_cmd(FifoCommand::Ack).await?;
301301
}
302302
FifoCommand::StartBenchmark => {
303+
markers.push(MarkerType::SampleStart(
304+
std::time::SystemTime::now()
305+
.duration_since(std::time::UNIX_EPOCH)?
306+
.as_millis() as u64,
307+
));
303308
perf_fifo.start_events().await?;
304309
runner_fifo.send_cmd(FifoCommand::Ack).await?;
305310
}
306311
FifoCommand::StopBenchmark => {
312+
markers.push(MarkerType::SampleEnd(
313+
std::time::SystemTime::now()
314+
.duration_since(std::time::UNIX_EPOCH)?
315+
.as_millis() as u64,
316+
));
317+
307318
perf_fifo.stop_events().await?;
308319
runner_fifo.send_cmd(FifoCommand::Ack).await?;
309320
}
@@ -319,11 +330,13 @@ impl PerfRunner {
319330
runner_fifo.send_cmd(FifoCommand::Ack).await?;
320331
}
321332
FifoCommand::AddMarker { pid, marker } => {
322-
markers_by_pid.entry(pid).or_default().push(marker);
333+
markers.push(marker);
323334
runner_fifo.send_cmd(FifoCommand::Ack).await?;
324335
}
325-
FifoCommand::Ack => unreachable!(),
326-
FifoCommand::Err => unreachable!(),
336+
_ => {
337+
warn!("Received unexpected command: {cmd:?}");
338+
runner_fifo.send_cmd(FifoCommand::Err).await?;
339+
}
327340
}
328341
}
329342

@@ -332,7 +345,7 @@ impl PerfRunner {
332345
bench_order_by_pid,
333346
symbols_by_pid,
334347
unwind_data_by_pid,
335-
markers_by_pid,
348+
markers,
336349
})
337350
}
338351
}
@@ -344,7 +357,7 @@ pub struct BenchmarkData {
344357
bench_order_by_pid: HashMap<u32, Vec<String>>,
345358
symbols_by_pid: HashMap<u32, ProcessSymbols>,
346359
unwind_data_by_pid: HashMap<u32, Vec<UnwindData>>,
347-
markers_by_pid: HashMap<u32, Vec<MarkerType>>,
360+
markers: Vec<MarkerType>,
348361
}
349362

350363
#[derive(Debug)]
@@ -419,7 +432,7 @@ impl BenchmarkData {
419432

420433
to_ignore
421434
},
422-
markers_by_pid: self.markers_by_pid.clone(),
435+
markers: self.markers.clone(),
423436
};
424437
metadata.save_to(&path).unwrap();
425438

0 commit comments

Comments
 (0)