Bug 1491478 - Move WebRender memory reporting back to gfxPlatform. r=me
authorBobby Holley <bobbyholley@gmail.com>
Fri, 14 Sep 2018 16:24:36 -0700
changeset 492256 6368a1c271deedd050c22b4d38ba296377a2f825
parent 492255 67f6883be55ddf8601475b0b6278a54dd113753f
child 492257 5a423ac3eb2345b4a56a362b12dde2b256d37d79
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)
reviewersme
bugs1491478
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 1491478 - Move WebRender memory reporting back to gfxPlatform. r=me This is how things looked when jrmuizel reviewed them. MozReview-Commit-ID: Gqp1tcNzsjC
gfx/thebes/gfxPlatform.cpp
gfx/webrender_bindings/RenderThread.cpp
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -626,16 +626,99 @@ static uint32_t GetSkiaGlyphCacheSize()
 
     return cacheSize;
 #else
     return kDefaultGlyphCacheSize;
 #endif // MOZ_WIDGET_ANDROID
 }
 #endif
 
+class WebRenderMemoryReporter final : public nsIMemoryReporter {
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIMEMORYREPORTER
+
+private:
+  ~WebRenderMemoryReporter() = default;
+};
+
+// Memory reporter for WebRender.
+//
+// The reporting within WebRender is manual and incomplete. We could do a much
+// more thorough job by depending on the malloc_size_of crate, but integrating
+// that into WebRender is tricky [1].
+//
+// So the idea is to start with manual reporting for the large allocations
+// detected by DMD, and see how much that can cover in practice (which may
+// require a few rounds of iteration). If that approach turns out to be
+// fundamentally insufficient, we can either duplicate more of the malloc_size_of
+// functionality in WebRender, or deal with the complexity of a gecko-only
+// crate dependency.
+//
+// [1] See https://bugzilla.mozilla.org/show_bug.cgi?id=1480293#c1
+struct WebRenderMemoryReporterHelper {
+  WebRenderMemoryReporterHelper(nsIHandleReportCallback* aCallback, nsISupports* aData)
+    : mCallback(aCallback), mData(aData)
+  {}
+  nsCOMPtr<nsIHandleReportCallback> mCallback;
+  nsCOMPtr<nsISupports> mData;
+
+  void Report(size_t aBytes, const char* aName) const
+  {
+    nsPrintfCString path("explicit/gfx/webrender/%s", aName);
+    mCallback->Callback(EmptyCString(), path,
+                        nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
+                        aBytes, EmptyCString(), mData);
+  }
+};
+
+static void
+FinishAsyncMemoryReport()
+{
+  nsCOMPtr<nsIMemoryReporterManager> imgr =
+    do_GetService("@mozilla.org/memory-reporter-manager;1");
+  if (imgr) {
+    imgr->EndReport();
+  }
+}
+
+NS_IMPL_ISUPPORTS(WebRenderMemoryReporter, nsIMemoryReporter)
+
+NS_IMETHODIMP
+WebRenderMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
+                                        nsISupports* aData, bool aAnonymize)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+  MOZ_ASSERT(NS_IsMainThread());
+  layers::CompositorManagerChild* manager = CompositorManagerChild::GetInstance();
+  if (!manager) {
+    FinishAsyncMemoryReport();
+    return NS_OK;
+  }
+
+  WebRenderMemoryReporterHelper helper(aHandleReport, aData);
+  manager->SendReportMemory(
+    [=](wr::MemoryReport aReport) {
+      helper.Report(aReport.primitive_stores, "primitive-stores");
+      helper.Report(aReport.clip_stores, "clip-stores");
+      helper.Report(aReport.gpu_cache_metadata, "gpu-cache/metadata");
+      helper.Report(aReport.gpu_cache_cpu_mirror, "gpu-cache/cpu-mirror");
+      helper.Report(aReport.render_tasks, "render-tasks");
+      helper.Report(aReport.hit_testers, "hit-testers");
+      FinishAsyncMemoryReport();
+    },
+    [](mozilla::ipc::ResponseRejectReason aReason) {
+      FinishAsyncMemoryReport();
+    }
+  );
+
+  return NS_OK;
+}
+
+
 void
 gfxPlatform::Init()
 {
     MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
     MOZ_RELEASE_ASSERT(NS_IsMainThread(), "GFX: Not in main thread.");
 
     if (gEverInitialized) {
         MOZ_CRASH("Already started???");
@@ -818,16 +901,20 @@ gfxPlatform::Init()
 
     // Request the imgITools service, implicitly initializing ImageLib.
     nsCOMPtr<imgITools> imgTools = do_GetService("@mozilla.org/image/tools;1");
     if (!imgTools) {
       MOZ_CRASH("Could not initialize ImageLib");
     }
 
     RegisterStrongMemoryReporter(new GfxMemoryImageReporter());
+    if (XRE_IsParentProcess()) {
+      RegisterStrongAsyncMemoryReporter(new WebRenderMemoryReporter());
+    }
+
 #ifdef USE_SKIA
     RegisterStrongMemoryReporter(new SkMemoryReporter());
 #endif
     mlg::InitializeMemoryReporters();
 
 #ifdef USE_SKIA
     uint32_t skiaCacheSize = GetSkiaGlyphCacheSize();
     if (skiaCacheSize != kDefaultGlyphCacheSize) {
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -2,122 +2,37 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "base/task.h"
 #include "GeckoProfiler.h"
 #include "RenderThread.h"
-#include "nsIMemoryReporter.h"
 #include "nsThreadUtils.h"
 #include "mtransport/runnable_utils.h"
 #include "mozilla/layers/AsyncImagePipelineManager.h"
 #include "mozilla/gfx/GPUParent.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
-#include "mozilla/layers/CompositorManagerChild.h"
 #include "mozilla/layers/WebRenderBridgeParent.h"
 #include "mozilla/layers/SharedSurfacesParent.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/webrender/RendererOGL.h"
 #include "mozilla/webrender/RenderTextureHost.h"
 #include "mozilla/widget/CompositorWidget.h"
 
 #ifdef XP_WIN
 #include "mozilla/widget/WinCompositorWindowThread.h"
 #endif
 
 namespace mozilla {
 namespace wr {
 
-class MemoryReporter final : public nsIMemoryReporter {
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIMEMORYREPORTER
-
-private:
-  ~MemoryReporter() = default;
-};
-
-// Memory reporter for WebRender.
-//
-// The reporting within WebRender is manual and incomplete. We could do a much
-// more thorough job by depending on the malloc_size_of crate, but integrating
-// that into WebRender is tricky [1].
-//
-// So the idea is to start with manual reporting for the large allocations
-// detected by DMD, and see how much that can cover in practice (which may
-// require a few rounds of iteration). If that approach turns out to be
-// fundamentally insufficient, we can either duplicate more of the malloc_size_of
-// functionality in WebRender, or deal with the complexity of a gecko-only
-// crate dependency.
-//
-// [1] See https://bugzilla.mozilla.org/show_bug.cgi?id=1480293#c1
-struct MemoryReporterHelper {
-  MemoryReporterHelper(nsIHandleReportCallback* aCallback, nsISupports* aData)
-    : mCallback(aCallback), mData(aData)
-  {}
-  nsCOMPtr<nsIHandleReportCallback> mCallback;
-  nsCOMPtr<nsISupports> mData;
-
-  void Report(size_t aBytes, const char* aName) const
-  {
-    nsPrintfCString path("explicit/gfx/webrender/%s", aName);
-    mCallback->Callback(EmptyCString(), path,
-                        nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
-                        aBytes, EmptyCString(), mData);
-  }
-};
-
-static void
-FinishAsyncMemoryReport()
-{
-  nsCOMPtr<nsIMemoryReporterManager> imgr =
-    do_GetService("@mozilla.org/memory-reporter-manager;1");
-  if (imgr) {
-    imgr->EndReport();
-  }
-}
-
-NS_IMPL_ISUPPORTS(MemoryReporter, nsIMemoryReporter)
-
-NS_IMETHODIMP
-MemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
-                               nsISupports* aData, bool aAnonymize)
-{
-  MOZ_ASSERT(XRE_IsParentProcess());
-  MOZ_ASSERT(NS_IsMainThread());
-  layers::CompositorManagerChild* manager =
-    layers::CompositorManagerChild::GetInstance();
-  if (!manager) {
-    FinishAsyncMemoryReport();
-    return NS_OK;
-  }
-
-  MemoryReporterHelper helper(aHandleReport, aData);
-  manager->SendReportMemory(
-    [=](wr::MemoryReport aReport) {
-      helper.Report(aReport.primitive_stores, "primitive-stores");
-      helper.Report(aReport.clip_stores, "clip-stores");
-      helper.Report(aReport.gpu_cache_metadata, "gpu-cache/metadata");
-      helper.Report(aReport.gpu_cache_cpu_mirror, "gpu-cache/cpu-mirror");
-      helper.Report(aReport.render_tasks, "render-tasks");
-      helper.Report(aReport.hit_testers, "hit-testers");
-      FinishAsyncMemoryReport();
-    },
-    [](mozilla::ipc::ResponseRejectReason aReason) {
-      FinishAsyncMemoryReport();
-    }
-  );
-
-  return NS_OK;
-}
-
 static StaticRefPtr<RenderThread> sRenderThread;
 
 RenderThread::RenderThread(base::Thread* aThread)
   : mThread(aThread)
   , mFrameCountMapLock("RenderThread.mFrameCountMapLock")
   , mRenderTextureMapLock("RenderThread.mRenderTextureMapLock")
   , mHasShutdown(false)
   , mHandlingDeviceReset(false)
@@ -165,18 +80,16 @@ RenderThread::Start()
       gfx::gfxVars::UseWebRenderProgramBinary()) {
     MOZ_ASSERT(gfx::gfxVars::UseWebRender());
     // Initialize program cache if necessary
     RefPtr<Runnable> runnable = WrapRunnable(
       RefPtr<RenderThread>(sRenderThread.get()),
       &RenderThread::ProgramCacheTask);
     sRenderThread->Loop()->PostTask(runnable.forget());
   }
-
-  RegisterStrongAsyncMemoryReporter(new MemoryReporter());
 }
 
 // static
 void
 RenderThread::ShutDown()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(sRenderThread);