Skip to content

Commit 5c1f21b

Browse files
committed
feat: add timestamp to unwind data
1 parent 618e3ea commit 5c1f21b

8 files changed

Lines changed: 51 additions & 5 deletions

crates/runner-shared/src/unwind_data.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ use std::{
1111

1212
pub const UNWIND_FILE_EXT: &str = "unwind2";
1313

14-
pub type UnwindData = UnwindDataV1;
14+
pub type UnwindData = UnwindDataV2;
1515

1616
impl UnwindData {
1717
pub fn parse<R: Read + Seek>(mut reader: R) -> anyhow::Result<Self> {
1818
let compat: UnwindDataCompat = bincode::deserialize_from(&mut reader)?;
1919

2020
match compat {
21-
UnwindDataCompat::V1(v1) => Ok(v1),
21+
UnwindDataCompat::V1(v1) => Ok(v1.into()),
22+
UnwindDataCompat::V2(v2) => Ok(v2),
2223
}
2324
}
2425

@@ -42,7 +43,7 @@ impl UnwindData {
4243
}
4344

4445
let mut writer = std::fs::File::create(path.as_ref())?;
45-
let compat = UnwindDataCompat::V1(self.clone());
46+
let compat = UnwindDataCompat::V2(self.clone());
4647
bincode::serialize_into(&mut writer, &compat)?;
4748
Ok(())
4849
}
@@ -63,6 +64,7 @@ impl Debug for UnwindData {
6364

6465
f.debug_struct("UnwindData")
6566
.field("path", &self.path)
67+
.field("timestamp", &self.timestamp)
6668
.field("avma_range", &format_args!("{:x?}", self.avma_range))
6769
.field("base_avma", &format_args!("{:x}", self.base_avma))
6870
.field("base_svma", &format_args!("{:x}", self.base_svma))
@@ -81,11 +83,12 @@ impl Debug for UnwindData {
8183
#[derive(Serialize, Deserialize)]
8284
enum UnwindDataCompat {
8385
V1(UnwindDataV1),
86+
V2(UnwindDataV2),
8487
}
8588

8689
#[doc(hidden)]
8790
#[derive(Serialize, Deserialize, Clone)]
88-
pub struct UnwindDataV1 {
91+
struct UnwindDataV1 {
8992
pub path: String,
9093

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

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)