Profi
A simple profiler for single and multithreaded applications.
Record the time it takes for a scope to end and print the timings when the program exits.
Each measurement has an overhead of ~25ns-50ns, so it shouldn't impact benchmarks.
Run the benchmarks example to see what's the overhead on your machine.
Setup
profi is controlled by the enable feature, which is active by default.
When disabled, all macros and methods will become no-ops, resulting in zero impact on your code.
To disable it, add default-features = false to the profi dependency in your Cargo.toml.
For convenience, you can also add a custom feature:
[]
= { = "*", = false }
[]
= ["profi/enable"]
And run it with cargo run --release --features prof
If you use rayon, enable the rayon feature!
Usage
See the examples for more usage cases.
Basic Usage
use ;
┌──────────────┬────────────────────┬───────────┬──────────────┬───────┐
│ Name ┆ % Application Time ┆ Real Time ┆ Average time ┆ Calls │
╞══════════════╪════════════════════╪═══════════╪══════════════╪═══════╡
│ simple::main ┆ 100.00% ┆ 200.13ms ┆ - ┆ 1 │
└──────────────┴────────────────────┴───────────┴──────────────┴───────┘
Loops
use ;
┌────────────┬────────────────────┬───────────┬──────────────┬───────┐
│ Name ┆ % Application Time ┆ Real Time ┆ Average time ┆ Calls │
╞════════════╪════════════════════╪═══════════╪══════════════╪═══════╡
│ loop::main ┆ 100.00% ┆ 1.01s ┆ - ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ iteration ┆ 99.99% ┆ 1.01s ┆ 10.10ms/call ┆ 100 │
└────────────┴────────────────────┴───────────┴──────────────┴───────┘
Multiple threads
use ;
┌───────────────┬────────────────────┬───────────┬────────────┬──────────┬──────────────┬───────┐
│ Name ┆ % Application Time ┆ Real Time ┆ % CPU Time ┆ CPU Time ┆ Average time ┆ Calls │
╞═══════════════╪════════════════════╪═══════════╪════════════╪══════════╪══════════════╪═══════╡
│ threads::main ┆ 100.00% ┆ 10.48ms ┆ 9.43% ┆ 10.48ms ┆ - ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ 6 first ┆ 96.42% ┆ 10.11ms ┆ 54.38% ┆ 60.44ms ┆ 10.08ms/call ┆ 6 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ 4 last ┆ 95.93% ┆ 10.06ms ┆ 36.19% ┆ 40.22ms ┆ 10.06ms/call ┆ 4 │
└───────────────┴────────────────────┴───────────┴────────────┴──────────┴──────────────┴───────┘
"CPU Time" is the combined time all threads have spent on that scope.
For example, "6 first" has a "CPU Time" of 60 milliseconds because each thread waits 10ms, and the program spawns six of them.
Attribute
Enable the attributes feature to use the profile attribute on functions.
This will add a guard at the start of the function.
use profi::profile;
#[profile]
fn anotated() { /* ... */ }
Features
| Name | Description |
|---|---|
enable |
Activates the profiling, if not active all macros become no-ops |
attributes |
Enables the #[prof] macro |
deep-hierarchy |
By default profi merges all uses of a function, use this feature to disable this behaviour.See the nested example for more information |
nightly |
Enables nightly-only optimizations (unused at the moment) |
rayon |
Necessary if using rayon |