#json-format #profile #firefox #profiler #processed #serde-json #sampling

fxprof-processed-profile

Create profiles in the Firefox Profiler's processed profile JSON format

9 releases (breaking)

new 0.8.1 Mar 7, 2025
0.7.0 Apr 15, 2024
0.6.0 Apr 22, 2023
0.5.0 Jan 6, 2023
0.4.0 May 23, 2022

#36 in Profiling

Download history 48801/week @ 2024-11-19 42156/week @ 2024-11-26 54720/week @ 2024-12-03 49931/week @ 2024-12-10 45687/week @ 2024-12-17 23236/week @ 2024-12-24 30391/week @ 2024-12-31 54702/week @ 2025-01-07 47875/week @ 2025-01-14 48973/week @ 2025-01-21 43794/week @ 2025-01-28 46788/week @ 2025-02-04 40372/week @ 2025-02-11 48741/week @ 2025-02-18 52900/week @ 2025-02-25 44995/week @ 2025-03-04

195,097 downloads per month
Used in 66 crates (4 directly)

MIT/Apache

180KB
3K SLoC

fxprof-processed-profile

This crate allows you to create a profile that can be loaded into the Firefox Profiler.

Specifically, this uses the "Processed profile format".

Use Profile::new to create a new Profile object. Then add all the information into it. To convert it to JSON, use serde_json, for example serde_json::to_writer or serde_json::to_string.

Example

use fxprof_processed_profile::{Profile, CategoryHandle, CpuDelta, Frame, FrameInfo, FrameFlags, 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_frames = vec![
    FrameInfo { frame: Frame::Label(profile.intern_string("Root node")), category_pair: CategoryHandle::OTHER.into(), flags: FrameFlags::empty() },
    FrameInfo { frame: Frame::Label(profile.intern_string("First callee")), category_pair: CategoryHandle::OTHER.into(), flags: FrameFlags::empty() }
];
let stack = profile.intern_stack_frames(thread, stack_frames.into_iter());
profile.add_sample(thread, Timestamp::from_millis_since_reference(0.0), stack, CpuDelta::ZERO, 1);

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

Dependencies

~1–2MB
~41K SLoC