// 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/.
fn stream_json_marker_data(&self, json_writer: &mut gecko_profiler::JSONWriter) { let name = self.id.get_name();
json_writer.unique_string_property("id", &name);
json_writer.string_property("value", self.value.as_str());
}
}
/// An object metric. pubenum ObjectMetric<K> {
Parent { /// The metric's ID. Used for testing and profiler markers. Object /// metrics canot be labeled, so we only store a MetricId. If this /// changes, this should be changed to a MetricGetter to distinguish /// between metrics and sub-metrics.
id: MetricId,
inner: glean::private::ObjectMetric<K>,
},
Child,
}
impl<K: ObjectSerialize + Clone> ObjectMetric<K> { /// Create a new object metric. pubfn new(id: MetricId, meta: CommonMetricData) -> Self { if need_ipc() {
ObjectMetric::Child
} else { let inner = glean::private::ObjectMetric::new(meta);
ObjectMetric::Parent { id, inner }
}
}
pubfn set(&self, value: K) { matchself { #[allow(unused)]
ObjectMetric::Parent { id, inner } => { #[cfg(feature = "with_gecko")]
gecko_profiler::lazy_add_marker!( "Object::set",
TelemetryProfilerCategory,
ObjectMetricMarker {
id: *id, // It might be better to store the "raw" // Result<Value, ObjectError> in the marker, as we // are writing a lot of strings here. That would, // however, require us to parameterise the marker // type with `K`, the type parameter to // ObjectMetric. This would be treated by // rust's `typeid` as another concrete type, // meaning that it would have a unique tag for // (de)serialisation, and may quickly exhaust our // (current) marker (de)serialisation tag limit.
value: truncate_string_for_marker(
value.clone().into_serialized_object().map_or_else(
|e| glean::traits::ObjectError::to_string(&e),
|v| serde_json::Value::to_string(&v),
),
),
}
);
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.
}
};
}
pubfn set_string(&self, value: String) { matchself { #[allow(unused)]
ObjectMetric::Parent { id, inner } => { #[cfg(feature = "with_gecko")]
gecko_profiler::lazy_add_marker!( "Object::set",
TelemetryProfilerCategory,
ObjectMetricMarker {
id: *id,
value: truncate_string_for_marker(value.clone()),
}
);
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.
}
};
}
pubfn test_get_value<'a, S: Into<Option<&'a str>>>(
&self,
ping_name: S,
) -> Option<serde_json::Value> { matchself {
ObjectMetric::Parent { inner, .. } => inner.test_get_value(ping_name),
ObjectMetric::Child => {
panic!("Cannot get test value for object metric in non-parent process!",)
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.