Inferno is a port of parts of the flamegraph
toolkit to Rust, with the
aim of improving the performance of the original flamegraph tools. The
primary focus is on speeding up the stackcollapse-*
tools that process
output from various profiling tools into the "folded" format expected by
the flamegraph
plotting tool. So far, the focus has been on parsing
profiling results from
perf
and
dtrace
. At the time of writing,
inferno-collapse-perf
is ~9x faster than stackcollapse-perf.pl
and
inferno-collapse-dtrace
is ~10x faster than stackcollapse.pl
(see
compare.sh
.
It is developed in part through live coding sessions, which you can find on YouTube.
Dependency
To profile your application, you'll need to have a "profiler" installed.
This will likely be perf
or [bpftrace
] on Linux, and [DTrace] on
macOS. There are some great instructions on how to get started with
these tools on Brendan Gregg's [CPU Flame Graphs page].
[profiler]: https://en.wikipedia.org/wiki/Profiling_(computer_programming
[perf
]: https://perf.wiki.kernel.org/index.php/Main_Page
[bpftrace
]: https://github.com/iovisor/bpftrace/
[DTrace]: https://www.joyent.com/dtrace
[CPU Flame Graphs page]: http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html#Instructions
In Linux, you may need to tweak a kernel config such as
$ echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid
to get profiling to work.
How to use
As a library
Inferno provides a library interface through
the inferno
crate. This will let you collapse stacks and produce flame
graphs without going through the command line, and is intended for
integration with external Rust tools like cargo-flamegraph
.
As a binary
First, install Inferno. Then, build your application (in release mode and with debug symbols). Finally, run a profiler to gather profiling data and pass it through the appropriate Inferno "collapser". Depending on your platform, this will look something like
$ # Linux
# perf record --call-graph dwarf target/release/mybin
$ perf script | inferno-collapse-perf > stacks.folded
or
$ # macOS
$ target/release/mybin &
$ pid=$!
# dtrace -x ustackframes=100 -n "profile-97 /pid == $pid/ { @[ustack()] = count(); } tick-60s { exit(0); }" -o out.user_stacks
$ cat out.user_stacks | inferno-collapse-dtrace > stacks.folded
In the end, you'll end up with a "folded stack" file. You can pass that
file to inferno-flamegraph
to generate a flame graph SVG:
$ cat stacks.folded | inferno-flamegraph > flamegraph.svg
You'll end up with an image like this:
Comparison to the Perl implementation
To run Inferno's performance comparison, run ./compare.sh
.
It requires hyperfine, and you
must make sure you also check out Inferno's
submodules.
License
Inferno is a port of @brendangregg's awesome original FlameGraph project, written in Perl, and owes its existence and pretty much of all of its functionality entirely to that project. Like FlameGraph, Inferno is licensed under the CDDL 1.0 to avoid any licensing issues. Specifically, the CDDL 1.0 grants
a world-wide, royalty-free, non-exclusive license under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
as long as the source is made available along with the license (3.1), both of which are true since you're reading this file!