Skip to content

Commit 41fe653

Browse files
committed
Collect used addresses on demand.
1 parent f0e588b commit 41fe653

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed

‎fxprof-processed-profile/src/frame_table.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::category::{CategoryHandle, SubcategoryHandle, SubcategoryIndex};
44
use crate::fast_hash_map::FastIndexSet;
55
use crate::frame::FrameFlags;
66
use crate::func_table::{FuncIndex, FuncKey, FuncTable};
7-
use crate::global_lib_table::{GlobalLibIndex, GlobalLibTable};
7+
use crate::global_lib_table::{GlobalLibIndex, UsedLibraryAddressesCollector};
88
use crate::native_symbols::NativeSymbolIndex;
99
use crate::resource_table::ResourceTable;
1010
use crate::serialization_helpers::SerializableSingleValueColumn;
@@ -22,31 +22,30 @@ impl FrameInterner {
2222
Default::default()
2323
}
2424

25-
pub fn index_for_frame(
26-
&mut self,
27-
frame: InternalFrame,
28-
global_libs: &mut GlobalLibTable,
29-
) -> usize {
25+
pub fn index_for_frame(&mut self, frame: InternalFrame) -> usize {
3026
let (frame_index, is_new) = self.frame_key_set.insert_full(frame);
3127

32-
if is_new {
33-
if frame
28+
if is_new
29+
&& frame
3430
.flags
3531
.intersects(FrameFlags::IS_JS | FrameFlags::IS_RELEVANT_FOR_JS)
36-
{
37-
self.contains_js_frame = true;
38-
}
32+
{
33+
self.contains_js_frame = true;
34+
}
35+
frame_index
36+
}
3937

38+
pub fn gather_used_rvas(&self, collector: &mut UsedLibraryAddressesCollector) {
39+
for frame in &self.frame_key_set {
4040
if let InternalFrameVariant::Native(NativeFrameData {
4141
lib,
4242
relative_address,
4343
..
4444
}) = frame.variant
4545
{
46-
global_libs.add_lib_used_rva(lib, relative_address);
46+
collector.add_lib_used_rva(lib, relative_address);
4747
}
4848
}
49-
frame_index
5049
}
5150

5251
pub fn contains_js_frame(&self) -> bool {

‎fxprof-processed-profile/src/global_lib_table.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ pub struct GlobalLibTable {
1717
/// Indexed by `GlobalLibIndex.0`.
1818
used_libs: Vec<LibraryHandle>, // append-only for stable GlobalLibIndexes
1919
used_lib_map: FastHashMap<LibraryHandle, GlobalLibIndex>,
20+
}
21+
22+
#[derive(Debug)]
23+
pub struct UsedLibraryAddressesCollector {
2024
/// We keep track of RVA addresses that exist in frames that are assigned to this
2125
/// library, so that we can potentially provide symbolication info ahead of time.
2226
/// This is here instead of in `LibraryInfo` because we don't want to serialize it,
@@ -32,7 +36,6 @@ impl GlobalLibTable {
3236
symbol_tables: FastHashMap::default(),
3337
used_libs: Vec::new(),
3438
used_lib_map: FastHashMap::default(),
35-
used_libs_seen_rvas: Vec::new(),
3639
}
3740
}
3841

@@ -55,7 +58,6 @@ impl GlobalLibTable {
5558
let name_index = string_table.index_for_string(&lib.name);
5659
let index = GlobalLibIndex(used_libs.len(), name_index);
5760
used_libs.push(lib_handle);
58-
self.used_libs_seen_rvas.push(BTreeSet::new());
5961
index
6062
})
6163
}
@@ -65,14 +67,26 @@ impl GlobalLibTable {
6567
self.symbol_tables.get(handle).map(|v| &**v)
6668
}
6769

70+
pub fn address_collector(&self) -> UsedLibraryAddressesCollector {
71+
UsedLibraryAddressesCollector {
72+
used_libs_seen_rvas: vec![BTreeSet::new(); self.used_libs.len()],
73+
}
74+
}
75+
}
76+
77+
impl UsedLibraryAddressesCollector {
6878
pub fn add_lib_used_rva(&mut self, index: GlobalLibIndex, address: u32) {
6979
self.used_libs_seen_rvas[index.0].insert(address);
7080
}
7181

72-
pub fn lib_used_rva_iter(&self) -> UsedLibraryAddressesIterator {
82+
pub fn into_address_iter(
83+
self,
84+
global_lib_table: &GlobalLibTable,
85+
) -> UsedLibraryAddressesIterator {
7386
UsedLibraryAddressesIterator {
7487
next_used_lib_index: 0,
75-
global_lib_table: self,
88+
used_libs_seen_rvas_iter: self.used_libs_seen_rvas.into_iter(),
89+
global_lib_table,
7690
}
7791
}
7892
}
@@ -110,17 +124,15 @@ pub struct LibraryHandle(usize);
110124
/// in the profile.
111125
pub struct UsedLibraryAddressesIterator<'a> {
112126
next_used_lib_index: usize,
127+
used_libs_seen_rvas_iter: std::vec::IntoIter<BTreeSet<u32>>,
113128
global_lib_table: &'a GlobalLibTable,
114129
}
115130

