wlan_trace/
lib.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5pub mod names;
6
7#[doc(hidden)]
8pub use fuchsia_trace as __trace;
9
10use fuchsia_trace as trace;
11
12/// Writes a duration event when the current scope exits. No event is written at the start of the
13/// duration. As with all wlan-trace macros, the category will be "wlan" by default.
14#[macro_export]
15macro_rules! duration {
16    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
17        $crate::__trace::duration!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
18    };
19}
20
21/// Writes a duration begin event immediately and writes a duration end event when the current scope
22/// exits. As with all wlan-trace macros, the category will be "wlan" by default.
23#[macro_export]
24macro_rules! duration_begin_scope {
25    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
26        $crate::__trace::duration_begin!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
27        struct DurationEnd;
28        impl Drop for DurationEnd {
29            fn drop(&mut self) {
30                $crate::__trace::duration_end!($crate::names::CATEGORY_WLAN, $name);
31            }
32        }
33        let _scope = DurationEnd;
34    };
35}
36
37#[macro_export]
38macro_rules! duration_begin {
39    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
40        $crate::__trace::duration_begin!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
41    };
42}
43
44#[macro_export]
45macro_rules! duration_end {
46    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
47        $crate::__trace::duration_end!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
48    };
49}
50
51pub fn instant_wlancfg_start() {
52    if let Some(context) = trace::TraceCategoryContext::acquire(names::CATEGORY_WLAN) {
53        trace::instant(&context, names::NAME_WLANCFG_START, trace::Scope::Process, &[]);
54    }
55}
56
57pub fn async_begin_wlansoftmac_tx(async_id: trace::Id, origin: &str) {
58    trace::async_begin(
59        async_id,
60        names::CATEGORY_WLAN,
61        names::NAME_WLANSOFTMAC_TX,
62        &[trace::ArgValue::of("origin", origin)],
63    );
64}
65
66pub fn async_end_wlansoftmac_tx(async_id: trace::Id, status: zx::Status) {
67    trace::async_end(
68        async_id,
69        names::CATEGORY_WLAN,
70        names::NAME_WLANSOFTMAC_TX,
71        &[trace::ArgValue::of("status", format!("{}", status).as_str())],
72    );
73}
74
75pub fn async_begin_wlansoftmac_rx(async_id: trace::Id) {
76    trace::async_begin(async_id, names::CATEGORY_WLAN, names::NAME_WLANSOFTMAC_RX, &[]);
77}
78
79pub fn async_instant_wlansoftmac_rx(async_id: trace::Id, status: &str) {
80    if let Some(context) = trace::TraceCategoryContext::acquire(names::CATEGORY_WLAN) {
81        trace::async_instant(
82            async_id,
83            &context,
84            names::NAME_WLANSOFTMAC_RX,
85            &[trace::ArgValue::of("status", status)],
86        );
87    }
88}
89
90pub fn async_end_wlansoftmac_rx(async_id: trace::Id, status: &str) {
91    trace::async_end(
92        async_id,
93        names::CATEGORY_WLAN,
94        names::NAME_WLANSOFTMAC_RX,
95        &[trace::ArgValue::of("status", status)],
96    );
97}