Skip to content

Commit b4b3c9c

Browse files
committed
chore: wip [skip ci]
1 parent a502bc9 commit b4b3c9c

12 files changed

Lines changed: 207 additions & 228 deletions

File tree

Cargo.lock

Lines changed: 29 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ object = "0.36.7"
5353
linux-perf-data = "0.11.0"
5454
debugid = "0.8.0"
5555
memmap2 = "0.9.5"
56-
nix = { version = "0.29.0", features = ["fs", "user"] }
56+
nix = { version = "0.29.0", features = ["fs", "time", "user"] }
5757
futures = "0.3.31"
58+
runner-shared = { path = "crates/runner-shared" }
5859

5960
[target.'cfg(target_os = "linux")'.dependencies]
6061
procfs = "0.17.0"
@@ -67,6 +68,9 @@ rstest = { version = "0.25.0", default-features = false }
6768
rstest_reuse = "0.7.0"
6869
shell-quote = "0.7.2"
6970

71+
[workspace]
72+
members = ["crates/runner-shared"]
73+
7074
[workspace.metadata.release]
7175
sign-tag = true
7276
sign-commit = true

crates/runner-shared/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "runner-shared"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
anyhow = "1.0.100"
8+
serde = { version = "1.0.225", features = ["derive"] }
9+
serde_json = "1.0.145"

crates/runner-shared/src/fifo.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
/// The different markers that can be set in the perf.data.
7+
///
8+
/// `SampleStart/End`: Marks the start and end of a sampling period. This is used to differentiate between benchmarks.
9+
/// `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.
10+
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Copy, Clone)]
11+
pub enum MarkerType {
12+
SampleStart(u64),
13+
SampleEnd(u64),
14+
BenchmarkStart(u64),
15+
BenchmarkEnd(u64),
16+
}
17+
18+
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
19+
pub enum Command {
20+
CurrentBenchmark { pid: u32, uri: String },
21+
StartBenchmark,
22+
StopBenchmark,
23+
Ack,
24+
PingPerf,
25+
SetIntegration { name: String, version: String },
26+
Err,
27+
AddMarker { pid: u32, marker: MarkerType },
28+
}

crates/runner-shared/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This will be accessed from the `parse_callgraph` lambda.
2+
3+
pub mod fifo;
4+
pub mod metadata;
5+
pub mod unwind_data;
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
// Has to be in sync with `perf-parser`.
55
//
66

7+
use serde::{Deserialize, Serialize};
78
use std::{collections::HashMap, path::Path};
89

9-
use serde::{Deserialize, Serialize};
10+
use crate::fifo::MarkerType;
11+
12+
pub const PERF_METADATA_CURRENT_VERSION: u64 = 1;
1013

1114
#[derive(Serialize, Deserialize)]
1215
pub struct PerfMetadata {
16+
/// The version of this metadata format.
17+
/// Only available in version 1+
18+
#[serde(default)]
19+
pub version: u64,
20+
1321
/// Name and version of the integration
1422
pub integration: (String, String),
1523

@@ -18,6 +26,11 @@ pub struct PerfMetadata {
1826

1927
/// Modules that should be ignored and removed from the folded trace and callgraph (e.g. python interpreter)
2028
pub ignored_modules: Vec<(String, u64, u64)>,
29+
30+
/// Marker for certain regions in the profiling data
31+
/// Only available in version 1+
32+
#[serde(default)]
33+
pub markers: Vec<MarkerType>,
2134
}
2235

2336
impl PerfMetadata {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use core::{
2+
fmt::Debug,
3+
hash::{Hash, Hasher},
4+
};
5+
use serde::{Deserialize, Serialize};
6+
use std::{hash::DefaultHasher, ops::Range};
7+
8+
/// Unwind data for a single module.
9+
#[derive(Serialize, Deserialize)]
10+
pub struct UnwindData {
11+
pub path: String,
12+
13+
pub avma_range: Range<u64>,
14+
pub base_avma: u64,
15+
16+
pub eh_frame_hdr: Vec<u8>,
17+
pub eh_frame_hdr_svma: Range<u64>,
18+
19+
pub eh_frame: Vec<u8>,
20+
pub eh_frame_svma: Range<u64>,
21+
}
22+
23+
impl Debug for UnwindData {
24+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25+
let eh_frame_hdr_hash = {
26+
let mut hasher = DefaultHasher::new();
27+
self.eh_frame_hdr.hash(&mut hasher);
28+
hasher.finish()
29+
};
30+
let eh_frame_hash = {
31+
let mut hasher = DefaultHasher::new();
32+
self.eh_frame.hash(&mut hasher);
33+
hasher.finish()
34+
};
35+
36+
f.debug_struct("UnwindData")
37+
.field("path", &self.path)
38+
.field("avma_range", &format_args!("{:x?}", self.avma_range))
39+
.field("base_avma", &format_args!("{:x}", self.base_avma))
40+
.field(
41+
"eh_frame_hdr_svma",
42+
&format_args!("{:x?}", self.eh_frame_hdr_svma),
43+
)
44+
.field("eh_frame_hdr_hash", &format_args!("{eh_frame_hdr_hash:x}"))
45+
.field("eh_frame_hash", &format_args!("{eh_frame_hash:x}"))
46+
.field("eh_frame_svma", &format_args!("{:x?}", self.eh_frame_svma))
47+
.finish()
48+
}
49+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::{FifoCommand, RUNNER_ACK_FIFO, RUNNER_CTL_FIFO};
1+
use super::FifoCommand;
2+
use runner_shared::fifo::{RUNNER_ACK_FIFO, RUNNER_CTL_FIFO};
23
use std::path::PathBuf;
34
use tokio::io::{AsyncReadExt, AsyncWriteExt};
45
use tokio::net::unix::pipe::OpenOptions as TokioPipeOpenOptions;

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

Lines changed: 0 additions & 71 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use crate::{
22
prelude::*,
33
run::runner::wall_time::perf::{
44
perf_map::{ModuleSymbols, Symbol},
5-
unwind_data::UnwindData,
5+
unwind_data::UnwindDataExt,
66
},
77
};
88
use linux_perf_data::jitdump::{JitDumpReader, JitDumpRecord};
9+
use runner_shared::unwind_data::UnwindData;
910
use std::{
1011
collections::HashSet,
1112
path::{Path, PathBuf},

0 commit comments

Comments
 (0)