fxfs_trace

Attribute Macro trace

#[trace]
Expand description

Adds tracing to functions and methods.

§Method Tracing

When this attribute is present on an impl, methods marked with #[trace] will have tracing added to them. The name of the trace events default to <type-name>::<method-name> but this can be changed with arguments.

Arguments:

  • trace_all_methods - boolean toggle for whether to add tracing to all methods in the impl even if methods aren’t marked with #[trace]. Defaults to false.
  • prefix - string to appear before the method name in the trace events. Defaults to the name of the type. This argument may be required if the name of the type can’t be determined.

#[trace] Arguments:

  • name - string to use for the name of the trace event. Defaults to <prefix/type-name>::<method-name>.

Example:

struct Foo;
#[fxfs_trace::trace]
impl Foo {
    #[trace]
    async fn bar(&self) {
        ...
    }
}

If async_trait is also present on the impl then fxfs_trace::trace should come first. async_trait desugars async methods into sync methods that return a BoxFuture. If fxfs_trace runs after async_trait then fxfs_trace will see async methods as sync methods and apply the wrong tracing.

§Function Tracing

When this attribute is present on a function, the function will have tracing added to it.

Arguments:

  • name - string to use for the name of the trace event. Defaults to the name of the function.

§Synchronous Functions/Methods

fxfs_trace::duration! is added to the start of the function/method.

Example:

#[fxfs_trace::trace]
fn example_function() {
    ...
}
// Expands to:
fn example_function() {
    fxfs_trace::duration!(c"example_function");
    ...
}

§Async Functions/Methods

The body of function/method is wrapped in a fuchsia_tace::TraceFuture.

Example:

#[fxfs_trace::trace]
async fn example_function() {
    ...
}
// Expands to:
async fn example_function() {
    let trace_future_args = fxfs_trace::trace_future_args!("example_function");
    async move {
        ...
    }.trace(trace_future_args).await
}