Skip to content

Commit 110cc81

Browse files
authored
Improve API and docs of fxprof-processed-profile and wholesym slightly (#545)
The only actual API change in this PR is the renaming of a few SymbolManagerConfig methods from `symbols_*` to `symbol_*`, e.g. `windows_symbols_server` to `windows_symbol_server`.
2 parents 2920aa3 + 0b8c8a0 commit 110cc81

File tree

11 files changed

+635
-35564
lines changed

11 files changed

+635
-35564
lines changed

fxprof-processed-profile/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,26 @@ example [`serde_json::to_writer`] or [`serde_json::to_string`].
1515
use fxprof_processed_profile::{Profile, CategoryHandle, CpuDelta, Frame, FrameInfo, FrameFlags, SamplingInterval, Timestamp};
1616
use std::time::SystemTime;
1717

18+
// Creates the following call tree:
19+
//
20+
// App process (pid: 54132) > Main thread (tid: 54132000)
21+
//
22+
// 1 0 Root node
23+
// 1 1 - First callee
24+
1825
let mut profile = Profile::new("My app", SystemTime::now().into(), SamplingInterval::from_millis(1));
1926
let process = profile.add_process("App process", 54132, Timestamp::from_millis_since_reference(0.0));
2027
let thread = profile.add_thread(process, 54132000, Timestamp::from_millis_since_reference(0.0), true);
2128
profile.set_thread_name(thread, "Main thread");
22-
let stack_frames = vec![
23-
FrameInfo { frame: Frame::Label(profile.handle_for_string("Root node")), subcategory: CategoryHandle::OTHER.into(), flags: FrameFlags::empty() },
24-
FrameInfo { frame: Frame::Label(profile.handle_for_string("First callee")), subcategory: CategoryHandle::OTHER.into(), flags: FrameFlags::empty() }
25-
];
26-
let stack = profile.handle_for_stack_frames(thread, stack_frames.into_iter());
27-
profile.add_sample(thread, Timestamp::from_millis_since_reference(0.0), stack, CpuDelta::ZERO, 1);
29+
30+
let root_node_string = profile.handle_for_string("Root node");
31+
let root_frame = profile.handle_for_frame_with_label(thread, root_node_string, CategoryHandle::OTHER, FrameFlags::empty());
32+
let first_callee_string = profile.handle_for_string("First callee");
33+
let first_callee_frame = profile.handle_for_frame_with_label(thread, first_callee_string, CategoryHandle::OTHER, FrameFlags::empty());
34+
35+
let root_stack_node = profile.handle_for_stack(thread, root_frame, None);
36+
let first_callee_node = profile.handle_for_stack(thread, first_callee_frame, Some(root_stack_node));
37+
profile.add_sample(thread, Timestamp::from_millis_since_reference(0.0), Some(first_callee_node), CpuDelta::ZERO, 1);
2838

2939
let writer = std::io::BufWriter::new(output_file);
3040
serde_json::to_writer(writer, &profile)?;

fxprof-processed-profile/src/global_lib_table.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl Serialize for GlobalLibIndex {
9595
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
9696
pub struct LibraryHandle(usize);
9797

98+
/// An iterator returned by [`Profile::lib_used_rva_iter`](crate::Profile::lib_used_rva_iter).
99+
///
100+
/// Yields the set of relative addresses, per library, that are used by stack frames
101+
/// in the profile.
98102
pub struct UsedLibraryAddressesIterator<'a> {
99103
next_used_lib_index: usize,
100104
global_lib_table: &'a GlobalLibTable,

fxprof-processed-profile/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
//! use fxprof_processed_profile::{Profile, CategoryHandle, CpuDelta, FrameHandle, FrameFlags, SamplingInterval, Timestamp};
1414
//! use std::time::SystemTime;
1515
//!
16+
//! // Creates the following call tree:
17+
//! //
18+
//! // App process (pid: 54132) > Main thread (tid: 54132000)
19+
//! //
20+
//! // 1 0 Root node
21+
//! // 1 1 - First callee
22+
//!
1623
//! # fn write_profile(output_file: std::fs::File) -> Result<(), Box<dyn std::error::Error>> {
1724
//! let mut profile = Profile::new("My app", SystemTime::now().into(), SamplingInterval::from_millis(1));
1825
//! let process = profile.add_process("App process", 54132, Timestamp::from_millis_since_reference(0.0));

fxprof-processed-profile/src/profile.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ pub struct SourceLocation {
127127
pub col: Option<u32>,
128128
}
129129

130-
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
130+
/// The unit that should be used for the timeline at the top of the profiler UI.
131+
///
132+
/// Used in [`Profile::set_timeline_unit`].
133+
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
131134
pub enum TimelineUnit {
135+
#[default]
132136
Milliseconds,
133137
Bytes,
134138
}
@@ -1145,6 +1149,12 @@ impl Profile {
11451149
self.counters[counter.0].add_sample(timestamp, value_delta, number_of_operations_delta)
11461150
}
11471151

1152+
/// Returns an iterator with information about which native library addresses
1153+
/// are used by any stack frames stored in this profile.
1154+
pub fn lib_used_rva_iter(&self) -> UsedLibraryAddressesIterator {
1155+
self.global_libs.lib_used_rva_iter()
1156+
}
1157+
11481158
fn resolve_frame_address(
11491159
process: &mut Process,
11501160
frame_address: FrameAddress,
@@ -1284,10 +1294,6 @@ impl Profile {
12841294
fn contains_js_frame(&self) -> bool {
12851295
self.threads.iter().any(|t| t.contains_js_frame())
12861296
}
1287-
1288-
pub fn lib_used_rva_iter(&self) -> UsedLibraryAddressesIterator {
1289-
self.global_libs.lib_used_rva_iter()
1290-
}
12911297
}
12921298

12931299
impl Serialize for Profile {

0 commit comments

Comments
 (0)