Crate tracing_profile

Source
Expand description

A span based profiler, utilizing the tracing crate.

§Overview

This implementation of tracing_subscriber::Layer<S> records the time a span took to execute, along with any user supplied metadata and information necessary to construct a call graph from the resulting logs.

Multiple Layer implementations are provided: CsvLayer: logs data in CSV format PrintTreeLayer: prints a call graph PrintPerfCountersLayer: prints aggregated performance counters for each span. PerfettoLayer: uses a local or system-wide perfetto tracing service to record data. IttApiLayer: logs data in Intel’s ITT API TracyLayer: re-exports the tracing_tracy::TracyLayer.

init_tracing is a convenience function that initializes the tracing with the default values depending on the features enabled and environment variables set.

use tracing::instrument;
use tracing::debug_span;
use tracing_profile::init_tracing;

#[instrument(skip_all, name= "graph_root", fields(a="b", c="d"))]
fn entry_point() {
    let span = debug_span!("some_span");
    let _scope1 = span.enter();

    let span2 = debug_span!("another_span", field1 = "value1");
    let _scope2 = span2.enter();
}

fn main() {
    // Initialize the tracing with the default values
    // Note that the guard must be kept alive for the duration of the program.
    let _guard = init_tracing().unwrap();

    entry_point();
}

Note that if #[instrument] is used, skip_all is recommended. Omitting this will result in all the function arguments being included as fields.

§Features

The panic feature will turn eprintln! into panic!, causing the program to halt on errors.

Modules§

utils

Structs§

CsvLayer
PrintTreeConfig
Tree layer config.
PrintTreeLayer
GraphLayer (internally called layer::graph) This Layer prints a call graph to stdout. Please note that this layer both prints data about spans and events. Spans from the threads other than the main thread are not printed. Events from the main thread are attached to the latest main thread span. Depending on the Config::accumulate_events setting, the layer will either print the events of each span or accumulate the events of the children into the parent.

Functions§

init_tracing
Initialize the tracing with the default values depending on the features enabled and environment variables set.