diff --git a/toolkit/components/glean/metrics_index.py b/toolkit/components/glean/metrics_index.py index c393a46a0eaa..1f51ee17e8b5 100644 --- a/toolkit/components/glean/metrics_index.py +++ b/toolkit/components/glean/metrics_index.py @@ -26,6 +26,7 @@ gecko_metrics = [ "toolkit/components/glean/metrics.yaml", "toolkit/components/pdfjs/metrics.yaml", "toolkit/components/processtools/metrics.yaml", + "xpcom/metrics.yaml", ] # Metrics that are sent by Firefox Desktop diff --git a/xpcom/metrics.yaml b/xpcom/metrics.yaml new file mode 100644 index 000000000000..36d2e0fad327 --- /dev/null +++ b/xpcom/metrics.yaml @@ -0,0 +1,30 @@ +# 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 http://mozilla.org/MPL/2.0/. + +# Adding a new metric? We have docs for that! +# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html + +--- +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 +$tags: + - "Core :: XPCOM" + +timer_thread: + timers_fired_per_wakeup: + type: custom_distribution + description: > + How many timers were processed in a single wake-up of the Timer Thread. + range_min: 0 + range_max: 80 + bucket_count: 20 + histogram_type: exponential + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1814718 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1814718 + data_sensitivity: + - technical + notification_emails: + - jlink@mozilla.com + expires: never diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index 39570607fbbb..12c234ec9997 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -20,6 +20,8 @@ #include "mozilla/OperatorNewExtensions.h" #include "mozilla/StaticPrefs_timer.h" +#include "mozilla/glean/GleanMetrics.h" + #include using namespace mozilla; @@ -539,6 +541,7 @@ TimerThread::Run() { mAllowedEarlyFiringMicroseconds = usIntervalResolution / 2; bool forceRunNextTimer = false; + uint64_t timersFiredThisWakeup = 0; while (!mShutdown) { // Have to use PRIntervalTime here, since PR_WaitCondVar takes it TimeDuration waitFor; @@ -581,6 +584,7 @@ TimerThread::Run() { // release of the timer so that we don't end up releasing the timer // on the TimerThread instead of on the thread it targets. { + ++timersFiredThisWakeup; LogTimerEvent::Run run(timerRef.get()); PostTimerEvent(timerRef.forget()); } @@ -643,6 +647,10 @@ TimerThread::Run() { mWaiting = true; mNotified = false; { + // About to sleep - let's make note of how many timers we processed. + glean::timer_thread::timers_fired_per_wakeup.AccumulateSamples( + {timersFiredThisWakeup}); + timersFiredThisWakeup = 0; AUTO_PROFILER_TRACING_MARKER("TimerThread", "Wait", OTHER); mMonitor.Wait(waitFor); }