Skip to main content

sampler_config/
common.rs

1// Copyright 2025 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
5use serde::{Deserialize, Serialize};
6use std::fmt;
7use std::ops::Deref;
8
9#[derive(Copy, Clone, Debug, Default, Deserialize, Hash, PartialEq, Eq, Serialize)]
10pub struct ProjectId(pub u32);
11
12impl fmt::Display for ProjectId {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        write!(f, "{}", self.0)
15    }
16}
17
18impl Deref for ProjectId {
19    type Target = u32;
20
21    fn deref(&self) -> &Self::Target {
22        &self.0
23    }
24}
25
26#[derive(Copy, Clone, Debug, Deserialize, Hash, PartialEq, Eq, Serialize)]
27pub struct MetricId(pub u32);
28
29impl fmt::Display for MetricId {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "{}", self.0)
32    }
33}
34
35impl Deref for MetricId {
36    type Target = u32;
37
38    fn deref(&self) -> &Self::Target {
39        &self.0
40    }
41}
42
43#[derive(Copy, Clone, Debug, Deserialize, Hash, PartialEq, Eq, Serialize)]
44pub struct EventCode(pub u32);
45
46impl fmt::Display for EventCode {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        write!(f, "{}", self.0)
49    }
50}
51
52impl Deref for EventCode {
53    type Target = u32;
54
55    fn deref(&self) -> &Self::Target {
56        &self.0
57    }
58}
59
60/// Supported Cobalt Metric types
61#[derive(Deserialize, Debug, PartialEq, Eq, Hash, Copy, Clone, Serialize)]
62pub enum MetricType {
63    /// Maps cached diffs from Uint or Int Inspect types.
64    /// NOTE: This does not use duration tracking. Durations are always set to 0.
65    Occurrence,
66
67    /// Maps raw Int Inspect types.
68    Integer,
69
70    /// Maps cached diffs from IntHistogram Inspect type.
71    IntHistogram,
72
73    /// Maps Inspect String type to StringValue (Cobalt 1.1 only).
74    String,
75}