From e537e97fc65693ef92f4db01daa2ad6d332a494b Mon Sep 17 00:00:00 2001
From: Paul Bone <pbone@mozilla.com>
Date: Tue, 13 Sep 2022 05:29:46 +0000
Subject: [PATCH] Bug 1786864 - Add telemetry for how long we spend gathering
 memory telemetry r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D155805
---
 toolkit/components/telemetry/Histograms.json | 12 ++++++++++++
 xpcom/base/MemoryTelemetry.cpp               |  1 +
 2 files changed, 13 insertions(+)

diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json
index 97903269c1540..616e270303bf2 100644
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -1295,6 +1295,18 @@
     "n_buckets": 100,
     "description": "Maximum-sized block of contiguous virtual memory (KB)"
   },
+  "MEMORY_COLLECTION_TIME": {
+    "record_in_processes": ["all"],
+    "products": ["firefox"],
+    "alert_emails": ["memshrink-telemetry-alerts@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "low": 1,
+    "high": 60000,
+    "n_buckets": 32,
+    "bug_numbers": [1786864],
+    "description": "Time spent gathering memory telemetry in milliseconds"
+  },
   "MEMORY_JS_COMPARTMENTS_SYSTEM": {
     "record_in_processes": ["main", "content"],
     "products": ["firefox", "fennec", "thunderbird"],
diff --git a/xpcom/base/MemoryTelemetry.cpp b/xpcom/base/MemoryTelemetry.cpp
index 75b47d4d887b2..9fe731543e1de 100644
--- a/xpcom/base/MemoryTelemetry.cpp
+++ b/xpcom/base/MemoryTelemetry.cpp
@@ -272,6 +272,7 @@ nsresult MemoryTelemetry::GatherReports(
   // asynchronously, on a background thread.
   RefPtr<Runnable> runnable = NS_NewRunnableFunction(
       "MemoryTelemetry::GatherReports", [mgr, completionRunnable]() mutable {
+        Telemetry::AutoTimer<Telemetry::MEMORY_COLLECTION_TIME> autoTimer;
         RECORD(MEMORY_VSIZE, Vsize, UNITS_BYTES);
 #if !defined(HAVE_64BIT_BUILD) || !defined(XP_WIN)
         RECORD(MEMORY_VSIZE_MAX_CONTIGUOUS, VsizeMaxContiguous, UNITS_BYTES);
-- 
GitLab