22 releases (12 stable)

12.0.0 May 31, 2024
11.0.1 Jan 13, 2024
11.0.0 Dec 18, 2023
10.1.3 May 30, 2024
0.1.0 Mar 14, 2019

#12 in Profiling

Download history 19735/week @ 2024-08-13 19686/week @ 2024-08-20 20003/week @ 2024-08-27 20213/week @ 2024-09-03 19045/week @ 2024-09-10 18485/week @ 2024-09-17 19755/week @ 2024-09-24 18413/week @ 2024-10-01 20644/week @ 2024-10-08 18442/week @ 2024-10-15 20027/week @ 2024-10-22 21787/week @ 2024-10-29 21067/week @ 2024-11-05 22722/week @ 2024-11-12 23143/week @ 2024-11-19 20517/week @ 2024-11-26

90,692 downloads per month
Used in 67 crates (10 directly)

MIT/Apache

105KB
2K SLoC

This crate provides a library for high-performance event tracing which is used by the Rust compiler's unstable -Z self-profile feature.

The output of a tracing session will be an .mm_profdata file containing a stream of events and a string table that allows to decode the StringIds in the event stream.

Writing event trace files

The main entry point for writing event trace files is the Profiler struct.

To create a Profiler, call the [Profiler::new()] function and provide a Path with the directory and file name for the trace files. Alternatively, call the [Profiler::with_counter()] function, to choose the Counter the profiler will use for events (whereas [Profiler::new()] defaults to wall-time).

For more information on available counters, see the counters module documentation.

To record an event, call the [Profiler::record_instant_event()] method, passing a few arguments:

  • event_kind: a StringId which assigns an arbitrary category to the event
  • event_id: a StringId which specifies the name of the event
  • thread_id: a u32 id of the thread which is recording this event

Alternatively, events can also be recorded via the [Profiler::start_recording_interval_event()] method. This method records a "start" event and returns a TimingGuard object that will automatically record the corresponding "end" event when it is dropped.

To create a StringId, call one of the string allocation methods:

  • [Profiler::alloc_string()]: allocates a string and returns the StringId that refers to it

Dependencies

~0.4–5MB
~15K SLoC