Bug 761393 - Add telemetry probes to guess the retention time. r=taras
authorPaul Adenot <paul@paul.cx>
Sun, 26 Aug 2012 21:12:36 -0700
changeset 109917 1b3fa4309f3145d736a0a75762d9a1da7382d2c1
parent 109916 dd28317d64d4715d9b36e5a5f0be31f4cfcef25c
child 109918 38ca4f43a4fd6a3f33bf055895ab1965bb3f528c
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs761393
milestone18.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 761393 - Add telemetry probes to guess the retention time. r=taras
layout/base/nsCSSRendering.cpp
toolkit/components/telemetry/Histograms.json
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -43,16 +43,18 @@
 #include "nsSVGEffects.h"
 #include "nsSVGIntegrationUtils.h"
 #include "gfxDrawable.h"
 #include "sampler.h"
 #include "nsCSSRenderingBorders.h"
 #include "mozilla/css/ImageLoader.h"
 #include "ImageContainer.h"
 #include "mozilla/HashFunctions.h"
+#include "mozilla/Telemetry.h"
+#include <ctime>
 
 using namespace mozilla;
 using namespace mozilla::css;
 
 // To avoid storing this data on nsInlineFrame (bloat) and to avoid
 // recalculating this for each frame in a continuation (perf), hold
 // a cache of various coordinate information that we need in order
 // to paint inline backgrounds.
@@ -345,22 +347,23 @@ struct GradientCacheData {
  *
  * An entry stays in the cache as long as it is used often. As long as a cache
  * entry is in the cache, all the references it has are guaranteed to be valid:
  * the nsStyleRect for the key, the gfxPattern for the value.
  */
 class GradientCache MOZ_FINAL : public nsExpirationTracker<GradientCacheData,4>
 {
   public:
-    enum { MAX_GENERATION_MS = 10000};
-
     GradientCache()
       : nsExpirationTracker<GradientCacheData, 4>(MAX_GENERATION_MS)
     {
       mHashEntries.Init();
+      srand(time(nullptr));
+      mTimerPeriod = rand() % MAX_GENERATION_MS + 1;
+      Telemetry::Accumulate(Telemetry::GRADIENT_RETENTION_TIME, mTimerPeriod);
     }
 
     virtual void NotifyExpired(GradientCacheData* aObject)
     {
       // This will free the gfxPattern.
       RemoveObject(aObject);
       mHashEntries.Remove(aObject->mKey);
     }
@@ -402,16 +405,18 @@ class GradientCache MOZ_FINAL : public n
         // anyway, we probably don't want to retain things.
         return false;
       }
       mHashEntries.Put(GradientCacheKey(aKey, aGradientSize), aValue);
       return true;
     }
 
   protected:
+    uint32_t mTimerPeriod;
+    static const uint32_t MAX_GENERATION_MS = 10000;
     /**
      * FIXME use nsTHashtable to avoid duplicating the GradientCacheKey.
      * https://bugzilla.mozilla.org/show_bug.cgi?id=761393#c47
      */
     nsClassHashtable<GradientCacheKey, GradientCacheData> mHashEntries;
 };
 
 /* Local functions */
@@ -1992,16 +1997,17 @@ void
 nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
                               nsRenderingContext& aRenderingContext,
                               nsStyleGradient* aGradient,
                               const nsRect& aDirtyRect,
                               const nsRect& aOneCellArea,
                               const nsRect& aFillArea)
 {
   SAMPLE_LABEL("nsCSSRendering", "PaintGradient");
+  Telemetry::AutoTimer<Telemetry::GRADIENT_DURATION, Telemetry::Microsecond> gradientTimer;
   if (aOneCellArea.IsEmpty())
     return;
 
   gfxContext *ctx = aRenderingContext.ThebesContext();
   nscoord appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
   gfxRect oneCellArea =
     nsLayoutUtils::RectToGfxRect(aOneCellArea, appUnitsPerPixel);
 
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -400,16 +400,28 @@
     "description": "System font fallback, first call (ms)"
   },
   "SYSTEM_FONT_FALLBACK_SCRIPT": {
     "kind": "linear",
     "high": "110",
     "n_buckets": 111,
     "description": "System font fallback script"
   },
+  "GRADIENT_DURATION": {
+    "kind": "exponential",
+    "high":"50000000",
+    "n_buckets":20,
+    "description": "Gradient generation time (us)"
+  },
+  "GRADIENT_RETENTION_TIME": {
+    "kind": "linear",
+    "high": "10000",
+    "n_buckets":20,
+    "description": "Maximum retention time for the gradient cache. (ms)"
+  },
   "STARTUP_CACHE_AGE_HOURS": {
     "kind": "exponential",
     "high": "3000",
     "n_buckets": 20,
     "description": "Startup cache age (hours)"
   },
   "WORD_CACHE_HITS": {
     "kind": "exponential",