fxprof_processed_profile/
lib.rs

1//! This crate allows you to create a profile that can be loaded into
2//! the [Firefox Profiler](https://profiler.firefox.com/).
3//!
4//! Specifically, this uses the ["Processed profile format"](https://github.com/firefox-devtools/profiler/blob/main/docs-developer/processed-profile-format.md).
5//!
6//! Use [`Profile::new`] to create a new [`Profile`] object. Then add all the
7//! information into it. To convert it to JSON, use [`serde_json`], for
8//! example [`serde_json::to_writer`] or [`serde_json::to_string`].
9//!
10//! ## Example
11//!
12//! ```
13//! use fxprof_processed_profile::{Profile, CategoryHandle, CpuDelta, Frame, FrameInfo, FrameFlags, SamplingInterval, Timestamp};
14//! use std::time::SystemTime;
15//!
16//! # fn write_profile(output_file: std::fs::File) -> Result<(), Box<dyn std::error::Error>> {
17//! let mut profile = Profile::new("My app", SystemTime::now().into(), SamplingInterval::from_millis(1));
18//! let process = profile.add_process("App process", 54132, Timestamp::from_millis_since_reference(0.0));
19//! let thread = profile.add_thread(process, 54132000, Timestamp::from_millis_since_reference(0.0), true);
20//! profile.set_thread_name(thread, "Main thread");
21//! let stack = vec![
22//!     FrameInfo { frame: Frame::Label(profile.intern_string("Root node")), category_pair: CategoryHandle::OTHER.into(), flags: FrameFlags::empty() },
23//!     FrameInfo { frame: Frame::Label(profile.intern_string("First callee")), category_pair: CategoryHandle::OTHER.into(), flags: FrameFlags::empty() }
24//! ];
25//! profile.add_sample(thread, Timestamp::from_millis_since_reference(0.0), stack.into_iter(), CpuDelta::ZERO, 1);
26//!
27//! let writer = std::io::BufWriter::new(output_file);
28//! serde_json::to_writer(writer, &profile)?;
29//! # Ok(())
30//! # }
31//! ```
32
33pub use debugid;
34
35mod category;
36mod category_color;
37mod counters;
38mod cpu_delta;
39mod fast_hash_map;
40mod frame;
41mod frame_table;
42mod func_table;
43mod global_lib_table;
44mod lib_mappings;
45mod library_info;
46mod marker_table;
47mod markers;
48mod native_symbols;
49mod process;
50mod profile;
51mod reference_timestamp;
52mod resource_table;
53mod sample_table;
54mod serialization_helpers;
55mod stack_table;
56mod string_table;
57mod thread;
58mod thread_string_table;
59mod timestamp;
60
61pub use category::{CategoryHandle, CategoryPairHandle};
62pub use category_color::CategoryColor;
63pub use counters::CounterHandle;
64pub use cpu_delta::CpuDelta;
65pub use frame::{Frame, FrameFlags, FrameInfo};
66pub use global_lib_table::LibraryHandle;
67pub use lib_mappings::LibMappings;
68pub use library_info::{LibraryInfo, Symbol, SymbolTable};
69pub use markers::*;
70pub use process::ThreadHandle;
71pub use profile::{Profile, SamplingInterval, StringHandle};
72pub use reference_timestamp::ReferenceTimestamp;
73pub use thread::ProcessHandle;
74pub use timestamp::*;