cros_tracing_types/
lib.rs

1// Copyright 2023 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use std::time::Duration;
6
7use anyhow::bail;
8
9pub mod static_strings;
10
11/// Sets the duration for a trace.
12pub enum TraceDuration {
13    AlwaysOn,
14    StopIn(Duration),
15}
16
17impl TryFrom<TraceDuration> for Duration {
18    type Error = anyhow::Error;
19
20    fn try_from(duration: TraceDuration) -> anyhow::Result<Self> {
21        match duration {
22            TraceDuration::AlwaysOn => Ok(Duration::from_millis(0)),
23            TraceDuration::StopIn(d) if !d.is_zero() => Ok(d),
24            TraceDuration::StopIn(_) => {
25                bail!("zero duration not permitted; did you mean TraceDuration::AlwaysOn?")
26            }
27        }
28    }
29}