#tracing #graph #callgraph

tracing-callgraph

A tracing library for generating call graphs from spans

2 releases

0.1.0-alpha.1 Aug 1, 2020
0.1.0-alpha.0 Jul 20, 2020

#226 in Development tools

MIT license

11KB
206 lines

tracing-callgraph

A tracing library for generating call graphs in Graphviz dot representation.

CI License Cargo Documentation

Example

use tracing_callgraph::GraphLayer;
use tracing_subscriber::{prelude::*, registry::Registry};

fn setup_global_subscriber() -> impl Drop {
    let (graph_layer, _guard) = GraphLayer::with_file("./output.dot").unwrap();
    let subscriber = Registry::default().with(graph_layer);

    tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");
    _guard
}

#[tracing::instrument]
fn outer_a() {
    inner()
}

#[tracing::instrument]
fn outer_b() {
    inner()
}

#[tracing::instrument]
fn inner() {}

fn main() {
    let _guard = setup_global_subscriber();
    outer_a();
    outer_b();
}

Output

digraph {
    0 [ label = "\"outer_a\"" ]
    1 [ label = "\"inner\"" ]
    2 [ label = "\"outer_b\"" ]
    0 -> 1 [ label = "1" ]
    2 -> 1 [ label = "1" ]
}

Special Thanks

Special thanks to the authors of tracing-flame which this draws on heavily.

Dependencies

~1.5MB
~33K SLoC