#tracing #perfetto

sys tracing-profile-perfetto-sys

Low-level bindings to Perfetto, optionally used by the tracing-profile crate

1 unstable release

0.7.0 Sep 16, 2024

#277 in Profiling


Used in tracing-profile

Apache-2.0

2.5MB
43K SLoC

C++ 43K SLoC // 0.2% comments Rust 462 SLoC // 0.0% comments

Perfetto-sys

This crate wraps the perfetto sdk. Use it as follows:

Create a PerfettoGuard which will live for the duration of the tracing session via PerfettoGuard::new().
To create a span, create a TraceEvent via TraceEvent::new(<event name>). The event will persist until the TraceEvent is dropped.

The crate allows you to generate compile-time defined categories of events and counters by specifying the path to a JSON file in PERFETTO_INTERFACE_FILE environment variable during the build. See InterfaceData structure in build.rs for reference.

data_sources {
    config {
        name: "track_event"
    }
}

Note that the PerfettoGuard currently causes the thread to block until it establishes a connection to the tracing service.

Building the deb package

cd deb
dpkg --build perfetto
sudo dpkg -i perfetto
sudo dpkg -r perfetto

In process mode

When using in-process mode, all the data will be written to a local file, path to which can be set by passing the argument to init_perfetto function. If the value is null tracing.perfetto-trace will be used as a default value. When system mode is chosen this argument is ignored.

No runtime deps