1 unstable release

0.1.0 Jul 12, 2020

#20 in Profiling

Download history 1383/week @ 2020-09-18 981/week @ 2020-09-25 1456/week @ 2020-10-02 1340/week @ 2020-10-09 1445/week @ 2020-10-16 1886/week @ 2020-10-23 1277/week @ 2020-10-30 2041/week @ 2020-11-06 2234/week @ 2020-11-13 2212/week @ 2020-11-20 1723/week @ 2020-11-27 1557/week @ 2020-12-04 1162/week @ 2020-12-11 707/week @ 2020-12-18 666/week @ 2020-12-25 586/week @ 2021-01-01

2,848 downloads per month
Used in ipfs-embed-db

MIT license

10K SLoC


A [tracing] Layer for generating a folded stack trace for generating flamegraphs and flamecharts with inferno

Crates.io Documentation Documentation (master) MIT licensed Build Status Discord chat maintenance status

Documentation | Chat


tracing is a framework for instrumenting Rust programs to collect scoped, structured, and async-aware diagnostics. tracing-flame provides helpers for consuming tracing instrumentation that can later be visualized as a flamegraph/flamechart. Flamegraphs/flamecharts are useful for identifying performance bottlenecks in an application. For more details, see Brendan Gregg's post on flamegraphs.


This crate is meant to be used in a two step process:

  1. Capture textual representation of the spans that are entered and exited with FlameLayer.
  2. Feed the textual representation into inferno-flamegraph to generate the flamegraph or flamechart.

Note: when using a buffered writer as the writer for a FlameLayer, it is necessary to ensure that the buffer has been flushed before the data is passed into inferno-flamegraph. For more details on how to flush the internal writer of the FlameLayer, see the docs for FlushGuard.

Layer Setup

use std::{fs::File, io::BufWriter};
use tracing_flame::FlameLayer;
use tracing_subscriber::{registry::Registry, prelude::*, fmt};

fn setup_global_subscriber() -> impl Drop {
    let fmt_layer = fmt::Layer::default();

    let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap();


// your code here ..

As an alternative, you can provide any type that implements std::io::Write to FlameLayer::new.

Generating the Image

To convert the textual representation of a flamegraph to a visual one, first install inferno:

cargo install inferno

Then, pass the file created by FlameLayer into inferno-flamegraph:

# flamegraph
cat tracing.folded | inferno-flamegraph > tracing-flamegraph.svg

# flamechart
cat tracing.folded | inferno-flamegraph --flamechart > tracing-flamechart.svg

Differences between flamegraphs and flamecharts

By default, inferno-flamegraph creates flamegraphs. Flamegraphs operate by that collapsing identical stack frames and sorting them on the frame's names.

This behavior is great for multithreaded programs and long-running programs where the same frames occur many times, for short durations, because it reduces noise in the graph and gives the reader a better idea of the overall time spent in each part of the application.

However, it is sometimes desirable to preserve the exact ordering of events as they were emitted by tracing-flame, so that it is clear when each span is entered relative to others and get an accurate visual trace of the execution of your program. This representation is best created with a flamechart, which does not sort or collapse identical stack frames.


This project is licensed under the MIT license.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tracing by you, shall be licensed as MIT, without any additional terms or conditions.