Struct fxprof_processed_profile::Profile
source · pub struct Profile { /* private fields */ }
Expand description
Stores the profile data and can be serialized as JSON, via serde::Serialize
.
The profile data is organized into a list of processes with threads. Each thread has its own samples and markers.
use fxprof_processed_profile::{Profile, CategoryHandle, CpuDelta, Frame, SamplingInterval, Timestamp};
use std::time::SystemTime;
let mut profile = Profile::new("My app", SystemTime::now().into(), SamplingInterval::from_millis(1));
let process = profile.add_process("App process", 54132, Timestamp::from_millis_since_reference(0.0));
let thread = profile.add_thread(process, 54132000, Timestamp::from_millis_since_reference(0.0), true);
profile.set_thread_name(thread, "Main thread");
let stack = vec![
(Frame::Label(profile.intern_string("Root node")), CategoryHandle::OTHER.into()),
(Frame::Label(profile.intern_string("First callee")), CategoryHandle::OTHER.into())
];
profile.add_sample(thread, Timestamp::from_millis_since_reference(0.0), stack.into_iter(), CpuDelta::ZERO, 1);
let writer = std::io::BufWriter::new(output_file);
serde_json::to_writer(writer, &profile)?;
Implementations§
source§impl Profile
impl Profile
sourcepub fn new(
product: &str,
reference_timestamp: ReferenceTimestamp,
interval: SamplingInterval
) -> Self
pub fn new(
product: &str,
reference_timestamp: ReferenceTimestamp,
interval: SamplingInterval
) -> Self
Create a new profile.
The product
is the name of the main application which was profiled.
The reference_timestamp
is some arbitrary absolute timestamp which all
other timestamps in the profile data are relative to. The interval
is the intended
time delta between samples.
sourcepub fn set_interval(&mut self, interval: SamplingInterval)
pub fn set_interval(&mut self, interval: SamplingInterval)
Change the declared sampling interval.
sourcepub fn set_reference_timestamp(
&mut self,
reference_timestamp: ReferenceTimestamp
)
pub fn set_reference_timestamp(
&mut self,
reference_timestamp: ReferenceTimestamp
)
Change the reference timestamp.
sourcepub fn set_product(&mut self, product: &str)
pub fn set_product(&mut self, product: &str)
Change the product name.
sourcepub fn add_category(&mut self, name: &str, color: CategoryColor) -> CategoryHandle
pub fn add_category(&mut self, name: &str, color: CategoryColor) -> CategoryHandle
Add a category and return its handle.
Categories are used for stack frames and markers, as part of a “category pair”.
sourcepub fn add_subcategory(
&mut self,
category: CategoryHandle,
name: &str
) -> CategoryPairHandle
pub fn add_subcategory(
&mut self,
category: CategoryHandle,
name: &str
) -> CategoryPairHandle
Add a subcategory for a category, and return the “category pair” handle.
sourcepub fn add_process(
&mut self,
name: &str,
pid: u32,
start_time: Timestamp
) -> ProcessHandle
pub fn add_process(
&mut self,
name: &str,
pid: u32,
start_time: Timestamp
) -> ProcessHandle
Add an empty process. The name, pid and start time can be changed afterwards, but they are required here because they have to be present in the profile JSON.
sourcepub fn set_process_start_time(
&mut self,
process: ProcessHandle,
start_time: Timestamp
)
pub fn set_process_start_time(
&mut self,
process: ProcessHandle,
start_time: Timestamp
)
Change the start time of a process.
sourcepub fn set_process_end_time(
&mut self,
process: ProcessHandle,
end_time: Timestamp
)
pub fn set_process_end_time(
&mut self,
process: ProcessHandle,
end_time: Timestamp
)
Set the end time of a process.
sourcepub fn set_process_name(&mut self, process: ProcessHandle, name: &str)
pub fn set_process_name(&mut self, process: ProcessHandle, name: &str)
Change the name of a process.
sourcepub fn add_lib(&mut self, process: ProcessHandle, library: LibraryInfo)
pub fn add_lib(&mut self, process: ProcessHandle, library: LibraryInfo)
Add a library. This allows symbolication of native stacks once the profile is loaded in the Firefox Profiler.
Each library covers an address space in the virtual memory of a process. Future calls
to Profile::add_sample
with native frames resolve the frame’s code address with
respect to the currently loaded libraries.
sourcepub fn unload_lib(&mut self, process: ProcessHandle, base_address: u64)
pub fn unload_lib(&mut self, process: ProcessHandle, base_address: u64)
Mark the library at the specified base address in the specified process as unloaded,
so that future calls to Profile::add_sample
know about the unloading.
sourcepub fn add_thread(
&mut self,
process: ProcessHandle,
tid: u32,
start_time: Timestamp,
is_main: bool
) -> ThreadHandle
pub fn add_thread(
&mut self,
process: ProcessHandle,
tid: u32,
start_time: Timestamp,
is_main: bool
) -> ThreadHandle
Add an empty thread to the specified process.
sourcepub fn set_thread_name(&mut self, thread: ThreadHandle, name: &str)
pub fn set_thread_name(&mut self, thread: ThreadHandle, name: &str)
Change the name of a thread.
sourcepub fn set_thread_start_time(
&mut self,
thread: ThreadHandle,
start_time: Timestamp
)
pub fn set_thread_start_time(
&mut self,
thread: ThreadHandle,
start_time: Timestamp
)
Change the start time of a thread.
sourcepub fn set_thread_end_time(&mut self, thread: ThreadHandle, end_time: Timestamp)
pub fn set_thread_end_time(&mut self, thread: ThreadHandle, end_time: Timestamp)
Set the end time of a thread.
sourcepub fn intern_string(&mut self, s: &str) -> StringHandle
pub fn intern_string(&mut self, s: &str) -> StringHandle
Turn the string into in a StringHandle
, for use in Frame::Label
.
sourcepub fn add_sample(
&mut self,
thread: ThreadHandle,
timestamp: Timestamp,
frames: impl Iterator<Item = (Frame, CategoryPairHandle)>,
cpu_delta: CpuDelta,
weight: i32
)
pub fn add_sample(
&mut self,
thread: ThreadHandle,
timestamp: Timestamp,
frames: impl Iterator<Item = (Frame, CategoryPairHandle)>,
cpu_delta: CpuDelta,
weight: i32
)
Add a sample to the given thread.
The sample has a timestamp, a stack, a CPU delta, and a weight.
The stack frames are supplied as an iterator. Every frame has an associated category pair.
The CPU delta is the amount of CPU time that the CPU was busy with work for this thread since the previous sample. It should always be less than or equal the time delta between the sample timestamps.
sourcepub fn add_sample_same_stack_zero_cpu(
&mut self,
thread: ThreadHandle,
timestamp: Timestamp,
weight: i32
)
pub fn add_sample_same_stack_zero_cpu(
&mut self,
thread: ThreadHandle,
timestamp: Timestamp,
weight: i32
)
Add a sample with a CPU delta of zero. Internally, multiple consecutive samples with a delta of zero will be combined into one sample with an accumulated weight.
sourcepub fn add_marker<T: ProfilerMarker>(
&mut self,
thread: ThreadHandle,
name: &str,
marker: T,
timing: MarkerTiming
)
pub fn add_marker<T: ProfilerMarker>(
&mut self,
thread: ThreadHandle,
name: &str,
marker: T,
timing: MarkerTiming
)
Add a marker to the given thread.