Skip to content

Commit c415dc5

Browse files
--wip-- [skip ci]
1 parent 39f4f3a commit c415dc5

8 files changed

Lines changed: 42 additions & 54 deletions

File tree

crates/runner-shared/src/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use crate::debug_info::{DebugInfoPidMapping, ModuleDebugInfo};
1010
use crate::fifo::MarkerType;
1111
use crate::perf_map::ProcessModuleLoadBias;
12-
use crate::unwind_data::UnwindDataPidMapping;
12+
use crate::unwind_data::MappedProcessUnwindData;
1313

1414
#[derive(Serialize, Deserialize)]
1515
pub struct PerfMetadata {
@@ -45,7 +45,7 @@ pub struct PerfMetadata {
4545

4646
/// Per-pid unwind data references, mapping PID to list of unwind data index + mounting info
4747
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
48-
pub unwind_data_pid_mappings_by_pid: HashMap<pid_t, Vec<UnwindDataPidMapping>>,
48+
pub unwind_data_pid_mappings_by_pid: HashMap<pid_t, Vec<MappedProcessUnwindData>>,
4949

5050
/// Per-pid symbol references, mapping PID to list of perf map index + load bias
5151
#[serde(default, skip_serializing_if = "HashMap::is_empty")]

crates/runner-shared/src/unwind_data.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,23 @@ impl Debug for UnwindDataV3 {
163163
}
164164

165165
/// Per-pid mounting info referencing a deduplicated unwind data entry.
166-
#[derive(Serialize, Deserialize, Clone)]
167-
pub struct UnwindDataPidMapping {
166+
#[derive(Debug, Serialize, Deserialize, Clone)]
167+
pub struct MappedProcessUnwindData {
168168
pub unwind_data_key: String,
169+
#[serde(flatten)]
170+
pub inner: ProcessUnwindData,
171+
}
172+
173+
#[derive(Serialize, Deserialize, Clone)]
174+
pub struct ProcessUnwindData {
169175
pub timestamp: Option<u64>,
170176
pub avma_range: Range<u64>,
171177
pub base_avma: u64,
172178
}
173179

174-
impl Debug for UnwindDataPidMapping {
180+
impl Debug for ProcessUnwindData {
175181
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
176-
f.debug_struct("UnwindDataPidMapping")
177-
.field("unwind_data_key", &self.unwind_data_key)
182+
f.debug_struct("ProcessUnwindData")
178183
.field("timestamp", &self.timestamp)
179184
.field("avma_range", &format_args!("{:x?}", self.avma_range))
180185
.field("base_avma", &format_args!("{:x}", self.base_avma))

src/bin/compare_walltime_output.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ fn load_new_format(
177177
entries.push(NormalizedEntry {
178178
path: v3.path.clone(),
179179
base_svma: v3.base_svma,
180-
base_avma: mapping.base_avma,
181-
avma_start: mapping.avma_range.start,
182-
avma_end: mapping.avma_range.end,
183-
timestamp: mapping.timestamp,
180+
base_avma: mapping.inner.base_avma,
181+
avma_start: mapping.inner.avma_range.start,
182+
avma_end: mapping.inner.avma_range.end,
183+
timestamp: mapping.inner.timestamp,
184184
eh_frame_hdr_hash: hash_bytes(&v3.eh_frame_hdr),
185185
eh_frame_hash: hash_bytes(&v3.eh_frame),
186186
});

src/executor/wall_time/perf/debug_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::executor::wall_time::perf::perf_map::ModuleSymbols;
1+
use crate::executor::wall_time::perf::module_symbols::ModuleSymbols;
22
use crate::prelude::*;
33
use addr2line::{fallible_iterator::FallibleIterator, gimli};
44
use object::{Object, ObjectSection};

src/executor/wall_time/perf/jit_dump.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use crate::{
2-
executor::wall_time::perf::perf_map::{ModuleSymbols, Symbol},
2+
executor::wall_time::perf::module_symbols::{ModuleSymbols, Symbol},
33
prelude::*,
44
};
55
use linux_perf_data::jitdump::{JitDumpReader, JitDumpRecord};
6-
use runner_shared::unwind_data::UnwindData;
6+
use runner_shared::unwind_data::{ProcessUnwindData, UnwindData};
77
use std::{
88
collections::{HashMap, HashSet},
99
path::{Path, PathBuf},
1010
};
1111

12-
use super::parse_perf_file::ProcessUnwindData;
13-
1412
struct JitDump {
1513
path: PathBuf,
1614
}

src/executor/wall_time/perf/parse_perf_file.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
use super::perf_map::ModuleSymbols;
1+
use super::module_symbols::ModuleSymbols;
22
use super::unwind_data::unwind_data_from_elf;
33
use crate::prelude::*;
44
use libc::pid_t;
55
use linux_perf_data::PerfFileReader;
66
use linux_perf_data::PerfFileRecord;
77
use linux_perf_data::linux_perf_event_reader::EventRecord;
88
use linux_perf_data::linux_perf_event_reader::RecordType;
9+
use runner_shared::unwind_data::ProcessUnwindData;
910
use runner_shared::unwind_data::UnwindData;
1011
use std::collections::HashMap;
1112
use std::collections::HashSet;
12-
use std::ops::Range;
1313
use std::path::Path;
1414
use std::path::PathBuf;
1515

16-
// TODO: Move this somewhere else ?
1716
#[derive(Default)]
1817
pub struct MountedModule {
1918
/// Symbols extracted from the mapped ELF file
2019
pub module_symbols: Option<ModuleSymbols>,
2120
/// Unwind data extracted from the mapped ELF file
2221
pub unwind_data: Option<UnwindData>,
22+
/// Per-process mounting information
2323
pub process_mounted_module: HashMap<pid_t, ProcessMountedModule>,
2424
}
2525

@@ -32,15 +32,6 @@ pub struct ProcessMountedModule {
3232
pub process_unwind_data: Option<ProcessUnwindData>,
3333
}
3434

35-
// TODO: Move this somehwere else ?
36-
// Or determine if we cannot use the metadata type directly
37-
#[derive(Debug)]
38-
pub struct ProcessUnwindData {
39-
pub timestamp: Option<u64>,
40-
pub base_avma: u64,
41-
pub avma_range: Range<u64>,
42-
}
43-
4435
impl MountedModule {
4536
pub fn pids(&self) -> impl Iterator<Item = pid_t> {
4637
self.process_mounted_module.keys().copied()
@@ -243,7 +234,6 @@ fn process_mmap2_record(
243234
// Extract unwind_data
244235
match unwind_data_from_elf(
245236
record_path_string.as_bytes(),
246-
record.page_offset,
247237
record.address,
248238
end_addr,
249239
None,

src/executor/wall_time/perf/save_artifacts.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use crate::executor::valgrind::helpers::ignored_objects_path::get_objects_path_to_ignore;
22
use crate::executor::wall_time::perf::debug_info::debug_info_by_path;
33
use crate::executor::wall_time::perf::naming;
4-
use crate::executor::wall_time::perf::parse_perf_file::{MountedModule, ProcessUnwindData};
4+
use crate::executor::wall_time::perf::parse_perf_file::MountedModule;
55
use crate::prelude::*;
66
use libc::pid_t;
77
use rayon::prelude::*;
88
use runner_shared::debug_info::{DebugInfoPidMapping, ModuleDebugInfo};
99
use runner_shared::perf_map::ProcessModuleLoadBias;
10-
use runner_shared::unwind_data::{UnwindData, UnwindDataPidMapping};
10+
use runner_shared::unwind_data::{MappedProcessUnwindData, ProcessUnwindData, UnwindData};
1111
use std::collections::HashMap;
1212
use std::path::{Path, PathBuf};
1313

1414
pub struct SavedArtifacts {
1515
pub symbol_pid_mappings_by_pid: HashMap<pid_t, Vec<ProcessModuleLoadBias>>,
1616
pub debug_info: HashMap<String, ModuleDebugInfo>,
1717
pub debug_info_pid_mappings_by_pid: HashMap<pid_t, Vec<DebugInfoPidMapping>>,
18-
pub unwind_data_pid_mappings_by_pid: HashMap<pid_t, Vec<UnwindDataPidMapping>>,
18+
pub unwind_data_pid_mappings_by_pid: HashMap<pid_t, Vec<MappedProcessUnwindData>>,
1919
pub ignored_modules: Vec<(String, u64, u64)>,
2020
pub key_to_path: HashMap<String, PathBuf>,
2121
}
@@ -182,7 +182,7 @@ fn save_unwind_data(
182182
mounted_modules_by_path: &HashMap<PathBuf, MountedModule>,
183183
jit_unwind_data_by_pid: &HashMap<pid_t, Vec<(UnwindData, ProcessUnwindData)>>,
184184
path_to_key: &mut HashMap<PathBuf, String>,
185-
) -> HashMap<pid_t, Vec<UnwindDataPidMapping>> {
185+
) -> HashMap<pid_t, Vec<MappedProcessUnwindData>> {
186186
let unwind_data_count = mounted_modules_by_path
187187
.values()
188188
.filter(|m| m.unwind_data.is_some())
@@ -196,7 +196,7 @@ fn save_unwind_data(
196196
}
197197
});
198198

199-
let mut mappings_by_pid: HashMap<pid_t, Vec<UnwindDataPidMapping>> = HashMap::new();
199+
let mut mappings_by_pid: HashMap<pid_t, Vec<MappedProcessUnwindData>> = HashMap::new();
200200
for (path, m) in mounted_modules_by_path {
201201
if m.unwind_data.is_none() {
202202
continue;
@@ -207,11 +207,13 @@ fn save_unwind_data(
207207
mappings_by_pid
208208
.entry(pid)
209209
.or_default()
210-
.push(UnwindDataPidMapping {
210+
.push(MappedProcessUnwindData {
211211
unwind_data_key: key.clone(),
212-
timestamp: pud.timestamp,
213-
avma_range: pud.avma_range.clone(),
214-
base_avma: pud.base_avma,
212+
inner: runner_shared::unwind_data::ProcessUnwindData {
213+
timestamp: pud.timestamp,
214+
avma_range: pud.avma_range.clone(),
215+
base_avma: pud.base_avma,
216+
},
215217
});
216218
}
217219
}
@@ -226,11 +228,13 @@ fn save_unwind_data(
226228
mappings_by_pid
227229
.entry(pid)
228230
.or_default()
229-
.push(UnwindDataPidMapping {
231+
.push(MappedProcessUnwindData {
230232
unwind_data_key: key,
231-
timestamp: process_unwind_data.timestamp,
232-
avma_range: process_unwind_data.avma_range.clone(),
233-
base_avma: process_unwind_data.base_avma,
233+
inner: runner_shared::unwind_data::ProcessUnwindData {
234+
timestamp: process_unwind_data.timestamp,
235+
avma_range: process_unwind_data.avma_range.clone(),
236+
base_avma: process_unwind_data.base_avma,
237+
},
234238
});
235239
}
236240
}

src/executor/wall_time/perf/unwind_data.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ use anyhow::{Context, bail};
55
use debugid::CodeId;
66
use object::Object;
77
use object::ObjectSection;
8+
use runner_shared::unwind_data::ProcessUnwindData;
89
use runner_shared::unwind_data::UnwindData;
910
use std::ops::Range;
10-
use std::path::Path;
11-
12-
use super::parse_perf_file::ProcessUnwindData;
1311

1412
// Based on: https://github.com/mstange/linux-perf-stuff/blob/22ca6531b90c10dd2a4519351c843b8d7958a451/src/main.rs#L747-L893
1513
pub fn unwind_data_from_elf(
1614
path_slice: &[u8],
17-
runtime_file_offset: u64,
1815
runtime_start_addr: u64,
1916
runtime_end_addr: u64,
2017
build_id: Option<&[u8]>,
@@ -105,11 +102,10 @@ mod tests {
105102
let object = object::File::parse(&file_data[..]).expect("Failed to parse test binary");
106103
let load_bias =
107104
elf_helper::compute_load_bias(start_addr, end_addr, file_offset, &object).unwrap();
108-
println!("Load bias for {}: 0x{:x}", module_path, load_bias);
105+
println!("Load bias for {module_path}: 0x{load_bias:x}");
109106
assert_eq!(
110107
load_bias, expected_load_bias,
111-
"Invalid load bias: {:x} != {:x}",
112-
load_bias, expected_load_bias
108+
"Invalid load bias: {load_bias:x} != {expected_load_bias:x}"
113109
);
114110
load_bias
115111
}
@@ -142,7 +138,6 @@ mod tests {
142138
assert_and_get_load_bias(start_addr, end_addr, file_offset, MODULE_PATH, 0x0);
143139
insta::assert_debug_snapshot!(unwind_data_from_elf(
144140
MODULE_PATH.as_bytes(),
145-
file_offset,
146141
start_addr,
147142
end_addr,
148143
None,
@@ -166,7 +161,6 @@ mod tests {
166161

167162
insta::assert_debug_snapshot!(unwind_data_from_elf(
168163
MODULE_PATH.as_bytes(),
169-
file_offset,
170164
start_addr,
171165
end_addr,
172166
None,
@@ -189,7 +183,6 @@ mod tests {
189183
);
190184
insta::assert_debug_snapshot!(unwind_data_from_elf(
191185
MODULE_PATH.as_bytes(),
192-
file_offset,
193186
start_addr,
194187
end_addr,
195188
None,
@@ -218,7 +211,6 @@ mod tests {
218211
);
219212
insta::assert_debug_snapshot!(unwind_data_from_elf(
220213
MODULE_PATH.as_bytes(),
221-
file_offset,
222214
start_addr,
223215
end_addr,
224216
None,
@@ -248,7 +240,6 @@ mod tests {
248240

249241
insta::assert_debug_snapshot!(unwind_data_from_elf(
250242
MODULE_PATH.as_bytes(),
251-
file_offset,
252243
start_addr,
253244
end_addr,
254245
None,

0 commit comments

Comments
 (0)