#tracing #graph #callgraph #tracing-subscriber

tracing-callgraph

从跨度生成调用图的跟踪库

2 个版本

0.1.0-alpha.12020年8月1日
0.1.0-alpha.02020年7月20日

#1615开发工具

MIT 许可证

12KB
206

tracing-callgraph

一个用于在 Graphviz dot 表示形式中生成调用图的 tracing 库。

CI License Cargo Documentation

示例

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();
}

输出

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

特别感谢

特别感谢 tracing-flame 的作者,本库大量借鉴了其设计。

依赖项

~3.5MB
~50K SLoC