Bug 1694496 MLA FFI for `rate` metric type r=janerik

Differential Revision: https://phabricator.services.mozilla.com/D119786
This commit is contained in:
Chris H-C 2021-07-15 16:05:51 +00:00
Родитель e9bc7d86c7
Коммит 69a309e7de
4 изменённых файлов: 128 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,37 @@
// 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/.
#![cfg(feature = "with_gecko")]
use nsstring::nsACString;
#[no_mangle]
pub unsafe extern "C" fn fog_denominator_add(id: u32, amount: i32) {
with_metric!(DENOMINATOR_MAP, id, metric, metric.add(amount));
}
#[no_mangle]
pub unsafe extern "C" fn fog_denominator_test_has_value(id: u32, ping_name: &nsACString) -> bool {
with_metric!(DENOMINATOR_MAP, id, metric, test_has!(metric, ping_name))
}
#[no_mangle]
pub unsafe extern "C" fn fog_denominator_test_get_value(id: u32, ping_name: &nsACString) -> i32 {
with_metric!(DENOMINATOR_MAP, id, metric, test_get!(metric, ping_name))
}
#[no_mangle]
pub extern "C" fn fog_denominator_test_get_error(
id: u32,
ping_name: &nsACString,
error_str: &mut nsACString,
) -> bool {
let err = with_metric!(
DENOMINATOR_MAP,
id,
metric,
test_get_errors!(metric, ping_name)
);
err.map(|err_str| error_str.assign(&err_str)).is_some()
}

Просмотреть файл

@ -11,11 +11,14 @@ mod boolean;
mod counter;
mod custom_distribution;
mod datetime;
mod denominator;
mod event;
mod labeled;
mod memory_distribution;
mod numerator;
mod ping;
mod quantity;
mod rate;
mod string;
mod string_list;
mod timespan;

Просмотреть файл

@ -0,0 +1,44 @@
// 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/.
#![cfg(feature = "with_gecko")]
use nsstring::nsACString;
#[no_mangle]
pub unsafe extern "C" fn fog_numerator_add_to_numerator(id: u32, amount: i32) {
with_metric!(NUMERATOR_MAP, id, metric, metric.add_to_numerator(amount));
}
#[no_mangle]
pub unsafe extern "C" fn fog_numerator_test_has_value(id: u32, ping_name: &nsACString) -> bool {
with_metric!(NUMERATOR_MAP, id, metric, test_has!(metric, ping_name))
}
#[no_mangle]
pub unsafe extern "C" fn fog_numerator_test_get_value(
id: u32,
ping_name: &nsACString,
num: &mut i32,
den: &mut i32,
) {
let (n, d) = with_metric!(NUMERATOR_MAP, id, metric, test_get!(metric, ping_name));
*num = n;
*den = d;
}
#[no_mangle]
pub extern "C" fn fog_numerator_test_get_error(
id: u32,
ping_name: &nsACString,
error_str: &mut nsACString,
) -> bool {
let err = with_metric!(
NUMERATOR_MAP,
id,
metric,
test_get_errors!(metric, ping_name)
);
err.map(|err_str| error_str.assign(&err_str)).is_some()
}

Просмотреть файл

@ -0,0 +1,44 @@
// 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/.
#![cfg(feature = "with_gecko")]
use nsstring::nsACString;
#[no_mangle]
pub unsafe extern "C" fn fog_rate_add_to_numerator(id: u32, amount: i32) {
with_metric!(RATE_MAP, id, metric, metric.add_to_numerator(amount));
}
#[no_mangle]
pub unsafe extern "C" fn fog_rate_add_to_denominator(id: u32, amount: i32) {
with_metric!(RATE_MAP, id, metric, metric.add_to_denominator(amount));
}
#[no_mangle]
pub unsafe extern "C" fn fog_rate_test_has_value(id: u32, ping_name: &nsACString) -> bool {
with_metric!(RATE_MAP, id, metric, test_has!(metric, ping_name))
}
#[no_mangle]
pub unsafe extern "C" fn fog_rate_test_get_value(
id: u32,
ping_name: &nsACString,
num: &mut i32,
den: &mut i32,
) {
let (n, d) = with_metric!(RATE_MAP, id, metric, test_get!(metric, ping_name));
*num = n;
*den = d;
}
#[no_mangle]
pub extern "C" fn fog_rate_test_get_error(
id: u32,
ping_name: &nsACString,
error_str: &mut nsACString,
) -> bool {
let err = with_metric!(RATE_MAP, id, metric, test_get_errors!(metric, ping_name));
err.map(|err_str| error_str.assign(&err_str)).is_some()
}