EmbarkStudios / puffin

🐦 Friendly little instrumentation profiler for Rust 🦀
Apache License 2.0
1.49k stars 75 forks source link

Conditional profile scopes #222

Closed emilk closed 3 months ago

emilk commented 3 months ago

Sometimes I find myself wishing there was a way to only instrument a piece of code if some condition is met, to reduce overhead:

fn do_stuff(n: usize) {
    puffin::profile_scope_if!(10_000 < n, "processing lots of data");
    for i in 0..n {
        …
    }
}

If do_stuff is called once with a big n, we get a profile scope. If do_stuff is called a million times with a small n, we don't pay the overhead of the profiling.