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:
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.
For advanced filename customization, use init_tracing_with_builder
with TraceFilenameBuilder
.
§Basic Usage
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();
}
§Advanced Usage with Custom Filenames
With the gen_filename
feature enabled, you can use a builder pattern:
use tracing_profile::{init_tracing_with_builder, TraceFilenameBuilder};
// Create a custom filename builder
let builder = TraceFilenameBuilder::new()
.name("my_application")
.iteration(1)
.timestamp()
.git_info()
.platform()
.hostname();
// Initialize tracing with the custom builder
let _guard = init_tracing_with_builder(builder).unwrap();
// Your application code here...
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§
Structs§
- Print
Tree Config - Tree layer config.
- Print
Tree Layer - 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.