Skip to main content

hrx/execution/
statistics.rs

1use std::sync::atomic::{AtomicU64, Ordering};
2/// Cumulative counters for one coordinated runtime. Native low-level calls are
3/// outside this accounting domain. Reads are snapshots, not global barriers.
4#[derive(Clone, Debug, Default, serde::Serialize)]
5pub struct Statistics {
6    /// Native GPU executable graphs instantiated by coordinated graph preparation.
7    pub native_graphs_prepared: u64,
8    /// Lazily created direct-copy streams, at most one per GPU lane.
9    pub copy_streams_created: u64,
10    /// Successfully allocated tracked buffers.
11    pub allocations: u64,
12    /// Shared dma-buf imports created during allocation.
13    pub imports: u64,
14    /// Accepted graph submissions.
15    pub submissions: u64,
16    /// Terminal graph submissions, including cancellation and failure.
17    pub completions: u64,
18    /// Explicit copy bytes executed by graph nodes.
19    pub copied_bytes: u64,
20    /// Copy bytes completed on the upload lane.
21    pub uploaded_bytes: u64,
22    /// Copy bytes completed on the download lane.
23    pub downloaded_bytes: u64,
24    /// Copy bytes completed on the compute lane.
25    pub device_copied_bytes: u64,
26    /// Byte extents passed to cross-engine cache maintenance.
27    pub cache_maintenance_bytes: u64,
28    /// Bytes whose tracked allocations are still retained.
29    pub live_bytes: u64,
30    /// Maximum retained allocation bytes observed by this runtime.
31    pub peak_bytes: u64,
32}
33#[derive(Default)]
34pub(super) struct Counters {
35    pub native_graphs_prepared: AtomicU64,
36    pub copy_streams_created: AtomicU64,
37    pub allocations: AtomicU64,
38    pub imports: AtomicU64,
39    pub submissions: AtomicU64,
40    pub completions: AtomicU64,
41    pub copied_bytes: AtomicU64,
42    pub lane_copy_bytes: [AtomicU64; 3],
43    pub cache_maintenance_bytes: AtomicU64,
44    pub live_bytes: AtomicU64,
45    pub peak_bytes: AtomicU64,
46}
47impl Counters {
48    pub fn snapshot(&self) -> Statistics {
49        Statistics {
50            native_graphs_prepared: self.native_graphs_prepared.load(Ordering::Relaxed),
51            copy_streams_created: self.copy_streams_created.load(Ordering::Relaxed),
52            allocations: self.allocations.load(Ordering::Relaxed),
53            imports: self.imports.load(Ordering::Relaxed),
54            submissions: self.submissions.load(Ordering::Relaxed),
55            completions: self.completions.load(Ordering::Relaxed),
56            copied_bytes: self.copied_bytes.load(Ordering::Relaxed),
57            uploaded_bytes: self.lane_copy_bytes[0].load(Ordering::Relaxed),
58            device_copied_bytes: self.lane_copy_bytes[1].load(Ordering::Relaxed),
59            downloaded_bytes: self.lane_copy_bytes[2].load(Ordering::Relaxed),
60            cache_maintenance_bytes: self.cache_maintenance_bytes.load(Ordering::Relaxed),
61            live_bytes: self.live_bytes.load(Ordering::Relaxed),
62            peak_bytes: self.peak_bytes.load(Ordering::Relaxed),
63        }
64    }
65}