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 begin event immediately and writes a duration end event when the current scope
13/// exits. 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_begin!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
18        struct DurationEnd;
19        impl Drop for DurationEnd {
20            fn drop(&mut self) {
21                $crate::__trace::duration_end!($crate::names::CATEGORY_WLAN, $name);
22            }
23        }
24        let _scope = DurationEnd;
25    };
26}
27
28#[macro_export]
29macro_rules! duration_begin {
30    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
31        $crate::__trace::duration_begin!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
32    };
33}
34
35#[macro_export]
36macro_rules! duration_end {
37    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
38        $crate::__trace::duration_end!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
39    };
40}
41
42pub fn instant_wlancfg_start() {
43    if let Some(context) = trace::TraceCategoryContext::acquire(names::CATEGORY_WLAN) {
44        trace::instant(&context, names::NAME_WLANCFG_START, trace::Scope::Process, &[]);
45    }
46}
47
48pub fn async_begin_wlansoftmac_tx(async_id: trace::Id, origin: &str) {
49    trace::async_begin(
50        async_id,
51        names::CATEGORY_WLAN,
52        names::NAME_WLANSOFTMAC_TX,
53        &[trace::ArgValue::of("origin", origin)],
54    );
55}
56
57pub fn async_end_wlansoftmac_tx(async_id: trace::Id, status: zx::Status) {
58    trace::async_end(
59        async_id,
60        names::CATEGORY_WLAN,
61        names::NAME_WLANSOFTMAC_TX,
62        &[trace::ArgValue::of("status", format!("{}", status).as_str())],
63    );
64}
65
66pub fn async_begin_wlansoftmac_rx(async_id: trace::Id) {
67    trace::async_begin(async_id, names::CATEGORY_WLAN, names::NAME_WLANSOFTMAC_RX, &[]);
68}
69
70pub fn async_instant_wlansoftmac_rx(async_id: trace::Id, status: &str) {
71    if let Some(context) = trace::TraceCategoryContext::acquire(names::CATEGORY_WLAN) {
72        trace::async_instant(
73            async_id,
74            &context,
75            names::NAME_WLANSOFTMAC_RX,
76            &[trace::ArgValue::of("status", status)],
77        );
78    }
79}
80
81pub fn async_end_wlansoftmac_rx(async_id: trace::Id, status: &str) {
82    trace::async_end(
83        async_id,
84        names::CATEGORY_WLAN,
85        names::NAME_WLANSOFTMAC_RX,
86        &[trace::ArgValue::of("status", status)],
87    );
88}