1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

pub mod names;

#[doc(hidden)]
pub use fuchsia_trace as __trace;

use {fuchsia_trace as trace, fuchsia_zircon as zx};

/// Writes a duration event when the current scope exits. No event is written at the start of the
/// duration. As with all wlan-trace macros, the category will be "wlan" by default.
#[macro_export]
macro_rules! duration {
    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
        $crate::__trace::duration!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
    };
}

/// Writes a duration begin event immediately and writes a duration end event when the current scope
/// exits. As with all wlan-trace macros, the category will be "wlan" by default.
#[macro_export]
macro_rules! duration_begin_scope {
    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
        $crate::__trace::duration_begin!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
        struct DurationEnd;
        impl Drop for DurationEnd {
            fn drop(&mut self) {
                $crate::__trace::duration_end!($crate::names::CATEGORY_WLAN, $name);
            }
        }
        let _scope = DurationEnd;
    };
}

#[macro_export]
macro_rules! duration_begin {
    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
        $crate::__trace::duration_begin!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
    };
}

#[macro_export]
macro_rules! duration_end {
    ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
        $crate::__trace::duration_end!($crate::names::CATEGORY_WLAN, $name $(, $key => $val)* );
    };
}

pub fn instant_wlancfg_start() {
    if let Some(context) = trace::TraceCategoryContext::acquire(names::CATEGORY_WLAN) {
        trace::instant(&context, names::NAME_WLANCFG_START, trace::Scope::Process, &[]);
    }
}

pub fn async_begin_wlansoftmac_tx(async_id: trace::Id, origin: &str) {
    trace::async_begin(
        async_id,
        names::CATEGORY_WLAN,
        names::NAME_WLANSOFTMAC_TX,
        &[trace::ArgValue::of("origin", origin)],
    );
}

pub fn async_end_wlansoftmac_tx(async_id: trace::Id, status: zx::Status) {
    trace::async_end(
        async_id,
        names::CATEGORY_WLAN,
        names::NAME_WLANSOFTMAC_TX,
        &[trace::ArgValue::of("status", format!("{}", status).as_str())],
    );
}

pub fn async_begin_wlansoftmac_rx(async_id: trace::Id) {
    trace::async_begin(async_id, names::CATEGORY_WLAN, names::NAME_WLANSOFTMAC_RX, &[]);
}

pub fn async_instant_wlansoftmac_rx(async_id: trace::Id, status: &str) {
    if let Some(context) = trace::TraceCategoryContext::acquire(names::CATEGORY_WLAN) {
        trace::async_instant(
            async_id,
            &context,
            names::NAME_WLANSOFTMAC_RX,
            &[trace::ArgValue::of("status", status)],
        );
    }
}

pub fn async_end_wlansoftmac_rx(async_id: trace::Id, status: &str) {
    trace::async_end(
        async_id,
        names::CATEGORY_WLAN,
        names::NAME_WLANSOFTMAC_RX,
        &[trace::ArgValue::of("status", status)],
    );
}