Skip to content

Commit c947d63

Browse files
authored
Make SymbolMap lookups return handles for function names and symbol names (#718)
Using handles instead of owned strings allows us to significantly reduce the number of allocations when computing the response JSON in the symbolication API.
2 parents d47b3cd + 6123351 commit c947d63

File tree

25 files changed

+885
-558
lines changed

25 files changed

+885
-558
lines changed

samply-api/src/symbolicate/looked_up_addresses.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
use std::collections::BTreeMap;
22

3-
use samply_symbols::{FrameDebugInfo, SourceFilePath, SourceFilePathHandle, SymbolInfo};
4-
5-
pub trait PathResolver {
6-
fn resolve_source_file_path(&self, handle: SourceFilePathHandle) -> SourceFilePath<'_>;
7-
}
8-
9-
impl PathResolver for () {
10-
fn resolve_source_file_path(&self, _handle: SourceFilePathHandle) -> SourceFilePath<'_> {
11-
unreachable!()
12-
}
13-
}
3+
use samply_symbols::{FrameDebugInfo, FunctionNameHandle, SymbolInfo};
144

155
pub struct AddressResult {
166
pub symbol: SymbolInfo,
7+
/// The function name from debug info, if available. This may be more
8+
/// accurate than the symbol name from the symbol table.
9+
pub function_name: Option<FunctionNameHandle>,
1710
pub inline_frames: Option<Vec<FrameDebugInfo>>,
1811
}
1912

2013
impl AddressResult {
2114
pub fn new(symbol: SymbolInfo) -> Self {
2215
Self {
2316
symbol,
17+
function_name: None,
2418
inline_frames: None,
2519
}
2620
}
2721

2822
pub fn set_debug_info(&mut self, frames: Vec<FrameDebugInfo>) {
29-
let outer_function_name = frames.last().and_then(|f| f.function.as_ref());
30-
// Overwrite the symbol name with the function name from the debug info.
31-
if let Some(name) = outer_function_name {
32-
self.symbol.name = name.clone();
33-
}
23+
// Store the outer function name from debug info if available.
24+
self.function_name = frames.last().and_then(|f| f.function);
3425
// Add the inline frame info.
3526
self.inline_frames = Some(frames);
3627
}

samply-api/src/symbolicate/mod.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::sync::Arc;
33

44
use samply_symbols::{
55
AccessPatternHint, FileAndPathHelper, FramesLookupResult, LibraryInfo, LookupAddress,
6-
SourceFilePath, SourceFilePathHandle, SymbolManager, SymbolMap,
6+
SymbolManager,
77
};
88

99
use crate::error::Error;
10-
use crate::symbolicate::looked_up_addresses::{AddressResult, AddressResults, PathResolver};
11-
use crate::symbolicate::response_json::{PerLibResult, Response};
10+
use crate::symbolicate::looked_up_addresses::{AddressResult, AddressResults};
11+
use crate::symbolicate::response_json::{LibSymbols, Response};
1212
use crate::to_debug_id;
1313

1414
pub mod looked_up_addresses;
@@ -17,12 +17,6 @@ pub mod response_json;
1717

1818
use request_json::Lib;
1919

20-
impl<H: FileAndPathHelper> PathResolver for SymbolMap<H> {
21-
fn resolve_source_file_path(&self, handle: SourceFilePathHandle) -> SourceFilePath<'_> {
22-
self.resolve_source_file_path(handle)
23-
}
24-
}
25-
2620
pub struct SymbolicateApi<'a, H: FileAndPathHelper> {
2721
symbol_manager: &'a SymbolManager<H>,
2822
}
@@ -46,19 +40,19 @@ impl<'a, H: FileAndPathHelper + 'static> SymbolicateApi<'a, H> {
4640
request: request_json::Request,
4741
) -> Result<response_json::Response<H>, Error> {
4842
let requested_addresses = gather_requested_addresses(&request)?;
49-
let per_lib_results = self
43+
let symbols_per_lib = self
5044
.symbolicate_requested_addresses(requested_addresses)
5145
.await;
5246
Ok(Response {
5347
request,
54-
per_lib_results,
48+
symbols_per_lib,
5549
})
5650
}
5751

5852
async fn symbolicate_requested_addresses(
5953
&self,
6054
requested_addresses: HashMap<Lib, Vec<u32>>,
61-
) -> HashMap<Lib, Result<PerLibResult<H>, samply_symbols::Error>> {
55+
) -> HashMap<Lib, Result<LibSymbols<H>, samply_symbols::Error>> {
6256
let mut symbolicated_addresses = HashMap::new();
6357
for (lib, addresses) in requested_addresses.into_iter() {
6458
let address_results = self
@@ -73,7 +67,7 @@ impl<'a, H: FileAndPathHelper + 'static> SymbolicateApi<'a, H> {
7367
&self,
7468
lib: &Lib,
7569
addresses: &[u32],
76-
) -> Result<PerLibResult<H>, samply_symbols::Error> {
70+
) -> Result<LibSymbols<H>, samply_symbols::Error> {
7771
let debug_id = to_debug_id(&lib.breakpad_id)?;
7872

7973
let info = LibraryInfo {
@@ -124,7 +118,7 @@ impl<'a, H: FileAndPathHelper + 'static> SymbolicateApi<'a, H> {
124118
}
125119
}
126120

127-
let outcome = PerLibResult {
121+
let outcome = LibSymbols {
128122
address_results,
129123
symbol_map: Arc::new(symbol_map),
130124
};

0 commit comments

Comments
 (0)