Expand description
Here’s an example of how to use some of FLAMEs APIs:
extern crate flame;
use std::fs::File;
pub 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);
}
Structs§
- Note
- A note for use in debugging.
- Span
- A named timespan.
- Span
Guard - Thread
- A collection of events that happened on a single thread.
Functions§
- clear
- Clears all of the recorded info that Flame has tracked.
- commit_
thread - debug
- Prints all of the frames to stdout.
- dump_
html - dump_
json - dump_
stdout - dump_
text_ to_ writer - end
- Ends the current Span and returns the number of nanoseconds that passed.
- end_
collapse - Ends the current Span and returns the number of nanoseconds that passed.
- end_
with - Ends the current Span and returns a given result.
- note
- Records a note on the current Span.
- span_of
- Starts and ends a
Span
that lasts for the duration of the functionf
. - spans
- Returns a list of spans from the current thread
- start
- Starts a new Span
- start_
guard - Starts a
Span
and also returns aSpanGuard
. - threads