summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/api/src/ffi
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /toolkit/components/glean/api/src/ffi
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/glean/api/src/ffi')
-rw-r--r--toolkit/components/glean/api/src/ffi/custom_distribution.rs2
-rw-r--r--toolkit/components/glean/api/src/ffi/memory_distribution.rs2
-rw-r--r--toolkit/components/glean/api/src/ffi/mod.rs1
-rw-r--r--toolkit/components/glean/api/src/ffi/object.rs68
-rw-r--r--toolkit/components/glean/api/src/ffi/timing_distribution.rs2
5 files changed, 75 insertions, 0 deletions
diff --git a/toolkit/components/glean/api/src/ffi/custom_distribution.rs b/toolkit/components/glean/api/src/ffi/custom_distribution.rs
index 853a6e9845..643ebfbff5 100644
--- a/toolkit/components/glean/api/src/ffi/custom_distribution.rs
+++ b/toolkit/components/glean/api/src/ffi/custom_distribution.rs
@@ -22,6 +22,7 @@ pub extern "C" fn fog_custom_distribution_test_get_value(
id: u32,
ping_name: &nsACString,
sum: &mut u64,
+ count: &mut u64,
buckets: &mut ThinVec<u64>,
counts: &mut ThinVec<u64>,
) {
@@ -33,6 +34,7 @@ pub extern "C" fn fog_custom_distribution_test_get_value(
);
// FIXME(bug 1771885): Glean should use `u64` where it can.
*sum = val.sum as _;
+ *count = val.count as _;
for (&bucket, &count) in val.values.iter() {
buckets.push(bucket as _);
counts.push(count as _);
diff --git a/toolkit/components/glean/api/src/ffi/memory_distribution.rs b/toolkit/components/glean/api/src/ffi/memory_distribution.rs
index cf09d3f8de..35c8326c4d 100644
--- a/toolkit/components/glean/api/src/ffi/memory_distribution.rs
+++ b/toolkit/components/glean/api/src/ffi/memory_distribution.rs
@@ -22,6 +22,7 @@ pub extern "C" fn fog_memory_distribution_test_get_value(
id: u32,
ping_name: &nsACString,
sum: &mut u64,
+ count: &mut u64,
buckets: &mut ThinVec<u64>,
counts: &mut ThinVec<u64>,
) {
@@ -32,6 +33,7 @@ pub extern "C" fn fog_memory_distribution_test_get_value(
test_get!(metric, ping_name)
);
*sum = val.sum as _;
+ *count = val.count as _;
for (&bucket, &count) in val.values.iter() {
buckets.push(bucket as _);
counts.push(count as _);
diff --git a/toolkit/components/glean/api/src/ffi/mod.rs b/toolkit/components/glean/api/src/ffi/mod.rs
index 23235fc2f1..4eb614aefc 100644
--- a/toolkit/components/glean/api/src/ffi/mod.rs
+++ b/toolkit/components/glean/api/src/ffi/mod.rs
@@ -16,6 +16,7 @@ mod event;
mod labeled;
mod memory_distribution;
mod numerator;
+mod object;
mod ping;
mod quantity;
mod rate;
diff --git a/toolkit/components/glean/api/src/ffi/object.rs b/toolkit/components/glean/api/src/ffi/object.rs
new file mode 100644
index 0000000000..85f5269da9
--- /dev/null
+++ b/toolkit/components/glean/api/src/ffi/object.rs
@@ -0,0 +1,68 @@
+// 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;
+
+use crate::metrics::__glean_metric_maps as metric_maps;
+
+#[no_mangle]
+pub extern "C" fn fog_object_set_string(id: u32, value: &nsACString) {
+ if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
+ panic!("No dynamic metric for objects");
+ }
+
+ let value = value.to_utf8().to_string();
+ if metric_maps::set_object_by_id(id, value).is_err() {
+ panic!("No object for id {}", id);
+ }
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn fog_object_test_has_value(id: u32, ping_name: &nsACString) -> bool {
+ let storage = if ping_name.is_empty() {
+ None
+ } else {
+ Some(ping_name.to_utf8().into_owned())
+ };
+ if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
+ panic!("No dynamic metric for objects");
+ } else {
+ metric_maps::object_test_get_value(id, storage).is_some()
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn fog_object_test_get_value(
+ id: u32,
+ ping_name: &nsACString,
+ value: &mut nsACString,
+) {
+ let storage = if ping_name.is_empty() {
+ None
+ } else {
+ Some(ping_name.to_utf8().into_owned())
+ };
+
+ let object = if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
+ panic!("No dynamic metric for objects");
+ } else {
+ match metric_maps::object_test_get_value(id, storage) {
+ Some(object) => object,
+ None => return,
+ }
+ };
+ value.assign(&object);
+}
+
+#[no_mangle]
+pub extern "C" fn fog_object_test_get_error(id: u32, error_str: &mut nsACString) -> bool {
+ let err = if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
+ panic!("No dynamic metric for objects");
+ } else {
+ metric_maps::object_test_get_error(id)
+ };
+ err.map(|err_str| error_str.assign(&err_str)).is_some()
+}
diff --git a/toolkit/components/glean/api/src/ffi/timing_distribution.rs b/toolkit/components/glean/api/src/ffi/timing_distribution.rs
index 4ac5d03986..4391985efa 100644
--- a/toolkit/components/glean/api/src/ffi/timing_distribution.rs
+++ b/toolkit/components/glean/api/src/ffi/timing_distribution.rs
@@ -58,6 +58,7 @@ pub extern "C" fn fog_timing_distribution_test_get_value(
id: u32,
ping_name: &nsACString,
sum: &mut u64,
+ count: &mut u64,
buckets: &mut ThinVec<u64>,
counts: &mut ThinVec<u64>,
) {
@@ -68,6 +69,7 @@ pub extern "C" fn fog_timing_distribution_test_get_value(
test_get!(metric, ping_name)
);
*sum = val.sum as _;
+ *count = val.count as _;
for (&bucket, &count) in val.values.iter() {
buckets.push(bucket as _);
counts.push(count as _);