summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/bindings/private
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /toolkit/components/glean/bindings/private
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/glean/bindings/private')
-rw-r--r--toolkit/components/glean/bindings/private/Boolean.cpp2
-rw-r--r--toolkit/components/glean/bindings/private/Counter.cpp2
-rw-r--r--toolkit/components/glean/bindings/private/CustomDistribution.cpp23
-rw-r--r--toolkit/components/glean/bindings/private/CustomDistribution.h17
-rw-r--r--toolkit/components/glean/bindings/private/DistributionData.h22
-rw-r--r--toolkit/components/glean/bindings/private/Labeled.cpp2
-rw-r--r--toolkit/components/glean/bindings/private/Labeled.h2
-rw-r--r--toolkit/components/glean/bindings/private/Ping.cpp4
-rw-r--r--toolkit/components/glean/bindings/private/Timespan.cpp6
-rw-r--r--toolkit/components/glean/bindings/private/TimingDistribution.cpp20
10 files changed, 87 insertions, 13 deletions
diff --git a/toolkit/components/glean/bindings/private/Boolean.cpp b/toolkit/components/glean/bindings/private/Boolean.cpp
index 8300990b49..168179f569 100644
--- a/toolkit/components/glean/bindings/private/Boolean.cpp
+++ b/toolkit/components/glean/bindings/private/Boolean.cpp
@@ -21,7 +21,7 @@ void BooleanMetric::Set(bool aValue) const {
if (scalarId) {
Telemetry::ScalarSet(scalarId.extract(), aValue);
} else if (IsSubmetricId(mId)) {
- GetLabeledMirrorLock().apply([&](auto& lock) {
+ GetLabeledMirrorLock().apply([&](const auto& lock) {
auto tuple = lock.ref()->MaybeGet(mId);
if (tuple) {
Telemetry::ScalarSet(std::get<0>(tuple.ref()), std::get<1>(tuple.ref()),
diff --git a/toolkit/components/glean/bindings/private/Counter.cpp b/toolkit/components/glean/bindings/private/Counter.cpp
index f7f70f29eb..4eeeb3de7a 100644
--- a/toolkit/components/glean/bindings/private/Counter.cpp
+++ b/toolkit/components/glean/bindings/private/Counter.cpp
@@ -22,7 +22,7 @@ void CounterMetric::Add(int32_t aAmount) const {
if (scalarId) {
Telemetry::ScalarAdd(scalarId.extract(), aAmount);
} else if (IsSubmetricId(mId)) {
- GetLabeledMirrorLock().apply([&](auto& lock) {
+ GetLabeledMirrorLock().apply([&](const auto& lock) {
auto tuple = lock.ref()->MaybeGet(mId);
if (tuple && aAmount > 0) {
Telemetry::ScalarAdd(std::get<0>(tuple.ref()),
diff --git a/toolkit/components/glean/bindings/private/CustomDistribution.cpp b/toolkit/components/glean/bindings/private/CustomDistribution.cpp
index a5a821a558..88e96236db 100644
--- a/toolkit/components/glean/bindings/private/CustomDistribution.cpp
+++ b/toolkit/components/glean/bindings/private/CustomDistribution.cpp
@@ -33,6 +33,15 @@ void CustomDistributionMetric::AccumulateSamples(
fog_custom_distribution_accumulate_samples(mId, &aSamples);
}
+void CustomDistributionMetric::AccumulateSingleSample(uint64_t aSample) const {
+ auto hgramId = HistogramIdForMetric(mId);
+ if (hgramId) {
+ auto id = hgramId.extract();
+ Telemetry::Accumulate(id, aSample);
+ }
+ fog_custom_distribution_accumulate_single_sample(mId, aSample);
+}
+
void CustomDistributionMetric::AccumulateSamplesSigned(
const nsTArray<int64_t>& aSamples) const {
auto hgramId = HistogramIdForMetric(mId);
@@ -47,6 +56,16 @@ void CustomDistributionMetric::AccumulateSamplesSigned(
fog_custom_distribution_accumulate_samples_signed(mId, &aSamples);
}
+void CustomDistributionMetric::AccumulateSingleSampleSigned(
+ int64_t aSample) const {
+ auto hgramId = HistogramIdForMetric(mId);
+ if (hgramId) {
+ auto id = hgramId.extract();
+ Telemetry::Accumulate(id, aSample);
+ }
+ fog_custom_distribution_accumulate_single_sample_signed(mId, aSample);
+}
+
Result<Maybe<DistributionData>, nsCString>
CustomDistributionMetric::TestGetValue(const nsACString& aPingName) const {
nsCString err;
@@ -78,6 +97,10 @@ void GleanCustomDistribution::AccumulateSamples(
mCustomDist.AccumulateSamplesSigned(aSamples);
}
+void GleanCustomDistribution::AccumulateSingleSample(const int64_t aSample) {
+ mCustomDist.AccumulateSingleSampleSigned(aSample);
+}
+
void GleanCustomDistribution::TestGetValue(
const nsACString& aPingName,
dom::Nullable<dom::GleanDistributionData>& aRetval, ErrorResult& aRv) {
diff --git a/toolkit/components/glean/bindings/private/CustomDistribution.h b/toolkit/components/glean/bindings/private/CustomDistribution.h
index 8227b024ad..8074a0542e 100644
--- a/toolkit/components/glean/bindings/private/CustomDistribution.h
+++ b/toolkit/components/glean/bindings/private/CustomDistribution.h
@@ -35,6 +35,13 @@ class CustomDistributionMetric {
void AccumulateSamples(const nsTArray<uint64_t>& aSamples) const;
/**
+ * Accumulates the provided sample in the metric.
+ *
+ * @param aSamples The sample to be recorded by the metric.
+ */
+ void AccumulateSingleSample(uint64_t aSample) const;
+
+ /**
* Accumulates the provided samples in the metric.
*
* @param aSamples The vector holding the samples to be recorded by the
@@ -46,6 +53,14 @@ class CustomDistributionMetric {
void AccumulateSamplesSigned(const nsTArray<int64_t>& aSamples) const;
/**
+ * Accumulates the provided sample in the metric.
+ *
+ * @param aSamples The signed integer sample to be recorded by the
+ * metric.
+ */
+ void AccumulateSingleSampleSigned(int64_t aSample) const;
+
+ /**
* **Test-only API**
*
* Gets the currently stored value as a DistributionData.
@@ -80,6 +95,8 @@ class GleanCustomDistribution final : public GleanMetric {
void AccumulateSamples(const dom::Sequence<int64_t>& aSamples);
+ void AccumulateSingleSample(const int64_t aSample);
+
void TestGetValue(const nsACString& aPingName,
dom::Nullable<dom::GleanDistributionData>& aRetval,
ErrorResult& aRv);
diff --git a/toolkit/components/glean/bindings/private/DistributionData.h b/toolkit/components/glean/bindings/private/DistributionData.h
index fb9bba720e..782fe17c98 100644
--- a/toolkit/components/glean/bindings/private/DistributionData.h
+++ b/toolkit/components/glean/bindings/private/DistributionData.h
@@ -27,6 +27,28 @@ struct DistributionData final {
this->values.InsertOrUpdate(aBuckets[i], aCounts[i]);
}
}
+
+ friend std::ostream& operator<<(std::ostream& aStream,
+ const DistributionData& aDist) {
+ aStream << "DistributionData(";
+ aStream << "sum=" << aDist.sum << ", ";
+ aStream << "count=" << aDist.count << ", ";
+ aStream << "values={";
+ bool first = true;
+ for (const auto& entry : aDist.values) {
+ if (!first) {
+ aStream << ", ";
+ }
+ first = false;
+
+ const uint64_t bucket = entry.GetKey();
+ const uint64_t count = entry.GetData();
+ aStream << bucket << "=" << count;
+ }
+ aStream << "}";
+ aStream << ")";
+ return aStream;
+ }
};
} // namespace mozilla::glean
diff --git a/toolkit/components/glean/bindings/private/Labeled.cpp b/toolkit/components/glean/bindings/private/Labeled.cpp
index 23527708e0..1af9b870ae 100644
--- a/toolkit/components/glean/bindings/private/Labeled.cpp
+++ b/toolkit/components/glean/bindings/private/Labeled.cpp
@@ -31,7 +31,7 @@ already_AddRefed<GleanMetric> GleanLabeled::NamedGetter(const nsAString& aName,
auto mirrorId = ScalarIdForMetric(mId);
if (mirrorId) {
- GetLabeledMirrorLock().apply([&](auto& lock) {
+ GetLabeledMirrorLock().apply([&](const auto& lock) {
auto tuple = std::make_tuple<Telemetry::ScalarID, nsString>(
mirrorId.extract(), nsString(aName));
lock.ref()->InsertOrUpdate(submetricId, std::move(tuple));
diff --git a/toolkit/components/glean/bindings/private/Labeled.h b/toolkit/components/glean/bindings/private/Labeled.h
index 65e31bd2bd..0e3aafba05 100644
--- a/toolkit/components/glean/bindings/private/Labeled.h
+++ b/toolkit/components/glean/bindings/private/Labeled.h
@@ -60,7 +60,7 @@ class Labeled {
static inline void UpdateLabeledMirror(Telemetry::ScalarID aMirrorId,
uint32_t aSubmetricId,
const nsACString& aLabel) {
- GetLabeledMirrorLock().apply([&](auto& lock) {
+ GetLabeledMirrorLock().apply([&](const auto& lock) {
auto tuple = std::make_tuple<Telemetry::ScalarID, nsString>(
std::move(aMirrorId), NS_ConvertUTF8toUTF16(aLabel));
lock.ref()->InsertOrUpdate(aSubmetricId, std::move(tuple));
diff --git a/toolkit/components/glean/bindings/private/Ping.cpp b/toolkit/components/glean/bindings/private/Ping.cpp
index 19f4fb5f77..8dbb316128 100644
--- a/toolkit/components/glean/bindings/private/Ping.cpp
+++ b/toolkit/components/glean/bindings/private/Ping.cpp
@@ -42,7 +42,7 @@ void Ping::Submit(const nsACString& aReason) const {
{
auto callback = Maybe<PingTestCallback>();
GetCallbackMapLock().apply(
- [&](auto& lock) { callback = lock.ref()->Extract(mId); });
+ [&](const auto& lock) { callback = lock.ref()->Extract(mId); });
// Calling the callback outside of the lock allows it to register a new
// callback itself.
if (callback) {
@@ -55,7 +55,7 @@ void Ping::Submit(const nsACString& aReason) const {
void Ping::TestBeforeNextSubmit(PingTestCallback&& aCallback) const {
{
GetCallbackMapLock().apply(
- [&](auto& lock) { lock.ref()->InsertOrUpdate(mId, aCallback); });
+ [&](const auto& lock) { lock.ref()->InsertOrUpdate(mId, aCallback); });
}
}
diff --git a/toolkit/components/glean/bindings/private/Timespan.cpp b/toolkit/components/glean/bindings/private/Timespan.cpp
index 2ab1f0dbba..7f154152eb 100644
--- a/toolkit/components/glean/bindings/private/Timespan.cpp
+++ b/toolkit/components/glean/bindings/private/Timespan.cpp
@@ -93,7 +93,7 @@ void TimespanMetric::Start() const {
auto optScalarId = ScalarIdForMetric(mId);
if (optScalarId) {
auto scalarId = optScalarId.extract();
- GetTimesToStartsLock().apply([&](auto& lock) {
+ GetTimesToStartsLock().apply([&](const auto& lock) {
(void)NS_WARN_IF(lock.ref()->Remove(scalarId));
lock.ref()->InsertOrUpdate(scalarId, TimeStamp::Now());
});
@@ -105,7 +105,7 @@ void TimespanMetric::Stop() const {
auto optScalarId = ScalarIdForMetric(mId);
if (optScalarId) {
auto scalarId = optScalarId.extract();
- GetTimesToStartsLock().apply([&](auto& lock) {
+ GetTimesToStartsLock().apply([&](const auto& lock) {
auto optStart = lock.ref()->Extract(scalarId);
if (!NS_WARN_IF(!optStart)) {
double delta = (TimeStamp::Now() - optStart.extract()).ToMilliseconds();
@@ -127,7 +127,7 @@ void TimespanMetric::Cancel() const {
if (optScalarId) {
auto scalarId = optScalarId.extract();
GetTimesToStartsLock().apply(
- [&](auto& lock) { lock.ref()->Remove(scalarId); });
+ [&](const auto& lock) { lock.ref()->Remove(scalarId); });
}
fog_timespan_cancel(mId);
}
diff --git a/toolkit/components/glean/bindings/private/TimingDistribution.cpp b/toolkit/components/glean/bindings/private/TimingDistribution.cpp
index 036db5f9db..7273d3fd2f 100644
--- a/toolkit/components/glean/bindings/private/TimingDistribution.cpp
+++ b/toolkit/components/glean/bindings/private/TimingDistribution.cpp
@@ -106,7 +106,7 @@ extern "C" NS_EXPORT void GIFFT_TimingDistributionStart(
uint32_t aMetricId, mozilla::glean::TimerId aTimerId) {
auto mirrorId = mozilla::glean::HistogramIdForMetric(aMetricId);
if (mirrorId) {
- mozilla::glean::GetTimerIdToStartsLock().apply([&](auto& lock) {
+ mozilla::glean::GetTimerIdToStartsLock().apply([&](const auto& lock) {
auto tuple = mozilla::glean::MetricTimerTuple{aMetricId, aTimerId};
// It should be all but impossible for anyone to have already inserted
// this timer for this metric given the monotonicity of timer ids.
@@ -121,7 +121,7 @@ extern "C" NS_EXPORT void GIFFT_TimingDistributionStopAndAccumulate(
uint32_t aMetricId, mozilla::glean::TimerId aTimerId) {
auto mirrorId = mozilla::glean::HistogramIdForMetric(aMetricId);
if (mirrorId) {
- mozilla::glean::GetTimerIdToStartsLock().apply([&](auto& lock) {
+ mozilla::glean::GetTimerIdToStartsLock().apply([&](const auto& lock) {
auto tuple = mozilla::glean::MetricTimerTuple{aMetricId, aTimerId};
auto optStart = lock.ref()->Extract(tuple);
// The timer might not be in the map to be removed if it's already been
@@ -147,7 +147,7 @@ extern "C" NS_EXPORT void GIFFT_TimingDistributionCancel(
uint32_t aMetricId, mozilla::glean::TimerId aTimerId) {
auto mirrorId = mozilla::glean::HistogramIdForMetric(aMetricId);
if (mirrorId) {
- mozilla::glean::GetTimerIdToStartsLock().apply([&](auto& lock) {
+ mozilla::glean::GetTimerIdToStartsLock().apply([&](const auto& lock) {
// The timer might not be in the map to be removed if it's already been
// cancelled or stop_and_accumulate'd.
auto tuple = mozilla::glean::MetricTimerTuple{aMetricId, aTimerId};
@@ -172,8 +172,20 @@ void TimingDistributionMetric::StopAndAccumulate(const TimerId&& aId) const {
// type.
void TimingDistributionMetric::AccumulateRawDuration(
const TimeDuration& aDuration) const {
+ // `* 1000.0` is an acceptable overflow risk as durations are unlikely to be
+ // on the order of (-)10^282 years.
+ double durationNs = aDuration.ToMicroseconds() * 1000.0;
+ double roundedDurationNs = std::round(durationNs);
+ if (MOZ_UNLIKELY(
+ roundedDurationNs <
+ static_cast<double>(std::numeric_limits<uint64_t>::min()) ||
+ roundedDurationNs >
+ static_cast<double>(std::numeric_limits<uint64_t>::max()))) {
+ // TODO(bug 1691073): Instrument this error.
+ return;
+ }
fog_timing_distribution_accumulate_raw_nanos(
- mId, uint64_t(aDuration.ToMicroseconds() * 1000.00));
+ mId, static_cast<uint64_t>(roundedDurationNs));
}
void TimingDistributionMetric::Cancel(const TimerId&& aId) const {