17 releases

Uses old Rust 2015

0.2.2 Mar 8, 2018
0.2.1-pre2 Apr 19, 2018
0.2.0 Jul 10, 2017
0.1.11 Jan 2, 2017
0.1.2 Nov 25, 2015

#238 in Profiling

Download history 487/week @ 2024-07-27 432/week @ 2024-08-03 428/week @ 2024-08-10 372/week @ 2024-08-17 401/week @ 2024-08-24 426/week @ 2024-08-31 365/week @ 2024-09-07 434/week @ 2024-09-14 489/week @ 2024-09-21 451/week @ 2024-09-28 571/week @ 2024-10-05 773/week @ 2024-10-12 538/week @ 2024-10-19 495/week @ 2024-10-26 531/week @ 2024-11-02 262/week @ 2024-11-09

1,915 downloads per month
Used in 25 crates (24 directly)

MIT/Apache

1MB
13K SLoC

JavaScript 10K SLoC // 0.0% comments TypeScript 2K SLoC // 0.3% comments Rust 459 SLoC // 0.0% comments

FLAME

A cool flamegraph library for rust

Flamegraphs are a great way to view profiling information. At a glance, they give you information about how much time your program spends in critical sections of your code giving you some much-needed insight into where optimizations may be needed.

Unlike tools like perf which have the OS interrupt your running program repeatadly and reports on every function in your callstack, FLAME lets you choose what you want to see in the graph by adding performance instrumentation to your own code.

Simply use any of FLAMEs APIs to annotate the start and end of a block code that you want timing information from, and FLAME will organize these timings hierarchically.

Docs

Here's an example of how to use some of FLAMEs APIs:

extern crate flame;

use std::fs::File;

fn main() {
    // Manual `start` and `end`
    flame::start("read file");
    let x = read_a_file();
    flame::end("read file");

    // Time the execution of a closure.  (the result of the closure is returned)
    let y = flame::span_of("database query", || query_database());

    // Time the execution of a block by creating a guard.
    let z = {
        let _guard = flame::start_guard("cpu-heavy calculation");
        cpu_heavy_operations_1();
        // Notes can be used to annotate a particular instant in time.
        flame::note("something interesting happened", None);
        cpu_heavy_operations_2()
    };

    // Dump the report to disk
    flame::dump_html(&mut File::create("flame-graph.html").unwrap()).unwrap();
    
    // Or read and process the data yourself!
    let spans = flame::spans();
    
    println!("{} {} {}", x, y, z);
}

And here's a screenshot of a flamegraph produced by dump_html (from a different project):

flamegraph

llogiq has created flamer, a compiler plugin that automatically inserts FLAME instrumentation into annotated functions allowing you to write code like

#[flame]
fn this_function_is_profiled() {
    ...
}

So if you are using a nightly version of rust, check it out; flamer is probably the easiest way to use FLAME!

Dependencies

~25–550KB