Bug 1251065 - Add prefs for logging the current and peak texture usage r=nical
authorJames Willcox <snorp@snorp.net>
Wed, 27 Jan 2016 09:37:44 -0600
changeset 322180 d7584b9e016655aad9900c849ae2f58ec3dbcc26
parent 322179 fe64e32bb4fbdb8d43e2855add7c970cc600d367
child 322181 06a4669aaf8c8d7f76232b5eb19ff0cd6263cc0b
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1251065
milestone47.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 1251065 - Add prefs for logging the current and peak texture usage r=nical
gfx/gl/GfxTexturesReporter.cpp
gfx/thebes/gfxPrefs.h
modules/libpref/init/all.js
--- a/gfx/gl/GfxTexturesReporter.cpp
+++ b/gfx/gl/GfxTexturesReporter.cpp
@@ -1,38 +1,79 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=4 et sw=4 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 <string>
+#include <sstream>
 #include "GfxTexturesReporter.h"
+#include "gfxPrefs.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::gl;
 
 NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter)
 
 Atomic<size_t> GfxTexturesReporter::sAmount(0);
 Atomic<size_t> GfxTexturesReporter::sPeakAmount(0);
 Atomic<size_t> GfxTexturesReporter::sTileWasteAmount(0);
 
+std::string
+FormatBytes(size_t amount)
+{
+    std::stringstream stream;
+    int depth = 0;
+    double val = amount;
+    while (val > 1024) {
+        val /= 1024;
+        depth++;
+    }
+
+    const char* unit;
+    switch(depth) {
+      case 0:
+      unit = "bytes";
+      break;
+      case 1:
+      unit = "KB";
+      break;
+      case 2:
+      unit = "MB";
+      break;
+      case 3:
+      unit = "GB";
+      break;
+  }
+
+  stream << val << " " << unit;
+  return stream.str();
+}
+
 /* static */ void
 GfxTexturesReporter::UpdateAmount(MemoryUse action, size_t amount)
 {
     if (action == MemoryFreed) {
         MOZ_RELEASE_ASSERT(amount <= sAmount);
         sAmount -= amount;
+
+        if (gfxPrefs::GfxLoggingTextureUsageEnabled()) {
+            printf_stderr("Current texture usage: %s\n", FormatBytes(sAmount).c_str());
+        }
     } else {
         sAmount += amount;
         if (sAmount > sPeakAmount) {
             sPeakAmount.exchange(sAmount);
+            if (gfxPrefs::GfxLoggingPeakTextureUsageEnabled()) {
+                printf_stderr("Peak texture usage: %s\n", FormatBytes(sPeakAmount).c_str());
+            }
         }
     }
 
 #ifdef MOZ_CRASHREPORTER
     CrashReporter::AnnotateTexturesSize(sAmount);
 #endif
 }
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -257,16 +257,18 @@ private:
   DECL_GFX_PREF(Once, "gfx.e10s.hide-plugins-for-scroll",      HidePluginsForScroll, bool, true);
   DECL_GFX_PREF(Once, "gfx.font_rendering.directwrite.force-enabled", DirectWriteFontRenderingForceEnabled, bool, false);
   DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels",     GrallocFenceWithReadPixels, bool, false);
   DECL_GFX_PREF(Live, "gfx.layerscope.enabled",                LayerScopeEnabled, bool, false);
   DECL_GFX_PREF(Live, "gfx.layerscope.port",                   LayerScopePort, int32_t, 23456);
   // Note that        "gfx.logging.level" is defined in Logging.h
   DECL_GFX_PREF(Once, "gfx.logging.crash.length",              GfxLoggingCrashLength, uint32_t, 16);
   // The maximums here are quite conservative, we can tighten them if problems show up.
+  DECL_GFX_PREF(Once, "gfx.logging.texture-usage.enabled",     GfxLoggingTextureUsageEnabled, bool, false);
+  DECL_GFX_PREF(Once, "gfx.logging.peak-texture-usage.enabled",GfxLoggingPeakTextureUsageEnabled, bool, false);
   DECL_GFX_PREF(Once, "gfx.max-alloc-size",                    MaxAllocSize, int32_t, (int32_t)500000000);
   DECL_GFX_PREF(Once, "gfx.max-texture-size",                  MaxTextureSize, int32_t, (int32_t)32767);
   DECL_GFX_PREF(Live, "gfx.partialpresent.force",              PartialPresent, int32_t, 0);
   DECL_GFX_PREF(Live, "gfx.perf-warnings.enabled",             PerfWarnings, bool, false);
   DECL_GFX_PREF(Live, "gfx.SurfaceTexture.detach.enabled",     SurfaceTextureDetachEnabled, bool, true);
   DECL_GFX_PREF(Live, "gfx.testing.device-reset",              DeviceResetForTesting, int32_t, 0);
   DECL_GFX_PREF(Live, "gfx.testing.device-fail",               DeviceFailForTesting, bool, false);
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -725,16 +725,19 @@ pref("gfx.content.azure.backends", "cair
 pref("gfx.content.azure.backends", "cairo");
 #endif
 
 pref("gfx.work-around-driver-bugs", true);
 pref("gfx.prefer-mesa-llvmpipe", false);
 
 pref("gfx.draw-color-bars", false);
 
+pref("gfx.logging.texture-usage.enabled", false);
+pref("gfx.logging.peak-texture-usage.enabled", false);
+
 pref("accessibility.browsewithcaret", false);
 pref("accessibility.warn_on_browsewithcaret", true);
 
 pref("accessibility.browsewithcaret_shortcut.enabled", true);
 
 #ifndef XP_MACOSX
 // Tab focus model bit field:
 // 1 focuses text controls, 2 focuses other form elements, 4 adds links.