|
| 1 | +//! This crate provides a library for high-performance event tracing which is used by the Rust compiler's unstable `-Z self-profile` feature. |
| 2 | +//! |
| 3 | +//! There are two main parts to this library: |
| 4 | +//! - Writing event trace files |
| 5 | +//! - Reading event trace files |
| 6 | +//! |
| 7 | +//! The output of a tracing session will be three files: |
| 8 | +//! 1. A `.events` file which contains all of the traced events. |
| 9 | +//! 2. A `.string_data` file which contains all the strings referenced by events. |
| 10 | +//! 3. A `.string_index` file which maps `StringId` values to offsets into the `.string_data` file. |
| 11 | +//! |
| 12 | +//! # Writing event trace files |
| 13 | +//! |
| 14 | +//! The main entry point for writing event trace files is the [`Profiler`] struct. |
| 15 | +//! |
| 16 | +//! To create a [`Profiler`], call the [`Profiler::new()`] function and provide a `Path` with the directory and file name for the trace files. |
| 17 | +//! |
| 18 | +//! To record an event, call the [`Profiler::record_event()`] method, passing a few arguments: |
| 19 | +//! - `event_kind`: a [`StringId`] which assigns an arbitrary category to the event |
| 20 | +//! - `event_id`: a [`StringId`] which specifies the name of the event |
| 21 | +//! - `thread_id`: a `u64` id of the thread which is recording this event |
| 22 | +//! - `timestamp_kind`: a [`TimestampKind`] which specifies how this event should be treated by `measureme` tooling |
| 23 | +//! |
| 24 | +//! To create a [`StringId`], call one of the string allocation methods: |
| 25 | +//! - [`Profiler::alloc_string()`]: allocates a string and returns the [`StringId`] that refers to it |
| 26 | +//! - [`Profiler::alloc_string_with_reserved_id()`]: allocates a string using the specified [`StringId`]. |
| 27 | +//! It is up to the caller to make sure the specified [`StringId`] hasn't already been used. |
| 28 | +//! |
| 29 | +//! # Reading event trace files |
| 30 | +//! |
| 31 | +//! The main entry point for reading trace files is the [`ProfilingData`] struct. |
| 32 | +//! |
| 33 | +//! To create a [`ProfilingData`], call the [`ProfilingData::new()`] function and provide a `Path` with the directory and file name for the trace files. |
| 34 | +//! |
| 35 | +//! To retrieve an `Iterator` of all of the events in the file, call the [`ProfilingData::iter()`] method. |
| 36 | +//! |
| 37 | +//! To retrieve an `Iterator` of only matching start/stop events, call the [`ProfilingData::iter_matching_events()`] method. |
| 38 | +//! |
| 39 | +//! [`Profiler`]: struct.Profiler.html |
| 40 | +//! [`Profiler::alloc_string()`]: struct.Profiler.html#method.alloc_string |
| 41 | +//! [`Profiler::alloc_string_with_reserved_id()`]: struct.Profiler.html#method.alloc_string_with_reserved_id |
| 42 | +//! [`Profiler::new()`]: struct.Profiler.html#method.new |
| 43 | +//! [`Profiler::record_event()`]: struct.Profiler.html#method.record_event |
| 44 | +//! [`ProfilingData`]: struct.ProfilingData.html |
| 45 | +//! [`ProfilingData::iter()`]: struct.ProfilingData.html#method.iter |
| 46 | +//! [`ProfilingData::iter_matching_events()`]: struct.ProfilingData.html#method.iter_matching_events |
| 47 | +//! [`StringId`]: struct.StringId.html |
| 48 | +//! [`TimestampKind`]: enum.TimestampKind.html |
| 49 | +
|
1 | 50 | mod event;
|
2 | 51 | mod file_header;
|
3 | 52 | #[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
|
|
0 commit comments