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
77
78
79
//! Public types of the function sink: a callback that receives every
//! `#[measure]` / `measure_block!` scope as it is entered and exited, so an
//! external recorder (a timeline viewer, a tracing bridge) can see individual
//! calls instead of only the aggregated report.
/// How a measured scope relates to the thread that entered it.
/// Receives every measured function scope while it runs.
///
/// Install one per process with [`set_function_sink`](crate::set_function_sink),
/// which only reports scopes when the `hotpath-sink` feature is enabled.
/// Both methods run inline on the instrumented thread, so they must be cheap
/// and must never block. They are called whether or not a
/// [`HotpathGuard`](crate::HotpathGuard) is alive and regardless of time
/// sampling; scopes filtered out by `HOTPATH_FOCUS` are not reported.
///
/// ```
/// use std::sync::atomic::{AtomicU64, Ordering};
///
/// struct CountCalls(AtomicU64);
///
/// impl hotpath::FunctionSink for CountCalls {
/// fn enter(&self, _name: &'static str, _kind: hotpath::ScopeKind) -> u64 {
/// self.0.fetch_add(1, Ordering::Relaxed)
/// }
///
/// fn exit(&self, _name: &'static str, _kind: hotpath::ScopeKind, _token: u64) {}
/// }
///
/// hotpath::set_function_sink(CountCalls(AtomicU64::new(0))).ok();
/// ```
/// Returned by [`set_function_sink`](crate::set_function_sink) when a sink is
/// already installed. The sink cannot be replaced for the lifetime of the
/// process.
;
/// No-op without the `hotpath-sink` feature: no scope is reported, so the sink
/// is dropped and never called. The signature matches the enabled
/// implementation, so callers need no feature gate of their own.
///
/// # Errors
///
/// Never fails.