Skip to content

Commit 00acbdb

Browse files
committed
refactor(walltime): extract symbolication module from perf/
Move ELF/DWARF artifact extraction (elf_helper, module_symbols, unwind_data, debug_info, jit_dump) and the LoadedModule struct out of perf/ into a shared symbolication/ module. These helpers are agnostic to which sampling tool produced the module list and will be reused by future Linux profilers.
1 parent 1b8e676 commit 00acbdb

28 files changed

Lines changed: 59128 additions & 48 deletions

File tree

src/executor/wall_time/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pub mod helpers;
33
pub mod isolation;
44
pub mod perf;
55
pub mod profiler;
6+
pub mod symbolication;

src/executor/wall_time/perf/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@ use std::path::Path;
2828
use std::path::PathBuf;
2929
use std::{cell::OnceCell, process::ExitStatus};
3030

31-
mod jit_dump;
3231
mod naming;
3332
mod parse_perf_file;
3433
mod save_artifacts;
3534
pub(crate) mod setup;
3635

37-
pub mod debug_info;
38-
pub mod elf_helper;
3936
pub mod fifo;
40-
pub mod module_symbols;
4137
pub mod perf_executable;
42-
pub mod unwind_data;
4338

4439
const PERF_METADATA_CURRENT_VERSION: u64 = 1;
4540
const PERF_PIPEDATA_FILE_NAME: &str = "perf.pipedata";
@@ -318,7 +313,7 @@ impl BenchmarkData {
318313
BenchmarkDataSaveError::FailedToHarvestPerfMaps
319314
})?;
320315
let jit_unwind_data_by_pid =
321-
jit_dump::save_symbols_and_harvest_unwind_data_for_pids(path_ref, &tracked_pids)
316+
crate::executor::wall_time::symbolication::jit_dump::save_symbols_and_harvest_unwind_data_for_pids(path_ref, &tracked_pids)
322317
.await
323318
.map_err(|e| {
324319
error!("Failed to harvest jit dumps: {e}");

src/executor/wall_time/perf/parse_perf_file.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
1-
use super::module_symbols::ModuleSymbols;
2-
use super::unwind_data::unwind_data_from_elf;
1+
use crate::executor::wall_time::symbolication::loaded_module::LoadedModule;
2+
use crate::executor::wall_time::symbolication::module_symbols::ModuleSymbols;
3+
use crate::executor::wall_time::symbolication::unwind_data::unwind_data_from_elf;
34
use crate::prelude::*;
45
use libc::pid_t;
56
use linux_perf_data::PerfFileReader;
67
use linux_perf_data::PerfFileRecord;
78
use linux_perf_data::linux_perf_event_reader::EventRecord;
89
use linux_perf_data::linux_perf_event_reader::RecordType;
9-
use runner_shared::unwind_data::ProcessUnwindData;
10-
use runner_shared::unwind_data::UnwindData;
1110
use std::collections::HashMap;
1211
use std::collections::HashSet;
1312
use std::path::Path;
1413
use std::path::PathBuf;
1514

16-
#[derive(Default)]
17-
pub struct LoadedModule {
18-
/// Symbols extracted from the mapped ELF file
19-
pub module_symbols: Option<ModuleSymbols>,
20-
/// Unwind data extracted from the mapped ELF file
21-
pub unwind_data: Option<UnwindData>,
22-
/// Per-process mounting information
23-
pub process_loaded_modules: HashMap<pid_t, ProcessLoadedModule>,
24-
}
25-
26-
#[derive(Default)]
27-
pub struct ProcessLoadedModule {
28-
/// Load bias used to adjust declared elf addresses to their actual runtime addresses
29-
/// The bias is the difference between where the segment *actually* is in memory versus where the ELF file *preferred* it to be
30-
pub symbols_load_bias: Option<u64>,
31-
/// Unwind data specific to the process mounting, derived from both load bias and the actual unwind data
32-
pub process_unwind_data: Option<ProcessUnwindData>,
33-
}
34-
35-
impl LoadedModule {
36-
pub fn pids(&self) -> impl Iterator<Item = pid_t> {
37-
self.process_loaded_modules.keys().copied()
38-
}
39-
}
40-
4115
pub struct MemmapRecordsOutput {
4216
/// Module symbols and the computed load bias for each pid that maps the ELF path.
4317
pub loaded_modules_by_path: HashMap<PathBuf, LoadedModule>,

src/executor/wall_time/perf/save_artifacts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::executor::valgrind::helpers::ignored_objects_path::get_objects_path_to_ignore;
2-
use crate::executor::wall_time::perf::debug_info::debug_info_by_path;
32
use crate::executor::wall_time::perf::naming;
4-
use crate::executor::wall_time::perf::parse_perf_file::LoadedModule;
3+
use crate::executor::wall_time::symbolication::debug_info::debug_info_by_path;
4+
use crate::executor::wall_time::symbolication::loaded_module::LoadedModule;
55
use crate::prelude::*;
66
use libc::pid_t;
77
use rayon::prelude::*;

src/executor/wall_time/perf/snapshots/codspeed_runner__executor__wall_time__perf__debug_info__tests__ruff_debug_info.snap

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

src/executor/wall_time/perf/snapshots/codspeed_runner__executor__wall_time__perf__module_symbols__tests__ruff_symbols.snap

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

src/executor/wall_time/perf/debug_info.rs renamed to src/executor/wall_time/symbolication/debug_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::elf_helper::find_debug_file;
2-
use super::parse_perf_file::LoadedModule;
3-
use crate::executor::wall_time::perf::module_symbols::ModuleSymbols;
2+
use super::loaded_module::LoadedModule;
3+
use super::module_symbols::ModuleSymbols;
44
use crate::prelude::*;
55
use addr2line::{fallible_iterator::FallibleIterator, gimli};
66
use object::{Object, ObjectSection};
File renamed without changes.

src/executor/wall_time/perf/jit_dump.rs renamed to src/executor/wall_time/symbolication/jit_dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
executor::wall_time::perf::module_symbols::{ModuleSymbols, Symbol},
2+
executor::wall_time::symbolication::module_symbols::{ModuleSymbols, Symbol},
33
prelude::*,
44
};
55
use linux_perf_data::jitdump::{JitDumpReader, JitDumpRecord};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::executor::wall_time::symbolication::module_symbols::ModuleSymbols;
2+
use libc::pid_t;
3+
use runner_shared::unwind_data::{ProcessUnwindData, UnwindData};
4+
use std::collections::HashMap;
5+
6+
/// A loaded ELF module discovered while parsing a profiler's sample stream.
7+
///
8+
/// Holds the symbol/unwind data extracted from the file plus the per-process
9+
/// mounting metadata (load bias and rebased unwind data) for every pid that
10+
/// mapped this module.
11+
#[derive(Default)]
12+
pub struct LoadedModule {
13+
/// Symbols extracted from the mapped ELF file
14+
pub module_symbols: Option<ModuleSymbols>,
15+
/// Unwind data extracted from the mapped ELF file
16+
pub unwind_data: Option<UnwindData>,
17+
/// Per-process mounting information
18+
pub process_loaded_modules: HashMap<pid_t, ProcessLoadedModule>,
19+
}
20+
21+
#[derive(Default)]
22+
pub struct ProcessLoadedModule {
23+
/// Load bias used to adjust declared elf addresses to their actual runtime addresses
24+
/// The bias is the difference between where the segment *actually* is in memory versus where the ELF file *preferred* it to be
25+
pub symbols_load_bias: Option<u64>,
26+
/// Unwind data specific to the process mounting, derived from both load bias and the actual unwind data
27+
pub process_unwind_data: Option<ProcessUnwindData>,
28+
}
29+
30+
impl LoadedModule {
31+
pub fn pids(&self) -> impl Iterator<Item = pid_t> {
32+
self.process_loaded_modules.keys().copied()
33+
}
34+
}

0 commit comments

Comments
 (0)