Last active
November 20, 2019 11:28
-
-
Save badboy/b9f8228e0688f0ba69cd22a60008d4d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Source Code Form is subject to the terms of the Mozilla Public | |
// License, v. 2.0. If a copy of the MPL was not distributed with this | |
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
use std::ffi::CString; | |
use std::os::raw::c_char; | |
/// A counter metric. | |
/// | |
/// Used to count things. | |
/// The value can only be incremented, not decremented. | |
#[derive(Clone, Debug)] | |
pub struct CounterMetric(u64); | |
extern "C" { | |
fn glean_new_counter_metric( | |
category: *const c_char, | |
name: *const c_char, | |
send_in_pings: *const *const c_char, | |
lifetime: u32, | |
disabled: u8, | |
) -> u64; | |
fn glean_counter_add(glean_handle: u64, metric_id: u64, amount: u32); | |
} | |
impl CounterMetric { | |
pub fn new( | |
category: String, | |
name: String, | |
_send_in_pings: Vec<String>, | |
lifetime: u32, | |
disabled: bool, | |
) -> CounterMetric { | |
unsafe { | |
let category = CString::new(category).unwrap(); | |
let name = CString::new(name).unwrap(); | |
let handle = glean_new_counter_metric( | |
category.as_ptr(), | |
name.as_ptr(), | |
std::ptr::null(), | |
lifetime, | |
disabled as u8, | |
); | |
CounterMetric(handle) | |
} | |
} | |
pub fn add(&self, amount: u32) { | |
unsafe { glean_counter_add(0, self.0, amount) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment