Skip to main content

unity_solution_generator/
profile.rs

1//! Per-section profiling. Default-off; opt in by setting `USG_PROFILE=1` (concise)
2//! or `USG_PROFILE=full` (verbose, includes child spans). Backed by `tracing` so
3//! external collectors (`tracing-tracy`, `tracing-flame`, etc.) can also consume it.
4//!
5//! Usage at a call site:
6//! ```ignore
7//! use unity_solution_generator::profile::section;
8//! let _s = section!("scan.parallel-walk", root = root_path);
9//! ```
10//!
11//! `_s` must be held for the duration of the work — drop closes the span and
12//! emits its elapsed time.
13
14pub use tracing::Level;
15
16/// Open a profiling section. Equivalent to `tracing::info_span!(...).entered()`,
17/// but named for clarity at the call site.
18#[macro_export]
19macro_rules! section {
20    ($name:expr) => {
21        tracing::info_span!($name).entered()
22    };
23    ($name:expr, $($field:tt)+) => {
24        tracing::info_span!($name, $($field)+).entered()
25    };
26}
27
28pub use crate::section;