Skip to content

Commit bf9395d

Browse files
committed
feat: add perf v2 support
1 parent 8782315 commit bf9395d

3 files changed

Lines changed: 132 additions & 116 deletions

File tree

crates/runner-shared/src/fifo.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! WARNING: Has to be in sync with `codspeed-rust/codspeed`.
2+
3+
pub const RUNNER_CTL_FIFO: &str = "/tmp/runner.ctl.fifo";
4+
pub const RUNNER_ACK_FIFO: &str = "/tmp/runner.ack.fifo";
5+
6+
pub const CURRENT_PROTOCOL_VERSION: u64 = 1;
7+
8+
/// The different markers that can be set in the perf.data.
9+
///
10+
/// `SampleStart/End`: Marks the start and end of a sampling period. This is used to differentiate between benchmarks.
11+
/// `BenchmarkStart/End`: Marks the start and end of a benchmark. This is used to measure the duration of a benchmark, without the benchmark harness code.
12+
#[derive(
13+
serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone,
14+
)]
15+
pub enum MarkerType {
16+
SampleStart(u64),
17+
SampleEnd(u64),
18+
BenchmarkStart(u64),
19+
BenchmarkEnd(u64),
20+
}
21+
22+
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
23+
pub enum Command {
24+
CurrentBenchmark { pid: u32, uri: String },
25+
StartBenchmark,
26+
StopBenchmark,
27+
Ack,
28+
PingPerf,
29+
SetIntegration { name: String, version: String },
30+
Err,
31+
AddMarker { pid: u32, marker: MarkerType },
32+
SetVersion(u64),
33+
}

crates/runner-shared/src/metadata.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
// !!!!!!!!!!!!!!!!!!!!!!!!
2-
// !! DO NOT TOUCH BELOW !!
3-
// !!!!!!!!!!!!!!!!!!!!!!!!
4-
// Has to be in sync with `perf-parser`.
5-
//
6-
7-
use std::{collections::HashMap, path::Path};
8-
1+
use anyhow::Context;
92
use serde::{Deserialize, Serialize};
3+
use std::path::Path;
4+
5+
use crate::fifo::MarkerType;
106

117
#[derive(Serialize, Deserialize)]
128
pub struct PerfMetadata {
9+
/// The version of this metadata format.
10+
/// Only available in version 1+
11+
#[serde(default)]
12+
pub version: u64,
13+
1314
/// Name and version of the integration
1415
pub integration: (String, String),
1516

16-
/// The URIs of the benchmarks in the order they were executed.
17-
pub bench_order_by_pid: HashMap<u32, Vec<String>>,
17+
/// The URIs of the benchmarks with the timestamps they were executed at.
18+
pub uri_by_ts: Vec<(u64, String)>,
1819

1920
/// Modules that should be ignored and removed from the folded trace and callgraph (e.g. python interpreter)
2021
pub ignored_modules: Vec<(String, u64, u64)>,
22+
23+
/// Marker for certain regions in the profiling data
24+
/// Only available in version 1+
25+
#[serde(default)]
26+
pub markers: Vec<MarkerType>,
2127
}
2228

2329
impl PerfMetadata {
30+
pub fn from_reader<R: std::io::Read>(reader: R) -> anyhow::Result<Self> {
31+
serde_json::from_reader(reader).context("Could not parse perf metadata from JSON")
32+
}
33+
2434
pub fn save_to<P: AsRef<Path>>(&self, path: P) -> anyhow::Result<()> {
2535
let file = std::fs::File::create(path.as_ref().join("perf.metadata"))?;
2636
serde_json::to_writer(file, self)?;

0 commit comments

Comments
 (0)