statevec_api/
throughput_probe.rs1#[cfg(feature = "throughput-probe")]
5mod imp {
6 use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
7
8 static RUNTIME_HOST_WITH_READ_TYPED_BY_PK_COUNT: AtomicU64 = AtomicU64::new(0);
9 static RUNTIME_HOST_UPDATE_TYPED_BY_PK_COUNT: AtomicU64 = AtomicU64::new(0);
10 static TYPED_TX_WITH_READ_TYPED_BY_PK_COUNT: AtomicU64 = AtomicU64::new(0);
11 static TYPED_TX_UPDATE_TYPED_BY_PK_COUNT: AtomicU64 = AtomicU64::new(0);
12 static TYPED_TX_UPDATE_OR_CREATE_TYPED_BY_PK_COUNT: AtomicU64 = AtomicU64::new(0);
13 static DUMP_ONCE: AtomicBool = AtomicBool::new(false);
14
15 #[inline(always)]
16 fn load(counter: &AtomicU64) -> u64 {
17 counter.load(Ordering::Relaxed)
18 }
19
20 #[inline(always)]
21 fn store(counter: &AtomicU64, value: u64) {
22 counter.store(value, Ordering::Relaxed);
23 }
24
25 #[inline(always)]
26 fn add(counter: &AtomicU64, value: u64) {
27 counter.fetch_add(value, Ordering::Relaxed);
28 }
29
30 pub struct RuntimeApiProbe;
31
32 impl RuntimeApiProbe {
33 pub fn reset() {
34 store(&RUNTIME_HOST_WITH_READ_TYPED_BY_PK_COUNT, 0);
35 store(&RUNTIME_HOST_UPDATE_TYPED_BY_PK_COUNT, 0);
36 store(&TYPED_TX_WITH_READ_TYPED_BY_PK_COUNT, 0);
37 store(&TYPED_TX_UPDATE_TYPED_BY_PK_COUNT, 0);
38 store(&TYPED_TX_UPDATE_OR_CREATE_TYPED_BY_PK_COUNT, 0);
39 DUMP_ONCE.store(false, Ordering::Relaxed);
40 }
41
42 pub fn dump_to_stderr_once(label: &str) {
43 if DUMP_ONCE.swap(true, Ordering::Relaxed) {
44 return;
45 }
46 eprintln!(
47 concat!(
48 "[statevec_api_probe] label={label}",
49 " runtime_host_with_read_typed_by_pk_count={runtime_host_with_read_typed_by_pk_count}",
50 " runtime_host_update_typed_by_pk_count={runtime_host_update_typed_by_pk_count}",
51 " typed_tx_with_read_typed_by_pk_count={typed_tx_with_read_typed_by_pk_count}",
52 " typed_tx_update_typed_by_pk_count={typed_tx_update_typed_by_pk_count}",
53 " typed_tx_update_or_create_typed_by_pk_count={typed_tx_update_or_create_typed_by_pk_count}"
54 ),
55 label = label,
56 runtime_host_with_read_typed_by_pk_count =
57 load(&RUNTIME_HOST_WITH_READ_TYPED_BY_PK_COUNT),
58 runtime_host_update_typed_by_pk_count =
59 load(&RUNTIME_HOST_UPDATE_TYPED_BY_PK_COUNT),
60 typed_tx_with_read_typed_by_pk_count = load(&TYPED_TX_WITH_READ_TYPED_BY_PK_COUNT),
61 typed_tx_update_typed_by_pk_count = load(&TYPED_TX_UPDATE_TYPED_BY_PK_COUNT),
62 typed_tx_update_or_create_typed_by_pk_count =
63 load(&TYPED_TX_UPDATE_OR_CREATE_TYPED_BY_PK_COUNT),
64 );
65 }
66 }
67
68 #[inline(always)]
69 pub(crate) fn on_runtime_host_with_read_typed_by_pk() {
70 add(&RUNTIME_HOST_WITH_READ_TYPED_BY_PK_COUNT, 1);
71 }
72
73 #[inline(always)]
74 pub(crate) fn on_runtime_host_update_typed_by_pk() {
75 add(&RUNTIME_HOST_UPDATE_TYPED_BY_PK_COUNT, 1);
76 }
77
78 #[inline(always)]
79 pub(crate) fn on_typed_tx_with_read_typed_by_pk() {
80 add(&TYPED_TX_WITH_READ_TYPED_BY_PK_COUNT, 1);
81 }
82
83 #[inline(always)]
84 pub(crate) fn on_typed_tx_update_typed_by_pk() {
85 add(&TYPED_TX_UPDATE_TYPED_BY_PK_COUNT, 1);
86 }
87
88 #[inline(always)]
89 pub(crate) fn on_typed_tx_update_or_create_typed_by_pk() {
90 add(&TYPED_TX_UPDATE_OR_CREATE_TYPED_BY_PK_COUNT, 1);
91 }
92}
93
94#[cfg(not(feature = "throughput-probe"))]
95mod imp {
96 pub struct RuntimeApiProbe;
97
98 impl RuntimeApiProbe {
99 pub fn reset() {}
100
101 pub fn dump_to_stderr_once(_label: &str) {}
102 }
103
104 #[inline(always)]
105 pub(crate) fn on_runtime_host_with_read_typed_by_pk() {}
106
107 #[inline(always)]
108 pub(crate) fn on_runtime_host_update_typed_by_pk() {}
109
110 #[inline(always)]
111 pub(crate) fn on_typed_tx_with_read_typed_by_pk() {}
112
113 #[inline(always)]
114 pub(crate) fn on_typed_tx_update_typed_by_pk() {}
115
116 #[inline(always)]
117 pub(crate) fn on_typed_tx_update_or_create_typed_by_pk() {}
118}
119
120pub use imp::RuntimeApiProbe;
121pub(crate) use imp::{
122 on_runtime_host_update_typed_by_pk, on_runtime_host_with_read_typed_by_pk,
123 on_typed_tx_update_or_create_typed_by_pk, on_typed_tx_update_typed_by_pk,
124 on_typed_tx_with_read_typed_by_pk,
125};