Bug 1494827 - Add USS telemetry for content process startup. r=kmag
authorEric Rahm <erahm@mozilla.com>
Thu, 27 Sep 2018 18:13:05 -0700
changeset 494574 5e28f82f0ba81e79ff0f53ead920e49718cab399
parent 494573 b8d8c53289150332f491df758566cf6832f2f400
child 494575 5dcf18a41fc29d4f7f10080566397fedfaa0c90a
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1494827
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494827 - Add USS telemetry for content process startup. r=kmag This adds telemetry for content processes' USS memory usage on startup.
js/xpconnect/loader/ScriptPreloader.cpp
js/xpconnect/loader/moz.build
toolkit/components/telemetry/Histograms.json
--- a/js/xpconnect/loader/ScriptPreloader.cpp
+++ b/js/xpconnect/loader/ScriptPreloader.cpp
@@ -11,26 +11,28 @@
 #include "mozilla/URLPreloader.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Logging.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Services.h"
+#include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 
 #include "MainThreadUtils.h"
 #include "nsDebug.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIFile.h"
 #include "nsIObserverService.h"
 #include "nsJSUtils.h"
+#include "nsMemoryReporterManager.h"
 #include "nsNetUtil.h"
 #include "nsProxyRelease.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "xpcpublic.h"
 
 #define STARTUP_COMPLETE_TOPIC "browser-delayed-startup-finished"
 #define DOC_ELEM_INSERTED_TOPIC "document-element-inserted"
@@ -418,16 +420,25 @@ ScriptPreloader::FinishContentStartup()
 
     mSaveTimer = nullptr;
 
     mStartupFinished = true;
 
     if (mChildActor) {
         mChildActor->SendScriptsAndFinalize(mScripts);
     }
+
+#ifdef XP_WIN
+    // Record the amount of USS at startup. This is Windows-only for now,
+    // we could turn it on for Linux relatively cheaply. On macOS it can have
+    // a perf impact.
+    mozilla::Telemetry::Accumulate(
+        mozilla::Telemetry::MEMORY_UNIQUE_CONTENT_STARTUP,
+        nsMemoryReporterManager::ResidentUnique() / 1024);
+#endif
 }
 
 bool
 ScriptPreloader::WillWriteScripts()
 {
     return Active() && (XRE_IsParentProcess() || mChildActor);
 }
 
--- a/js/xpconnect/loader/moz.build
+++ b/js/xpconnect/loader/moz.build
@@ -44,14 +44,15 @@ EXTRA_JS_MODULES += [
 ]
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '../src',
     '../wrappers',
     '/dom/base',
+    '/xpcom/base/',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-shadow']
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -976,16 +976,27 @@
     "bug_numbers": [1198209],
     "expires_in_version": "never",
     "kind": "exponential",
     "low": 32768,
     "high": 16777216,
     "n_buckets": 100,
     "description": "Unique Set Size (KB)"
   },
+  "MEMORY_UNIQUE_CONTENT_STARTUP": {
+    "record_in_processes": ["content"],
+    "alert_emails": ["erahm@mozilla.com", "memshrink-telemetry-alerts@mozilla.com"],
+    "bug_numbers": [1494827],
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "low": 2048,
+    "high": 131072,
+    "n_buckets": 100,
+    "description": "Unique Set Size of Content Process at Startup (KB)"
+  },
   "MEMORY_VSIZE": {
     "record_in_processes": ["main", "content"],
     "alert_emails": ["memshrink-telemetry-alerts@mozilla.com"],
     "expires_in_version": "never",
     "kind": "exponential",
     "low": 32768,
     "high": 16777216,
     "n_buckets": 100,