Skip to content

Commit de66bc9

Browse files
committed
Use binary search when looking up addresses in the PrecogLibrarySymbols SymbolMap.
The known addresses in the JSON are sorted, because we got them from a BTreeSet.
1 parent c980ed9 commit de66bc9

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

samply/src/shared/symbol_precog.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ struct PrecogLibrarySymbols {
158158
debug_id: String,
159159
code_id: String,
160160
symbol_table: Vec<InternedSymbolInfo>,
161-
// vector of (rva, index in symbol_table) so that multiple addresses
162-
// within a function map to the same symbol
161+
162+
/// Vector of (rva, index in symbol_table) so that multiple addresses
163+
/// within a function can share symbol info.
164+
///
165+
/// Sorted by rva.
163166
known_addresses: Vec<(u32, usize)>,
164167

165168
#[serde(skip)]
@@ -264,37 +267,34 @@ impl wholesym::samply_symbols::SymbolMapTrait for PrecogLibrarySymbols {
264267
fn lookup_sync(&self, address: wholesym::LookupAddress) -> Option<wholesym::SyncAddressInfo> {
265268
match address {
266269
wholesym::LookupAddress::Relative(rva) => {
267-
for (known_rva, sym_index) in &self.known_addresses {
268-
if *known_rva == rva {
269-
//eprintln!("lookup_sync: 0x{:x} -> {}", rva, info.symbol.0);
270-
let info = &self.symbol_table[*sym_index];
271-
return Some(wholesym::SyncAddressInfo {
272-
symbol: wholesym::SymbolInfo {
273-
address: info.rva,
274-
size: info.size,
275-
name: self.get_owned_string(info.symbol),
276-
},
277-
frames: info.frames.as_ref().map(|frames| {
278-
wholesym::FramesLookupResult::Available(
279-
frames
280-
.iter()
281-
.map(|frame| wholesym::FrameDebugInfo {
282-
function: self.get_owned_opt_string(frame.function),
283-
file_path: frame.file.map(|file| {
284-
SourceFilePath::new(
285-
self.get_string(file).to_owned(),
286-
None,
287-
)
288-
}),
289-
line_number: frame.line,
290-
})
291-
.collect(),
292-
)
293-
}),
294-
});
295-
}
296-
}
297-
None
270+
let Ok(entry_index) = self.known_addresses.binary_search_by_key(&rva, |ka| ka.0)
271+
else {
272+
return None;
273+
};
274+
let sym_index = self.known_addresses[entry_index].1;
275+
//eprintln!("lookup_sync: {:#x} -> {}", rva, sym_index);
276+
let info = &self.symbol_table[sym_index];
277+
Some(wholesym::SyncAddressInfo {
278+
symbol: wholesym::SymbolInfo {
279+
address: info.rva,
280+
size: info.size,
281+
name: self.get_owned_string(info.symbol),
282+
},
283+
frames: info.frames.as_ref().map(|frames| {
284+
wholesym::FramesLookupResult::Available(
285+
frames
286+
.iter()
287+
.map(|frame| wholesym::FrameDebugInfo {
288+
function: self.get_owned_opt_string(frame.function),
289+
file_path: frame.file.map(|file| {
290+
SourceFilePath::new(self.get_string(file).to_owned(), None)
291+
}),
292+
line_number: frame.line,
293+
})
294+
.collect(),
295+
)
296+
}),
297+
})
298298
}
299299
wholesym::LookupAddress::Svma(_) => None,
300300
wholesym::LookupAddress::FileOffset(_) => None,

0 commit comments

Comments
 (0)