1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Lightweight profiling utilities for performance monitoring.
//!
//! Provides simple timing and metrics collection for tracking
//! type checking and compilation performance.
mod allocation;
mod attribution;
mod cache;
mod core;
mod counters;
mod metrics;
#[cfg(feature = "micro-profiling")]
pub mod micro;
mod micro_macros;
mod report;
mod shard;
mod snapshot;
pub use allocation::{
AllocationSnapshot, ProfilingAllocator, allocation_snapshot, reset_allocation_counters,
set_allocation_tracking_enabled,
};
pub use attribution::{SpanAttribution, SpanRange};
pub use cache::CacheStats;
pub use core::{ProfileGuard, Profiler, Timer, global_profiler};
pub use metrics::{CounterMetrics, Metrics};
pub use report::{CounterEntry, CounterSummary, ProfileEntry, ProfileSummary};
/// Macro for profiling a block of code.
///
/// The two-argument form records under the plain dotted key. The `attr:` form
/// additionally carries a [`SpanAttribution`](crate::profiler::SpanAttribution),
/// recording under its own `key × attribution` bucket:
///
/// ```
/// use vize_l0::profile;
/// use vize_l0::profiler::SpanAttribution;
///
/// let plain = profile!("davinci.demo.plain", 1 + 1);
/// let attributed = profile!(
/// "davinci.demo.pass",
/// attr: SpanAttribution::new().with_stage("s1").with_pass("demo"),
/// 1 + 1
/// );
/// assert_eq!(plain + attributed, 4);
/// ```
#[macro_export]
macro_rules! profile {
($name:expr, $block:expr) => {{
let name: &'static str = $name;
let profiler = $crate::profiler::global_profiler();
// Keep disabled profiling cheap enough to leave at fine-grained call
// sites: one relaxed atomic check, then the original block executes.
if profiler.is_enabled() {
let _profile_guard = profiler.global_span(name);
$block
} else {
$block
}
}};
($name:expr, attr: $attribution:expr, $block:expr) => {{
let name: &'static str = $name;
let profiler = $crate::profiler::global_profiler();
// Same disabled-cost contract as the unattributed arm: one relaxed
// atomic check, then the original block executes.
if profiler.is_enabled() {
let _profile_guard = profiler.global_span_attributed(name, $attribution);
$block
} else {
$block
}
}};
}
#[cfg(test)]
mod tests;