Macro puffin::profile_scope_custom

source ·
macro_rules! profile_scope_custom {
    ($name:expr) => { ... };
    ($name:expr, $data:expr) => { ... };
}
Expand description

Profile the current scope with the given name (unique in the parent scope).

This macro is identical to profile_scope, except that it expands to the expression containing the profiling scope, as opposed to profile_scope which expands to a variable (which cannot be accessed due to macro hygiene).

This allows for profiling scopes to persist for a custom duration.

§Example

let some_large_vec = Vec::from_iter(0..1000);

// Use rayon's parallel for loop over our large iterator
rayon::prelude::for_each_init(
        &some_large_vec,
        // This gets called to init each work segment, and is passed into the calls
        // Rayon keeps the profiling scope stored for the entire duration of the work segment
        // So we can track the entire segment as one, instead of each loop iteration
        || puffin::profile_scope_custom!("rayon_work_segment"),
        |((_profiler_scope), i)| {
            // All calls here gets profiled on the same scope
            println!("{i}")
        },
);