1#[cfg(feature = "tracing")]
6pub use fuchsia_trace::{
7 Id, Scope, TraceFutureExt, duration, flow_begin, flow_end, flow_step, instant,
8 trace_future_args,
9};
10
11#[cfg(not(feature = "tracing"))]
12mod noop;
13#[cfg(not(feature = "tracing"))]
14pub mod __backend {
15 pub use crate::noop::*;
16}
17#[cfg(not(feature = "tracing"))]
18pub use crate::noop::{Id, Scope, TraceFutureExt};
19
20#[cfg(test)]
21mod tests {
22 use crate::*;
23
24 #[fuchsia::test]
25 fn test_duration() {
26 let trace_only_var = 6;
27 duration!("category", "name");
28 duration!("category", "name", "arg" => 5);
29 duration!("category", "name", "arg" => 5, "arg2" => trace_only_var);
30 }
31
32 #[fuchsia::test]
33 fn test_instant() {
34 let trace_only_var = 6;
35 instant!("category", "name", Scope::Thread);
36 instant!("category", "name", Scope::Thread, "arg" => 5);
37 instant!("category", "name", Scope::Thread, "arg" => 5, "arg2" => trace_only_var);
38 }
39
40 #[fuchsia::test]
41 fn test_flow_begin() {
42 let trace_only_var = 6;
43 let flow_id: Id = 5u64.into();
44 flow_begin!("category", "name", flow_id);
45 flow_begin!("category", "name", flow_id, "arg" => 5);
46 flow_begin!("category", "name", flow_id, "arg" => 5, "arg2" => trace_only_var);
47 }
48
49 #[fuchsia::test]
50 fn test_flow_step() {
51 let trace_only_var = 6;
52 let flow_id: Id = 5u64.into();
53 flow_step!("category", "name", flow_id);
54 flow_step!("category", "name", flow_id, "arg" => 5);
55 flow_step!("category", "name", flow_id, "arg" => 5, "arg2" => trace_only_var);
56 }
57
58 #[fuchsia::test]
59 fn test_flow_end() {
60 let trace_only_var = 6;
61 let flow_id: Id = 5u64.into();
62 flow_end!("category", "name", flow_id);
63 flow_end!("category", "name", flow_id, "arg" => 5);
64 flow_end!("category", "name", flow_id, "arg" => 5, "arg2" => trace_only_var);
65 }
66
67 #[fuchsia::test]
68 async fn test_trace_future() {
69 let value = async move { 5 }.trace(trace_future_args!("category", "name")).await;
70 assert_eq!(value, 5);
71
72 let value =
73 async move { 5 }.trace(trace_future_args!("category", "name", "arg1" => 6)).await;
74 assert_eq!(value, 5);
75
76 let trace_only_var = 7;
77 let value = async move { 5 }
78 .trace(trace_future_args!("category", "name", "arg1" => 6, "ar2" => trace_only_var))
79 .await;
80 assert_eq!(value, 5);
81 }
82
83 #[fuchsia::test]
84 fn test_arg_types() {
85 duration!("category", "name", "bool" => true);
86 duration!("category", "name", "i32" => 5i32, "u32" => 5u32);
87 duration!("category", "name", "i64" => 5i64, "u64" => 5u64);
88 duration!("category", "name", "isize" => 5isize, "usize" => 5usize);
89 duration!("category", "name", "f64" => 5f64);
90
91 let owned_str = "test-str".to_owned();
92 duration!("category", "name", "str" => owned_str.as_str());
93
94 let mut value = 5u64;
95 duration!("category", "name", "const-ptr" => &value as *const u64);
96 duration!("category", "name", "mut-ptr" => &mut value as *mut u64);
97 }
98}