116131
impl<'a> Iterator for UsedLibraryAddressesIterator<'a> {
117-
type Item = (&'a LibraryInfo, &'a BTreeSet<u32>);
132+
type Item = (&'a LibraryInfo, BTreeSet<u32>);
118133

119134
fn next(&mut self) -> Option<Self::Item> {
120-
let rvas = self
121-
.global_lib_table
122-
.used_libs_seen_rvas
123-
.get(self.next_used_lib_index)?;
135+
let rvas = self.used_libs_seen_rvas_iter.next()?;
124136

125137
let lib_handle = self.global_lib_table.used_libs[self.next_used_lib_index];
126138
let info = &self.global_lib_table.all_libs[lib_handle.0];

‎fxprof-processed-profile/src/profile.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl Profile {
647647
name,
648648
source_location: Default::default(),
649649
};
650-
let frame_index = thread.frame_index_for_frame(internal_frame, &mut self.global_libs);
650+
let frame_index = thread.frame_index_for_frame(internal_frame);
651651
FrameHandle(thread_handle, frame_index)
652652
}
653653

@@ -691,7 +691,7 @@ impl Profile {
691691
source_location,
692692
flags,
693693
};
694-
let frame_index = thread.frame_index_for_frame(internal_frame, &mut self.global_libs);
694+
let frame_index = thread.frame_index_for_frame(internal_frame);
695695
FrameHandle(thread_handle, frame_index)
696696
}
697697

@@ -771,7 +771,7 @@ impl Profile {
771771
source_location,
772772
flags,
773773
};
774-
let frame_index = thread.frame_index_for_frame(internal_frame, &mut self.global_libs);
774+
let frame_index = thread.frame_index_for_frame(internal_frame);
775775
FrameHandle(thread_handle, frame_index)
776776
}
777777

@@ -1153,7 +1153,11 @@ impl Profile {
11531153
/// Returns an iterator with information about which native library addresses
11541154
/// are used by any stack frames stored in this profile.
11551155
pub fn lib_used_rva_iter(&self) -> UsedLibraryAddressesIterator {
1156-
self.global_libs.lib_used_rva_iter()
1156+
let mut collector = self.global_libs.address_collector();
1157+
for thread in &self.threads {
1158+
thread.gather_used_rvas(&mut collector);
1159+
}
1160+
collector.into_address_iter(&self.global_libs)
11571161
}
11581162

11591163
fn resolve_frame_address(

‎fxprof-processed-profile/src/thread.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::ser::{SerializeMap, Serializer};
66
use crate::cpu_delta::CpuDelta;
77
use crate::fast_hash_map::FastHashSet;
88
use crate::frame_table::{FrameInterner, InternalFrame};
9-
use crate::global_lib_table::{GlobalLibIndex, GlobalLibTable};
9+
use crate::global_lib_table::{GlobalLibIndex, UsedLibraryAddressesCollector};
1010
use crate::marker_table::MarkerTable;
1111
use crate::markers::InternalMarkerSchema;
1212
use crate::native_symbols::{NativeSymbolIndex, NativeSymbols};
@@ -109,12 +109,8 @@ impl Thread {
109109
.get_native_symbol_name(native_symbol_index)
110110
}
111111

112-
pub fn frame_index_for_frame(
113-
&mut self,
114-
frame: InternalFrame,
115-
global_libs: &mut GlobalLibTable,
116-
) -> usize {
117-
self.frame_interner.index_for_frame(frame, global_libs)
112+
pub fn frame_index_for_frame(&mut self, frame: InternalFrame) -> usize {
113+
self.frame_interner.index_for_frame(frame)
118114
}
119115

120116
pub fn stack_index_for_stack(&mut self, prefix: Option<usize>, frame: usize) -> usize {
@@ -191,6 +187,10 @@ impl Thread {
191187
self.frame_interner.contains_js_frame()
192188
}
193189

190+
pub fn gather_used_rvas(&self, collector: &mut UsedLibraryAddressesCollector) {
191+
self.frame_interner.gather_used_rvas(collector);
192+
}
193+
194194
pub fn cmp_for_json_order(&self, other: &Thread) -> Ordering {
195195
let ordering = (!self.is_main).cmp(&(!other.is_main));
196196
if ordering != Ordering::Equal {

‎samply/src/shared/symbol_precog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub fn presymbolicate(
357357
.as_ref()
358358
.map(|id| wholesym::CodeId::from_str(id).expect("bad codeid")),
359359
};
360-
let rvas: Vec<u32> = rvas.iter().copied().collect();
360+
let rvas: Vec<u32> = rvas.into_iter().collect();
361361
(lib_info, rvas)
362362
})
363363
.collect();

0 commit comments

Comments
 (0)