Skip to main content

kithara_test_utils/probe/
noop.rs

1use std::time::Duration;
2
3use kithara_events::{AbrMode, CancelReason, RequestId, RequestPriority};
4use url::Url;
5
6pub trait Probe {
7    fn record_probe(&self, name: &'static str);
8}
9
10pub trait IntoProbeArg: Copy {
11    #[must_use]
12    fn from_probe_arg(packed: u64) -> Self {
13        let _ = packed;
14        unimplemented!("noop probe: from_probe_arg not supported without `probe` feature")
15    }
16
17    fn into_probe_arg(self) -> u64;
18}
19
20macro_rules! impl_int_probe_arg_noop {
21    ($($ty:ty),* $(,)?) => {
22        $(
23            impl IntoProbeArg for $ty {
24                fn into_probe_arg(self) -> u64 { self as u64 }
25                fn from_probe_arg(packed: u64) -> Self { packed as $ty }
26            }
27        )*
28    };
29}
30
31impl_int_probe_arg_noop!(u64, i64, u32, i32, usize);
32
33impl IntoProbeArg for bool {
34    fn from_probe_arg(packed: u64) -> Self {
35        packed != 0
36    }
37    fn into_probe_arg(self) -> u64 {
38        u64::from(self)
39    }
40}
41
42impl IntoProbeArg for Duration {
43    fn from_probe_arg(packed: u64) -> Self {
44        Self::from_micros(packed)
45    }
46    fn into_probe_arg(self) -> u64 {
47        u64::try_from(self.as_micros()).unwrap_or(u64::MAX)
48    }
49}
50
51impl IntoProbeArg for &Url {
52    fn into_probe_arg(self) -> u64 {
53        0
54    }
55}
56
57impl IntoProbeArg for RequestId {
58    fn into_probe_arg(self) -> u64 {
59        self.get()
60    }
61}
62
63fn request_priority_wire(p: RequestPriority) -> u64 {
64    match p {
65        RequestPriority::High => 0,
66        RequestPriority::Low => 1,
67    }
68}
69
70impl IntoProbeArg for RequestPriority {
71    fn into_probe_arg(self) -> u64 {
72        request_priority_wire(self)
73    }
74}
75
76fn cancel_reason_wire(r: CancelReason) -> u64 {
77    match r {
78        CancelReason::EpochCancel => 0,
79        CancelReason::PeerCancel => 1,
80        CancelReason::DownloaderShutdown => 2,
81        CancelReason::BeforeStart => 3,
82    }
83}
84
85impl IntoProbeArg for CancelReason {
86    fn into_probe_arg(self) -> u64 {
87        cancel_reason_wire(self)
88    }
89}
90
91impl IntoProbeArg for AbrMode {
92    fn into_probe_arg(self) -> u64 {
93        usize::from(self) as u64
94    }
95}
96
97impl<T: IntoProbeArg> IntoProbeArg for Option<T> {
98    fn into_probe_arg(self) -> u64 {
99        self.map_or(u64::MAX, IntoProbeArg::into_probe_arg)
100    }
101}
102
103pub fn register_probes() {}
104
105#[must_use]
106pub fn caller_fn_above(_probe_fn_name: &str) -> Option<String> {
107    None
108}
109
110#[must_use]
111pub fn next_probe_seq() -> u64 {
112    0
113}
114
115#[must_use]
116pub fn next_thread_probe_seq() -> u64 {
117    0
118}
119
120#[must_use]
121pub fn current_thread_u64() -> u64 {
122    0
123}
124
125#[must_use]
126pub fn current_install_id() -> u64 {
127    0
128}
129
130#[must_use]
131pub fn bump_install_id() -> u64 {
132    0
133}
134
135#[cfg(not(target_arch = "wasm32"))]
136kithara_platform::tokio::task_local! {
137    pub static OWNED_INSTALL_ID: u64;
138}
139
140pub fn fire_0(_name: &'static str) {}
141pub fn fire_1(_name: &'static str, _a0: u64) {}
142pub fn fire_2(_name: &'static str, _a0: u64, _a1: u64) {}
143pub fn fire_3(_name: &'static str, _a0: u64, _a1: u64, _a2: u64) {}
144pub fn fire_4(_name: &'static str, _a0: u64, _a1: u64, _a2: u64, _a3: u64) {}
145pub fn fire_5(_name: &'static str, _a0: u64, _a1: u64, _a2: u64, _a3: u64, _a4: u64) {}
146pub fn fire_6(_name: &'static str, _a0: u64, _a1: u64, _a2: u64, _a3: u64, _a4: u64, _a5: u64) {}