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_frames = 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//! let stack = profile.intern_stack_frames(thread, stack_frames.into_iter());
26//! profile.add_sample(thread, Timestamp::from_millis_since_reference(0.0), stack, CpuDelta::ZERO, 1);
27//!
28//! let writer = std::io::BufWriter::new(output_file);
29//! serde_json::to_writer(writer, &profile)?;
30//! # Ok(())
31//! # }
32//! ```
33
34pub use debugid;
35
36mod category;
37mod category_color;
38mod counters;
39mod cpu_delta;
40mod fast_hash_map;
41mod frame;
42mod frame_table;
43mod func_table;
44mod global_lib_table;
45mod lib_mappings;
46mod library_info;
47mod marker_table;
48mod markers;
49mod native_symbols;
50mod process;
51mod profile;
52mod reference_timestamp;
53mod resource_table;
54mod sample_table;
55mod serialization_helpers;
56mod stack_table;
57mod string_table;
58mod thread;
59mod thread_string_table;
60mod timestamp;
61
62pub use category::{CategoryHandle, CategoryPairHandle};
63pub use category_color::CategoryColor;
64pub use counters::CounterHandle;
65pub use cpu_delta::CpuDelta;
66pub use frame::{Frame, FrameFlags, FrameInfo};
67pub use global_lib_table::{LibraryHandle, UsedLibraryAddressesIterator};
68pub use lib_mappings::LibMappings;
69pub use library_info::{LibraryInfo, Symbol, SymbolTable};
70pub use markers::{
71    GraphColor, Marker, MarkerFieldFlags, MarkerFieldFormat, MarkerFieldFormatKind,
72    MarkerGraphType, MarkerHandle, MarkerLocations, MarkerTiming, MarkerTypeHandle,
73    RuntimeSchemaMarkerField, RuntimeSchemaMarkerGraph, RuntimeSchemaMarkerSchema,
74    StaticSchemaMarker, StaticSchemaMarkerField, StaticSchemaMarkerGraph,
75};
76pub use process::ThreadHandle;
77pub use profile::{FrameHandle, Profile, SamplingInterval, StackHandle, StringHandle};
78pub use reference_timestamp::ReferenceTimestamp;
79pub use sample_table::WeightType;
80pub use thread::ProcessHandle;
81pub use timestamp::Timestamp;