#tracing #applications #spans #parallelism #parallel #plot #cli-applications

bin+lib tracing-durations-export

Record and visualize parallelism of tracing spans

4 releases

0.2.0 Jan 30, 2024
0.1.2 Jan 27, 2024
0.1.1 Jan 7, 2024
0.1.0 Jan 6, 2024

#154 in Debugging

Download history 12/week @ 2024-01-08 546/week @ 2024-01-15 33/week @ 2024-01-22 138/week @ 2024-01-29 59/week @ 2024-02-05 786/week @ 2024-02-12 836/week @ 2024-02-19 399/week @ 2024-02-26 746/week @ 2024-03-04 784/week @ 2024-03-11 461/week @ 2024-03-18 352/week @ 2024-03-25 502/week @ 2024-04-01

2,159 downloads per month


907 lines


crates.io Documentation

A tracing layer to figure out which tasks are running in parallel and which are blocked on cpu, mainly for cli applications.

Each span from beginning to end is a blue stripe. An async span can either be active or yield and wait (details in the tracing docs), only in the sections in which a span is active, we plot an orange section above it. Sync spans are always active, so their blue and orange regions are identical. The darker the color the more spans of the same name are active at the same time.

The example plot below is generated by cached_network.rs has four sections. The first show sequentially making network requests and parsing the response, the second section shows the same logic but parallelized with buffer_unordered. You can see how the requests happen in parallel and the parsing starts as soon as a request is finished. Sections three and four are a more complex example where we first check a cache before emitting a network request.

Example plot

Open the svg in your browser and hover over the sections for detailed timings and field information.

The multi-lane option provides a more verbose view showing each individual span:

Example plot, multi lane

The plots are complementary to a cpu profiler such as perf or sample and looking at raw span durations. They don't give you and exact work-by-line breakdown, instead they tell you where cpu is blocking or delaying other work and when the cpu is idle waiting for more parallelism.


use std::fs::File;
use std::io::BufWriter;
use tracing_durations_layer::DurationLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::{registry::Registry, fmt};

fn setup_global_subscriber() -> DurationsLayerDropGuard {
    let fmt_layer = fmt::Layer::default();
    let (duration_layer, guard) = DurationsLayerBuilder::default()
        // Available with the `plot` feature
        // .plot_file("traces.svg")
    let subscriber = Registry::default()


// your code here ...

You can either use the plot feature and set .plot_file() on the builder, or after running your application, run

cargo run --bin plot --features plot --features cli -- traces.ndjson

and open traces.svg.

For the plots at the beginning of the readme:

TRACING_DURATION_EXPORT=examples/cached_network.ndjson cargo run --example cached_network
cargo run --bin plot --features plot --features cli -- examples/cached_network.ndjson
cargo run --bin plot --features plot --features cli -- --multi-lane examples/cached_network.ndjson --output examples/cached_network_multi_lane.svg

The traces.ndjson output file will look something like below, where each section where a span is active is one line.


Note that 0 is the time of the first span, not the start of the process.


~58K SLoC