Skip to content

Commit 4c990fd

Browse files
committed
feat: add perf v2 support
1 parent 664c010 commit 4c990fd

File tree

6 files changed

+154
-125
lines changed

6 files changed

+154
-125
lines changed

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 `instrument-hooks`.
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: i32, uri: String },
25+
StartBenchmark,
26+
StopBenchmark,
27+
Ack,
28+
PingPerf,
29+
SetIntegration { name: String, version: String },
30+
Err,
31+
AddMarker { pid: i32, marker: MarkerType },
32+
SetVersion(u64),
33+
}

crates/runner-shared/src/metadata.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
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+
pub version: u64,
11+
1312
/// Name and version of the integration
1413
pub integration: (String, String),
1514

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

1918
/// Modules that should be ignored and removed from the folded trace and callgraph (e.g. python interpreter)
2019
pub ignored_modules: Vec<(String, u64, u64)>,
20+
21+
/// Marker for certain regions in the profiling data
22+
pub markers: Vec<MarkerType>,
2123
}
2224

2325
impl PerfMetadata {
26+
pub fn from_reader<R: std::io::Read>(reader: R) -> anyhow::Result<Self> {
27+
serde_json::from_reader(reader).context("Could not parse perf metadata from JSON")
28+
}
29+
2430
pub fn save_to<P: AsRef<Path>>(&self, path: P) -> anyhow::Result<()> {
2531
let file = std::fs::File::create(path.as_ref().join("perf.metadata"))?;
2632
serde_json::to_writer(file, self)?;

src/run/runner/valgrind/helpers/perf_maps.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub async fn harvest_perf_maps(profile_folder: &Path) -> Result<()> {
2121
harvest_perf_maps_for_pids(profile_folder, &pids).await
2222
}
2323

24-
pub async fn harvest_perf_maps_for_pids(profile_folder: &Path, pids: &HashSet<i32>) -> Result<()> {
24+
pub async fn harvest_perf_maps_for_pids(
25+
profile_folder: &Path,
26+
pids: &HashSet<libc::pid_t>,
27+
) -> Result<()> {
2528
let perf_maps = pids
2629
.iter()
2730
.map(|pid| format!("perf-{pid}.map"))

0 commit comments

Comments
 (0)