borrowscope_runtime/tracker/
async_tracking.rs

1//! Async tracking: async blocks, await, futures
2
3use super::TRACKER;
4
5pub fn track_async_block_enter(
6    #[cfg_attr(not(feature = "track"), allow(unused_variables))] block_id: usize,
7    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
8) {
9    #[cfg(feature = "track")]
10    {
11        let mut tracker = TRACKER.lock();
12        tracker.record_async_block_enter(block_id, location);
13    }
14}
15
16/// Track async block exit.
17///
18/// Records an `AsyncBlockExit` event. Use this when exiting an async block.
19///
20/// # Arguments
21///
22/// * `block_id` - Identifier matching the corresponding `track_async_block_enter`
23/// * `location` - Source location
24#[inline(always)]
25pub fn track_async_block_exit(
26    #[cfg_attr(not(feature = "track"), allow(unused_variables))] block_id: usize,
27    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
28) {
29    #[cfg(feature = "track")]
30    {
31        let mut tracker = TRACKER.lock();
32        tracker.record_async_block_exit(block_id, location);
33    }
34}
35
36/// Track await expression start.
37///
38/// Records an `AwaitStart` event. Use this before awaiting a future.
39///
40/// # Arguments
41///
42/// * `await_id` - Unique identifier for this await point
43/// * `future_name` - Name or description of the future being awaited
44/// * `location` - Source location
45#[inline(always)]
46pub fn track_await_start(
47    #[cfg_attr(not(feature = "track"), allow(unused_variables))] await_id: usize,
48    #[cfg_attr(not(feature = "track"), allow(unused_variables))] future_name: &str,
49    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
50) {
51    #[cfg(feature = "track")]
52    {
53        let mut tracker = TRACKER.lock();
54        tracker.record_await_start(await_id, future_name, location);
55    }
56}
57
58/// Track await expression completion.
59///
60/// Records an `AwaitEnd` event. Use this after a future completes.
61///
62/// # Arguments
63///
64/// * `await_id` - Identifier matching the corresponding `track_await_start`
65/// * `location` - Source location
66#[inline(always)]
67pub fn track_await_end(
68    #[cfg_attr(not(feature = "track"), allow(unused_variables))] await_id: usize,
69    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
70) {
71    #[cfg(feature = "track")]
72    {
73        let mut tracker = TRACKER.lock();
74        tracker.record_await_end(await_id, location);
75    }
76}
77