Expand description
Conditional instrumentation support for profiling.
This module provides tracing integration when the profiling feature is
enabled. When disabled, instrumentation compiles to zero-cost no-ops.
§Features
profiling- Base feature enabling tracing spans (no backend)trace-file- Trace file output in Chrome JSON (.json) or Perfetto (.pftrace) format
§Usage
For method-level instrumentation, use the #[cfg_attr] pattern:
ⓘ
#[cfg_attr(feature = "profiling", tracing::instrument(skip(self)))]
pub async fn my_method(&self) -> Result<T, Error> {
// ...
}For manual span creation within functions:
ⓘ
#[cfg(feature = "profiling")]
let _span = tracing::info_span!("operation_name", field = value).entered();
// ... code to profile
#[cfg(feature = "profiling")]
drop(_span); // Optional: explicitly end span early§Trace Output
When built with the trace-file feature, traces can be written to files:
.jsonextension → Chrome JSON format (viewable in Perfetto UI).pftraceextension → Native Perfetto format (viewable in Perfetto UI)
Use --trace-file path.json or --trace-file path.pftrace to select
format.
Modules§
- instrument
- Attach a span to a
std::future::Future.
Macros§
- debug
- Constructs an event at the debug level.
- debug_
span - Constructs a span at the debug level.
- error
- Constructs an event at the error level.
- error_
span - Constructs a span at the error level.
- info
- Constructs an event at the info level.
- info_
span - Constructs a span at the info level.
- trace
- Constructs an event at the trace level.
- trace_
span - Constructs a span at the trace level.
- warn
- Constructs an event at the warn level.
- warn_
span - Constructs a span at the warn level.
Structs§
- Level
- Describes the level of verbosity of a span or event.
- Span
- A handle representing a span, with the capability to enter the span if it exists.
Traits§
- Instrument
- Attaches spans to a
std::future::Future.
Attribute Macros§
- instrument
- Instruments a function to create and enter a
tracingspan every time the function is called.