blob: 947d46946b36e6086c80d5c6d6c621d18f691eaa [file] [log] [blame] [edit]
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// This module is a wrapper of lib metrics_rs to only use it on ebuild.
#[cfg(feature = "chromeos")]
use anyhow::Context;
use anyhow::Result;
#[cfg(feature = "chromeos")]
use crate::sync::NoPoison;
// Use metrics_rs on ebuild.
#[cfg(feature = "chromeos")]
pub fn send_to_uma(name: &str, sample: i32, min: i32, max: i32, nbuckets: i32) -> Result<()> {
let metrics = metrics_rs::MetricsLibrary::get().context("MetricsLibrary::get() failed")?;
// Shall panic on poisoned mutex.
metrics
.do_lock()
.send_to_uma(name, sample, min, max, nbuckets)?;
Ok(())
}
// send_to_uma is no-op on cargo build.
#[cfg(not(feature = "chromeos"))]
pub fn send_to_uma(_name: &str, _sample: i32, _min: i32, _max: i32, _nbuckets: i32) -> Result<()> {
Ok(())
}
// Use metrics_rs on ebuild.
#[cfg(feature = "chromeos")]
pub fn send_enum_to_uma(name: &str, sample: i32, exclusive_max: i32) -> Result<()> {
let metrics = metrics_rs::MetricsLibrary::get().context("MetricsLibrary::get() failed")?;
// Shall panic on poisoned mutex.
metrics
.do_lock()
.send_enum_to_uma(name, sample, exclusive_max)?;
Ok(())
}
// send_enum_to_uma is no-op on cargo build.
#[cfg(not(feature = "chromeos"))]
pub fn send_enum_to_uma(_name: &str, _sample: i32, _exclusive_max: i32) -> Result<()> {
Ok(())
}