Coder Social home page Coder Social logo

flame's Introduction

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.

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");
        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 frames = flame::frames();
    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!

flame's People

Contributors

tyoverby avatar llogiq avatar cryze avatar fcourchesne avatar pastoraleman avatar

Watchers

James Cloos avatar goroutine avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.