run_test_suite_lib/
trace.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
5#[cfg(target_os = "fuchsia")]
6macro_rules! duration {
7    ($name:expr) => {
8        ::fuchsia_trace::duration!("run_test_suite", $name);
9    };
10}
11
12// On host we'll measure durations manually, then emit a trace level log.
13#[cfg(not(target_os = "fuchsia"))]
14macro_rules! duration {
15    ($name:literal) => {
16        let _scope = crate::trace::DurationScope::new($name);
17    };
18}
19
20#[cfg(not(target_os = "fuchsia"))]
21pub(crate) struct DurationScope {
22    start: std::time::Instant,
23    name: &'static str,
24}
25
26#[cfg(not(target_os = "fuchsia"))]
27impl DurationScope {
28    pub(crate) fn new(name: &'static str) -> Self {
29        Self { name, start: std::time::Instant::now() }
30    }
31}
32
33#[cfg(not(target_os = "fuchsia"))]
34impl std::ops::Drop for DurationScope {
35    fn drop(&mut self) {
36        log::trace!(
37            name = self.name,
38            duration = self.start.elapsed().as_nanos() as u64;
39            "DURATION_NANOS"
40        );
41    }
42}
43
44pub(crate) use duration;