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§

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.

Change the declared sampling interval.

Change the reference timestamp.

Change the product name.

Add a category and return its handle.

Categories are used for stack frames and markers, as part of a “category pair”.

Add a subcategory for a category, and return the “category pair” handle.

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.

Change the start time of a process.

Set the end time of a process.

Change the name of a process.

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.

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.

Add an empty thread to the specified process.

Change the name of a thread.

Change the start time of a thread.

Set the end time of a thread.

Turn the string into in a StringHandle, for use in Frame::Label.

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.

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.

Add a marker to the given thread.

Trait Implementations§

Formats the value using the given formatter. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.