Skip to content

Commit 39f4f3a

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

21 files changed

Lines changed: 463 additions & 535 deletions

crates/runner-shared/src/metadata.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Context;
2+
use libc::pid_t;
23
use serde::{Deserialize, Serialize};
34
use std::collections::HashMap;
45
use std::io::BufWriter;
@@ -7,7 +8,7 @@ use std::path::PathBuf;
78

89
use crate::debug_info::{DebugInfoPidMapping, ModuleDebugInfo};
910
use crate::fifo::MarkerType;
10-
use crate::perf_map::SymbolPidMapping;
11+
use crate::perf_map::ProcessModuleLoadBias;
1112
use crate::unwind_data::UnwindDataPidMapping;
1213

1314
#[derive(Serialize, Deserialize)]
@@ -32,23 +33,23 @@ pub struct PerfMetadata {
3233
/// Kept for backward compatibility, was used before deduplication of debug info entries.
3334
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
3435
#[deprecated(note = "Use 'debug_info' + 'debug_info_pid_mappings_by_pid' instead")]
35-
pub debug_info_by_pid: HashMap<i32, Vec<ModuleDebugInfo>>,
36+
pub debug_info_by_pid: HashMap<pid_t, Vec<ModuleDebugInfo>>,
3637

3738
/// Deduplicated debug info entries, keyed by semantic key
3839
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
3940
pub debug_info: HashMap<String, ModuleDebugInfo>,
4041

4142
/// Per-pid debug info references, mapping PID to list of debug info index + load bias
4243
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
43-
pub debug_info_pid_mappings_by_pid: HashMap<i32, Vec<DebugInfoPidMapping>>,
44+
pub debug_info_pid_mappings_by_pid: HashMap<pid_t, Vec<DebugInfoPidMapping>>,
4445

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

4950
/// Per-pid symbol references, mapping PID to list of perf map index + load bias
5051
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
51-
pub symbol_pid_mappings_by_pid: HashMap<i32, Vec<SymbolPidMapping>>,
52+
pub symbol_pid_mappings_by_pid: HashMap<pid_t, Vec<ProcessModuleLoadBias>>,
5253

5354
/// Mapping from semantic key to original binary path
5455
/// Kept for traceability, and if we ever need to reconstruct the original paths from the keys

crates/runner-shared/src/perf_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub const SYMBOLS_MAP_SUFFIX: &str = "symbols.map";
55

66
/// Per-pid mounting info referencing a deduplicated perf map entry.
77
#[derive(Serialize, Deserialize, Clone, Debug)]
8-
pub struct SymbolPidMapping {
8+
pub struct ProcessModuleLoadBias {
99
pub perf_map_key: String,
1010
pub load_bias: u64,
1111
}

crates/runner-shared/src/unwind_data.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,25 @@ impl Debug for UnwindDataV3 {
163163
}
164164

165165
/// Per-pid mounting info referencing a deduplicated unwind data entry.
166-
#[derive(Serialize, Deserialize, Clone, Debug)]
166+
#[derive(Serialize, Deserialize, Clone)]
167167
pub struct UnwindDataPidMapping {
168168
pub unwind_data_key: String,
169169
pub timestamp: Option<u64>,
170170
pub avma_range: Range<u64>,
171171
pub base_avma: u64,
172172
}
173173

174+
impl Debug for UnwindDataPidMapping {
175+
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)
178+
.field("timestamp", &self.timestamp)
179+
.field("avma_range", &format_args!("{:x?}", self.avma_range))
180+
.field("base_avma", &format_args!("{:x}", self.base_avma))
181+
.finish()
182+
}
183+
}
184+
174185
#[cfg(test)]
175186
mod tests {
176187
use super::*;

src/executor/wall_time/perf/debug_info.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,19 @@ impl ModuleDebugInfoExt for ModuleDebugInfo {
107107
/// Compute debug info once per unique ELF path from deduplicated symbols.
108108
/// Returns a map of path -> ModuleDebugInfo with `load_bias: 0` (load bias is per-pid).
109109
pub fn debug_info_by_path(
110-
symbols_by_path: &std::collections::HashMap<
110+
mounted_modules_by_path: &std::collections::HashMap<
111111
std::path::PathBuf,
112-
crate::executor::wall_time::perf::perf_map::ModuleSymbols,
112+
crate::executor::wall_time::perf::parse_perf_file::MountedModule,
113113
>,
114114
) -> std::collections::HashMap<std::path::PathBuf, ModuleDebugInfo> {
115-
symbols_by_path
115+
mounted_modules_by_path
116116
.par_iter()
117-
.filter_map(|(path, module_symbols)| {
117+
.filter_map(|(path, mounted_module)| {
118+
let module_symbols = mounted_module.module_symbols.as_ref()?;
118119
match ModuleDebugInfo::from_symbols(path, module_symbols, 0) {
119120
Ok(module_debug_info) => Some((path.clone(), module_debug_info)),
120121
Err(error) => {
121-
trace!("Failed to load debug info for module {path:?}: {error}",);
122+
trace!("Failed to load debug info for module {path:?}: {error}");
122123
None
123124
}
124125
}
@@ -134,7 +135,8 @@ mod tests {
134135
fn test_golang_debug_info() {
135136
let (start_addr, end_addr, file_offset) =
136137
(0x0000000000402000_u64, 0x000000000050f000_u64, 0x2000);
137-
let module_symbols = ModuleSymbols::new(
138+
let module_symbols = ModuleSymbols::from_elf("testdata/perf_map/go_fib.bin").unwrap();
139+
let load_bias = ModuleSymbols::compute_load_bias(
138140
"testdata/perf_map/go_fib.bin",
139141
start_addr,
140142
end_addr,
@@ -144,7 +146,7 @@ mod tests {
144146
let module_debug_info = ModuleDebugInfo::from_symbols(
145147
"testdata/perf_map/go_fib.bin",
146148
&module_symbols,
147-
module_symbols.load_bias(),
149+
load_bias,
148150
)
149151
.unwrap();
150152
insta::assert_debug_snapshot!(module_debug_info.debug_infos);
@@ -154,7 +156,9 @@ mod tests {
154156
fn test_cpp_debug_info() {
155157
let (start_addr, end_addr, file_offset) =
156158
(0x0000000000400000_u64, 0x0000000000459000_u64, 0x0);
157-
let module_symbols = ModuleSymbols::new(
159+
let module_symbols =
160+
ModuleSymbols::from_elf("testdata/perf_map/cpp_my_benchmark.bin").unwrap();
161+
let load_bias = ModuleSymbols::compute_load_bias(
158162
"testdata/perf_map/cpp_my_benchmark.bin",
159163
start_addr,
160164
end_addr,
@@ -164,7 +168,7 @@ mod tests {
164168
let mut module_debug_info = ModuleDebugInfo::from_symbols(
165169
"testdata/perf_map/cpp_my_benchmark.bin",
166170
&module_symbols,
167-
module_symbols.load_bias(),
171+
load_bias,
168172
)
169173
.unwrap();
170174

@@ -177,29 +181,33 @@ mod tests {
177181
fn test_rust_divan_debug_info() {
178182
const MODULE_PATH: &str = "testdata/perf_map/divan_sleep_benches.bin";
179183

180-
let module_symbols =
181-
ModuleSymbols::new(MODULE_PATH, 0x00005555555a2000, 0x0000555555692000, 0x4d000)
182-
.unwrap();
184+
let module_symbols = ModuleSymbols::from_elf(MODULE_PATH).unwrap();
185+
let load_bias = ModuleSymbols::compute_load_bias(
186+
MODULE_PATH,
187+
0x00005555555a2000,
188+
0x0000555555692000,
189+
0x4d000,
190+
)
191+
.unwrap();
183192
let module_debug_info =
184-
ModuleDebugInfo::from_symbols(MODULE_PATH, &module_symbols, module_symbols.load_bias())
185-
.unwrap();
193+
ModuleDebugInfo::from_symbols(MODULE_PATH, &module_symbols, load_bias).unwrap();
186194
insta::assert_debug_snapshot!(module_debug_info.debug_infos);
187195
}
188196

189197
#[test]
190198
fn test_the_algorithms_debug_info() {
191199
const MODULE_PATH: &str = "testdata/perf_map/the_algorithms.bin";
192200

193-
let module_symbols = ModuleSymbols::new(
201+
let module_symbols = ModuleSymbols::from_elf(MODULE_PATH).unwrap();
202+
let load_bias = ModuleSymbols::compute_load_bias(
194203
MODULE_PATH,
195204
0x00005573e59fe000,
196205
0x00005573e5b07000,
197206
0x00052000,
198207
)
199208
.unwrap();
200209
let module_debug_info =
201-
ModuleDebugInfo::from_symbols(MODULE_PATH, &module_symbols, module_symbols.load_bias())
202-
.unwrap();
210+
ModuleDebugInfo::from_symbols(MODULE_PATH, &module_symbols, load_bias).unwrap();
203211
insta::assert_debug_snapshot!(module_debug_info.debug_infos);
204212
}
205213

@@ -209,11 +217,12 @@ mod tests {
209217

210218
let (start_addr, end_addr, file_offset) =
211219
(0x0000555555e6d000_u64, 0x0000555556813000_u64, 0x918000);
212-
let module_symbols =
213-
ModuleSymbols::new(MODULE_PATH, start_addr, end_addr, file_offset).unwrap();
214-
let module_debug_info =
215-
ModuleDebugInfo::from_symbols(MODULE_PATH, &module_symbols, module_symbols.load_bias())
220+
let module_symbols = ModuleSymbols::from_elf(MODULE_PATH).unwrap();
221+
let load_bias =
222+
ModuleSymbols::compute_load_bias(MODULE_PATH, start_addr, end_addr, file_offset)
216223
.unwrap();
224+
let module_debug_info =
225+
ModuleDebugInfo::from_symbols(MODULE_PATH, &module_symbols, load_bias).unwrap();
217226
insta::assert_debug_snapshot!(module_debug_info.debug_infos);
218227
}
219228
}

src/executor/wall_time/perf/elf_helper.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,6 @@ pub fn relative_address_base(object_file: &object::File) -> u64 {
185185
object_file.relative_address_base()
186186
}
187187

188-
pub fn compute_base_avma(
189-
runtime_start_addr: u64,
190-
runtime_end_addr: u64,
191-
runtime_file_offset: u64,
192-
object: &object::File,
193-
) -> anyhow::Result<u64> {
194-
let bias = compute_load_bias(
195-
runtime_start_addr,
196-
runtime_end_addr,
197-
runtime_file_offset,
198-
object,
199-
)?;
200-
let base_svma = relative_address_base(object);
201-
Ok(base_svma.wrapping_add(bias))
188+
pub fn compute_base_avma(base_svma: u64, load_bias: u64) -> u64 {
189+
base_svma.wrapping_add(load_bias)
202190
}

0 commit comments

Comments
 (0)