Skip to content

Commit 2ee3731

Browse files
committed
feat: add timestamp to unwind data
1 parent f4c670f commit 2ee3731

8 files changed

+56
-7
lines changed

crates/runner-shared/src/unwind_data.rs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ use std::{hash::DefaultHasher, ops::Range};
77

88
pub const UNWIND_FILE_EXT: &str = "unwind_data";
99

10-
pub type UnwindData = UnwindDataV1;
10+
pub type UnwindData = UnwindDataV2;
1111

1212
impl UnwindData {
1313
pub fn parse(reader: &[u8]) -> anyhow::Result<Self> {
1414
let compat: UnwindDataCompat = bincode::deserialize(reader)?;
1515

1616
match compat {
17-
UnwindDataCompat::V1(v1) => Ok(v1),
17+
UnwindDataCompat::V1(v1) => Ok(v1.into()),
18+
UnwindDataCompat::V2(v2) => Ok(v2),
1819
}
1920
}
2021

2122
pub fn save_to<P: AsRef<std::path::Path>>(&self, folder: P, pid: i32) -> anyhow::Result<()> {
2223
let unwind_data_path = folder.as_ref().join(format!(
23-
"{}_{:x}_{:x}.{UNWIND_FILE_EXT}",
24-
pid, self.avma_range.start, self.avma_range.end
24+
"{}_{:x}_{:x}_{}.{UNWIND_FILE_EXT}",
25+
pid,
26+
self.avma_range.start,
27+
self.avma_range.end,
28+
self.timestamp.unwrap_or_default()
2529
));
2630
self.to_file(unwind_data_path)?;
2731

@@ -38,7 +42,7 @@ impl UnwindData {
3842
}
3943

4044
let mut writer = std::fs::File::create(path.as_ref())?;
41-
let compat = UnwindDataCompat::V1(self.clone());
45+
let compat = UnwindDataCompat::V2(self.clone());
4246
bincode::serialize_into(&mut writer, &compat)?;
4347
Ok(())
4448
}
@@ -59,6 +63,7 @@ impl Debug for UnwindData {
5963

6064
f.debug_struct("UnwindData")
6165
.field("path", &self.path)
66+
.field("timestamp", &self.timestamp)
6267
.field("avma_range", &format_args!("{:x?}", self.avma_range))
6368
.field("base_avma", &format_args!("{:x}", self.base_avma))
6469
.field("base_svma", &format_args!("{:x}", self.base_svma))
@@ -77,11 +82,12 @@ impl Debug for UnwindData {
7782
#[derive(Serialize, Deserialize)]
7883
enum UnwindDataCompat {
7984
V1(UnwindDataV1),
85+
V2(UnwindDataV2),
8086
}
8187

8288
#[doc(hidden)]
8389
#[derive(Serialize, Deserialize, Clone)]
84-
pub struct UnwindDataV1 {
90+
struct UnwindDataV1 {
8591
pub path: String,
8692

8793
pub avma_range: Range<u64>,
@@ -94,3 +100,39 @@ pub struct UnwindDataV1 {
94100
pub eh_frame: Vec<u8>,
95101
pub eh_frame_svma: Range<u64>,
96102
}
103+
104+
#[doc(hidden)]
105+
#[derive(Serialize, Deserialize, Clone)]
106+
pub struct UnwindDataV2 {
107+
pub path: String,
108+
109+
/// The monotonic timestamp when the unwind data was captured.
110+
/// Is `None` if unwind data is valid for the whole program execution
111+
pub timestamp: Option<u64>,
112+
113+
pub avma_range: Range<u64>,
114+
pub base_avma: u64,
115+
pub base_svma: u64,
116+
117+
pub eh_frame_hdr: Vec<u8>,
118+
pub eh_frame_hdr_svma: Range<u64>,
119+
120+
pub eh_frame: Vec<u8>,
121+
pub eh_frame_svma: Range<u64>,
122+
}
123+
124+
impl From<UnwindDataV1> for UnwindDataV2 {
125+
fn from(v1: UnwindDataV1) -> Self {
126+
Self {
127+
path: v1.path,
128+
timestamp: None,
129+
avma_range: v1.avma_range,
130+
base_avma: v1.base_avma,
131+
base_svma: v1.base_svma,
132+
eh_frame_hdr: v1.eh_frame_hdr,
133+
eh_frame_hdr_svma: v1.eh_frame_hdr_svma,
134+
eh_frame: v1.eh_frame,
135+
eh_frame_svma: v1.eh_frame_svma,
136+
}
137+
}
138+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl JitDump {
7474

7575
jit_unwind_data.push(UnwindData {
7676
path: format!("jit_{name}"),
77+
timestamp: Some(raw_record.timestamp),
7778
avma_range: avma_start..avma_end,
7879
base_avma: 0,
7980
eh_frame_hdr,

src/run/runner/wall_time/perf/snapshots/codspeed__run__runner__wall_time__perf__unwind_data__tests__cpp_unwind_data.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: "UnwindData::new(MODULE_PATH.as_bytes(), file_offset, start_addr, en
55
Ok(
66
UnwindData {
77
path: "testdata/perf_map/cpp_my_benchmark.bin",
8+
timestamp: None,
89
avma_range: 400000..459000,
910
base_avma: 400000,
1011
base_svma: 400000,

src/run/runner/wall_time/perf/snapshots/codspeed__run__runner__wall_time__perf__unwind_data__tests__golang_unwind_data.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: "UnwindData::new(MODULE_PATH.as_bytes(), file_offset, start_addr, en
55
Ok(
66
UnwindData {
77
path: "testdata/perf_map/go_fib.bin",
8+
timestamp: None,
89
avma_range: 402000..50f000,
910
base_avma: 400000,
1011
base_svma: 400000,

src/run/runner/wall_time/perf/snapshots/codspeed__run__runner__wall_time__perf__unwind_data__tests__ruff_unwind_data.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: "UnwindData::new(MODULE_PATH.as_bytes(), file_offset, start_addr, en
55
Ok(
66
UnwindData {
77
path: "testdata/perf_map/ty_walltime",
8+
timestamp: None,
89
avma_range: 555555e6d000..555556813000,
910
base_avma: 555555554000,
1011
base_svma: 0,

src/run/runner/wall_time/perf/snapshots/codspeed__run__runner__wall_time__perf__unwind_data__tests__rust_divan_unwind_data.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: "UnwindData::new(MODULE_PATH.as_bytes(), file_offset, start_addr, en
55
Ok(
66
UnwindData {
77
path: "testdata/perf_map/divan_sleep_benches.bin",
8+
timestamp: None,
89
avma_range: 5555555a2000..555555692000,
910
base_avma: 555555554000,
1011
base_svma: 0,

src/run/runner/wall_time/perf/snapshots/codspeed__run__runner__wall_time__perf__unwind_data__tests__the_algorithms_unwind_data.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
source: src/run/runner/wall_time/perf/unwind_data.rs
3-
expression: "UnwindData::new(MODULE_PATH.as_bytes(), 0x52efc, 0x00005555555a7000, 0x00005555556b0000,\nNone)"
3+
expression: "UnwindData::new(MODULE_PATH.as_bytes(), file_offset, start_addr, end_addr,\nNone)"
44
---
55
Ok(
66
UnwindData {
77
path: "testdata/perf_map/the_algorithms.bin",
8+
timestamp: None,
89
avma_range: 5555555a7000..5555556b0000,
910
base_avma: 555555554000,
1011
base_svma: 0,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl UnwindDataExt for UnwindData {
8181

8282
Ok(UnwindData {
8383
path,
84+
timestamp: None,
8485
avma_range,
8586
base_avma,
8687
base_svma,

0 commit comments

Comments
 (0)