diff options
Diffstat (limited to 'toolkit/components/glean/api/src/private')
5 files changed, 96 insertions, 1 deletions
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. |