diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/components/glean/api/src | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/glean/api/src')
11 files changed, 172 insertions, 2 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 _); diff --git a/toolkit/components/glean/api/src/pings.rs b/toolkit/components/glean/api/src/pings.rs index f1d0332695..21eb3855ee 100644 --- a/toolkit/components/glean/api/src/pings.rs +++ b/toolkit/components/glean/api/src/pings.rs @@ -6,7 +6,7 @@ //! //! The contents of this module are generated by //! `toolkit/components/glean/build_scripts/glean_parser_ext/run_glean_parser.py`, from -//! 'toolkit/components/glean/pings.yaml`. +//! ping definitions files identified by `toolkit/components/glean/metrics_index.py`. include!(mozbuild::objdir_path!( "toolkit/components/glean/api/src/pings.rs" diff --git a/toolkit/components/glean/api/src/private/custom_distribution.rs b/toolkit/components/glean/api/src/private/custom_distribution.rs index 2114430898..aeaf9b58c2 100644 --- a/toolkit/components/glean/api/src/private/custom_distribution.rs +++ b/toolkit/components/glean/api/src/private/custom_distribution.rs @@ -92,6 +92,10 @@ impl CustomDistribution for CustomDistributionMetric { } } + pub fn accumulate_single_sample_signed(&self, _sample: i64) { + unimplemented!("bug 1884183: expose this to FOG") + } + pub fn test_get_value<'a, S: Into<Option<&'a str>>>( &self, ping_name: S, diff --git a/toolkit/components/glean/api/src/private/mod.rs b/toolkit/components/glean/api/src/private/mod.rs index b0b1e11393..e86e121d72 100644 --- a/toolkit/components/glean/api/src/private/mod.rs +++ b/toolkit/components/glean/api/src/private/mod.rs @@ -24,6 +24,7 @@ mod labeled; mod labeled_counter; mod memory_distribution; mod numerator; +mod object; mod ping; mod quantity; mod rate; @@ -46,6 +47,7 @@ pub use self::labeled::LabeledMetric; pub use self::labeled_counter::LabeledCounterMetric; pub use self::memory_distribution::MemoryDistributionMetric; pub use self::numerator::NumeratorMetric; +pub use self::object::ObjectMetric; pub use self::ping::Ping; pub use self::quantity::QuantityMetric; pub use self::rate::RateMetric; diff --git a/toolkit/components/glean/api/src/private/object.rs b/toolkit/components/glean/api/src/private/object.rs new file mode 100644 index 0000000000..5199cfad31 --- /dev/null +++ b/toolkit/components/glean/api/src/private/object.rs @@ -0,0 +1,83 @@ +// 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 super::{CommonMetricData, MetricId}; + +use crate::ipc::need_ipc; + +use glean::traits::ObjectSerialize; + +/// An object metric. +pub enum ObjectMetric<K> { + Parent { + id: MetricId, + inner: glean::private::ObjectMetric<K>, + }, + Child, +} + +impl<K: ObjectSerialize> ObjectMetric<K> { + /// Create a new object metric. + pub fn new(id: MetricId, meta: CommonMetricData) -> Self { + if need_ipc() { + ObjectMetric::Child + } else { + let inner = glean::private::ObjectMetric::new(meta); + ObjectMetric::Parent { id, inner } + } + } + + pub fn set(&self, value: K) { + match self { + ObjectMetric::Parent { inner, .. } => { + inner.set(value); + } + ObjectMetric::Child => { + log::error!("Unable to set object metric in non-main process. This operation will be ignored."); + // TODO: Record an error. + } + }; + } + + pub fn set_string(&self, value: String) { + match self { + ObjectMetric::Parent { inner, .. } => { + inner.set_string(value); + } + ObjectMetric::Child => { + log::error!("Unable to set object metric in non-main process. This operation will be ignored."); + // TODO: Record an error. + } + }; + } + + pub fn test_get_value<'a, S: Into<Option<&'a str>>>( + &self, + ping_name: S, + ) -> Option<serde_json::Value> { + match self { + ObjectMetric::Parent { inner, .. } => inner.test_get_value(ping_name), + ObjectMetric::Child => { + panic!("Cannot get test value for object metric in non-parent process!",) + } + } + } + + pub fn test_get_value_as_str<'a, S: Into<Option<&'a str>>>( + &self, + ping_name: S, + ) -> Option<String> { + self.test_get_value(ping_name) + .map(|val| serde_json::to_string(&val).unwrap()) + } + + pub fn test_get_num_recorded_errors(&self, error: glean::ErrorType) -> i32 { + match self { + ObjectMetric::Parent { inner, .. } => inner.test_get_num_recorded_errors(error), + ObjectMetric::Child => { + panic!("Cannot get the number of recorded errors in non-parent process!") + } + } + } +} diff --git a/toolkit/components/glean/api/src/private/ping.rs b/toolkit/components/glean/api/src/private/ping.rs index cc9585eea1..7e03c1ff00 100644 --- a/toolkit/components/glean/api/src/private/ping.rs +++ b/toolkit/components/glean/api/src/private/ping.rs @@ -30,6 +30,7 @@ impl Ping { include_client_id: bool, send_if_empty: bool, precise_timestamps: bool, + include_info_sections: bool, reason_codes: Vec<String>, ) -> Self { if need_ipc() { @@ -40,6 +41,7 @@ impl Ping { include_client_id, send_if_empty, precise_timestamps, + include_info_sections, reason_codes, )) } @@ -103,7 +105,7 @@ mod test { // Smoke test for what should be the generated code. static PROTOTYPE_PING: Lazy<Ping> = - Lazy::new(|| Ping::new("prototype", false, true, true, vec![])); + Lazy::new(|| Ping::new("prototype", false, true, true, true, vec![])); #[test] fn smoke_test_custom_ping() { diff --git a/toolkit/components/glean/api/src/private/timing_distribution.rs b/toolkit/components/glean/api/src/private/timing_distribution.rs index 0ab25cc900..6707560e41 100644 --- a/toolkit/components/glean/api/src/private/timing_distribution.rs +++ b/toolkit/components/glean/api/src/private/timing_distribution.rs @@ -374,6 +374,10 @@ impl TimingDistribution for TimingDistributionMetric { } } + pub fn accumulate_single_sample(&self, _sample: i64) { + unimplemented!("bug 1884183: expose this to FOG") + } + /// **Exported for test purposes.** /// /// Gets the currently stored value of the metric. |