Crates.io | fxprof-processed-profile |
lib.rs | fxprof-processed-profile |
version | 0.8.1 |
created_at | 2022-05-08 15:01:56.885444+00 |
updated_at | 2025-03-07 21:59:55.022516+00 |
description | Create profiles in the Firefox Profiler's processed profile JSON format. |
homepage | |
repository | https://github.com/mstange/samply/ |
max_upload_size | |
id | 582565 |
size | 226,028 |
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
].
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)?;