From ee03abff84011f979f32206613471636a63f87cc Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Thu, 3 Apr 2025 13:50:08 +0000 Subject: [PATCH] Bug 1957331 - QM: Add telemetry for shutdown time excluding suspend; r=dom-storage-reviewers,jstutte This patch adds a new Glean timing_distribution metric, to measure the duration of QuotaManager shutdown. The measurement runs on the PBackground thread and uses NowExcludingSuspendMs to exclude any system suspend time (e.g. sleep or hibernation), providing a more accurate view of active runtime cost. This helps monitor shutdown performance and detect improvements or regressions, especially for users with significant storage data. Telemetry metadata was added under dom/quota/metrics.yaml. Differential Revision: https://phabricator.services.mozilla.com/D243625 --- dom/quota/ActorsParent.cpp | 24 ++++++++++++++++++++++++ dom/quota/metrics.yaml | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 6955e979de24..28d0936938d7 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -1840,8 +1840,32 @@ void QuotaManager::ShutdownInstance() { recordTimeDeltaHelper->Start(); + // Glean SDK recommends using its own timing APIs where possible. In this + // case, we use NowExcludingSuspendMs() directly to manually calculate a + // duration that excludes suspend time. This is a valid exception because + // our use case is sensitive to suspend, and we need full control over the + // timing logic. + // + // We are currently recording both this and the older helper-based + // measurement. The results are not directly comparable, since the new API + // uses monotonic time. If this approach proves more reliable, we'll retire + // the old telemetry, change the expiration of the new metric to never, + // and add a matching "including suspend" version. + + const auto startExcludingSuspendMs = NowExcludingSuspendMs(); + gInstance->Shutdown(); + const auto endExcludingSuspendMs = NowExcludingSuspendMs(); + + if (startExcludingSuspendMs && endExcludingSuspendMs) { + const auto duration = TimeDuration::FromMilliseconds( + *endExcludingSuspendMs - *startExcludingSuspendMs); + + glean::quotamanager_shutdown::total_time_excluding_suspend + .AccumulateRawDuration(duration); + } + recordTimeDeltaHelper->End(); gInstance = nullptr; diff --git a/dom/quota/metrics.yaml b/dom/quota/metrics.yaml index d71cc956eb1c..ee3c50d88510 100644 --- a/dom/quota/metrics.yaml +++ b/dom/quota/metrics.yaml @@ -129,6 +129,34 @@ quotamanager.initialize.temporarystorage: - jvarga@mozilla.com - storage-telemetry@mozilla.com expires: 141 +quotamanager.shutdown: + total_time_excluding_suspend: + type: timing_distribution + time_unit: millisecond + description: > + This metric logs the total time required to shut down the QuotaManager + instance on the PBackground thread. The duration excludes any periods + when the system was suspended (system sleep or hibernation), to better + reflect actual time spent performing shutdown. + While the shutdown process is measured on the PBackground thread, it + involves spinning the event loop and thus waiting for operations on other + threads (especially I/O threads) to complete. + The primary goal is to measure the actual runtime cost of shutdown under + typical conditions, without distortion from system-level suspension + delays. + This data can help detect performance regressions or improvements related + to QuotaManager shutdown behavior, especially in scenarios involving + large amounts of user storage data. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1590635 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1590635 + data_sensitivity: + - technical + notification_emails: + - jvarga@mozilla.com + - storage-telemetry@mozilla.com + expires: 141 dom.quota: info_load_time: