Bug 1203427 (part 1) - Add nsExpirationTracker::mName. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 09 Sep 2015 21:07:07 -0700
changeset 262977 96dba490e51be5faff3c73ee1ea6411b577f877b
parent 262976 65cec42b60faaca7166b1db707d1c4f98d3f8e88
child 262978 00eeeae71d651c4bfcc0ac0e55b0f95ca8006013
push id15222
push usercbook@mozilla.com
push dateThu, 17 Sep 2015 13:02:20 +0000
treeherderfx-team@3d5f54bd4dfe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1203427
milestone43.0a1
Bug 1203427 (part 1) - Add nsExpirationTracker::mName. r=froydnj. There are many sub-classes of nsExpirationTracker. In order to distinguish them nicely in the logging of timer firings, it's necessary to manually name each one. (This wouldn't be necessary if there was a way to stringify template parameters, but there isn't.)
docshell/shistory/nsSHEntryShared.cpp
dom/base/nsDocument.cpp
dom/canvas/CanvasImageCache.cpp
gfx/layers/client/TiledContentClient.cpp
gfx/tests/gtest/gfxWordCacheTest.cpp
gfx/thebes/gfxBlur.cpp
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxGradientCache.cpp
image/SurfaceCache.cpp
image/imgLoader.cpp
layout/base/ActiveLayerTracker.cpp
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsTextFrame.cpp
layout/style/RuleProcessorCache.h
xpcom/ds/nsExpirationTracker.h
xpcom/tests/gtest/TestExpirationTracker.cpp
--- a/docshell/shistory/nsSHEntryShared.cpp
+++ b/docshell/shistory/nsSHEntryShared.cpp
@@ -33,17 +33,17 @@ uint64_t gSHEntrySharedID = 0;
 // Default this to time out unused content viewers after 30 minutes
 #define CONTENT_VIEWER_TIMEOUT_SECONDS_DEFAULT (30 * 60)
 
 typedef nsExpirationTracker<nsSHEntryShared, 3> HistoryTrackerBase;
 class HistoryTracker final : public HistoryTrackerBase
 {
 public:
   explicit HistoryTracker(uint32_t aTimeout)
-    : HistoryTrackerBase(1000 * aTimeout / 2)
+    : HistoryTrackerBase(1000 * aTimeout / 2, "HistoryTracker")
   {
   }
 
 protected:
   virtual void NotifyExpired(nsSHEntryShared* aObj)
   {
     RemoveObject(aObj);
     aObj->Expire();
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1424,17 +1424,18 @@ nsDOMStyleSheetSetList::EnsureFresh()
     if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) {
       return;
     }
   }
 }
 
 // ==================================================================
 nsIDocument::SelectorCache::SelectorCache()
-  : nsExpirationTracker<SelectorCacheKey, 4>(1000) { }
+  : nsExpirationTracker<SelectorCacheKey, 4>(1000, "nsIDocument::SelectorCache")
+{ }
 
 // CacheList takes ownership of aSelectorList.
 void nsIDocument::SelectorCache::CacheList(const nsAString& aSelector,
                                            nsCSSSelectorList* aSelectorList)
 {
   SelectorCacheKey* key = new SelectorCacheKey(aSelector);
   mTable.Put(key->mKey, aSelectorList);
   AddObject(key);
--- a/dom/canvas/CanvasImageCache.cpp
+++ b/dom/canvas/CanvasImageCache.cpp
@@ -211,17 +211,17 @@ class CanvasImageCacheShutdownObserver f
 {
   ~CanvasImageCacheShutdownObserver() {}
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 };
 
 ImageCache::ImageCache()
-  : nsExpirationTracker<ImageCacheEntryData,4>(GENERATION_MS)
+  : nsExpirationTracker<ImageCacheEntryData,4>(GENERATION_MS, "ImageCache")
   , mTotal(0)
 {
   if (!sPrefsInitialized) {
     sPrefsInitialized = true;
     Preferences::AddIntVarCache(&sCanvasImageCacheLimit, "canvas.image.cache.limit", 0);
   }
   mImageCacheObserver = new ImageCacheObserver(this);
   MOZ_RELEASE_ASSERT(mImageCacheObserver, "Can't alloc ImageCacheObserver");
--- a/gfx/layers/client/TiledContentClient.cpp
+++ b/gfx/layers/client/TiledContentClient.cpp
@@ -437,17 +437,17 @@ gfxShmSharedReadLock::GetReadCount() {
   }
   ShmReadLockInfo* info = GetShmReadLockInfoPtr();
   return info->readCount;
 }
 
 class TileExpiry final : public nsExpirationTracker<TileClient, 3>
 {
   public:
-    TileExpiry() : nsExpirationTracker<TileClient, 3>(1000) {}
+    TileExpiry() : nsExpirationTracker<TileClient, 3>(1000, "TileExpiry") {}
 
     static void AddTile(TileClient* aTile)
     {
       if (!sTileExpiry) {
         sTileExpiry = MakeUnique<TileExpiry>();
       }
 
       sTileExpiry->AddObject(aTile);
--- a/gfx/tests/gtest/gfxWordCacheTest.cpp
+++ b/gfx/tests/gtest/gfxWordCacheTest.cpp
@@ -31,17 +31,19 @@ static FrameTextRunCache *gTextRuns = nu
 
 /*
  * Cache textruns and expire them after 3*10 seconds of no use.
  */
 class FrameTextRunCache final : public nsExpirationTracker<gfxTextRun,3> {
 public:
   enum { TIMEOUT_SECONDS = 10 };
   FrameTextRunCache()
-    : nsExpirationTracker<gfxTextRun,3>(TIMEOUT_SECONDS*1000) {}
+    : nsExpirationTracker<gfxTextRun,3>(TIMEOUT_SECONDS * 1000,
+                                        "FrameTextRunCache")
+  {}
   ~FrameTextRunCache() {
     AgeAllGenerations();
   }
 
   void RemoveFromCache(gfxTextRun* aTextRun) {
     if (aTextRun->GetExpirationState()->IsTracked()) {
       RemoveObject(aTextRun);
     }
--- a/gfx/thebes/gfxBlur.cpp
+++ b/gfx/thebes/gfxBlur.cpp
@@ -259,17 +259,17 @@ struct BlurCacheData {
  * SourceSurfaces used to draw the blurs.
  *
  * An entry stays in the cache as long as it is used often.
  */
 class BlurCache final : public nsExpirationTracker<BlurCacheData,4>
 {
   public:
     BlurCache()
-      : nsExpirationTracker<BlurCacheData, 4>(GENERATION_MS)
+      : nsExpirationTracker<BlurCacheData, 4>(GENERATION_MS, "BlurCache")
     {
     }
 
     virtual void NotifyExpired(BlurCacheData* aObject)
     {
       RemoveObject(aObject);
       mHashEntries.Remove(aObject->mKey);
     }
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -160,17 +160,18 @@ gfxFontCache::Shutdown()
     printf("Number of simple glyph extents eagerly requested=%d\n", gGlyphExtentsSetupEagerSimple);
     printf("Number of tight glyph extents eagerly requested=%d\n", gGlyphExtentsSetupEagerTight);
     printf("Number of tight glyph extents lazily requested=%d\n", gGlyphExtentsSetupLazyTight);
     printf("Number of simple glyph extent setups that fell back to tight=%d\n", gGlyphExtentsSetupFallBackToTight);
 #endif
 }
 
 gfxFontCache::gfxFontCache()
-    : nsExpirationTracker<gfxFont,3>(FONT_TIMEOUT_SECONDS * 1000)
+    : nsExpirationTracker<gfxFont,3>(FONT_TIMEOUT_SECONDS * 1000,
+                                     "gfxFontCache")
 {
     nsCOMPtr<nsIObserverService> obs = GetObserverService();
     if (obs) {
         obs->AddObserver(new Observer, "memory-pressure", false);
     }
 
 #ifndef RELEASE_BUILD
     // Currently disabled for release builds, due to unexplained crashes
--- a/gfx/thebes/gfxGradientCache.cpp
+++ b/gfx/thebes/gfxGradientCache.cpp
@@ -117,17 +117,18 @@ 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 final : public nsExpirationTracker<GradientCacheData,4>
 {
   public:
     GradientCache()
-      : nsExpirationTracker<GradientCacheData, 4>(MAX_GENERATION_MS)
+      : nsExpirationTracker<GradientCacheData,4>(MAX_GENERATION_MS,
+                                                 "GradientCache")
     {
       srand(time(nullptr));
       mTimerPeriod = rand() % MAX_GENERATION_MS + 1;
       Telemetry::Accumulate(Telemetry::GRADIENT_RETENTION_TIME, mTimerPeriod);
     }
 
     virtual void NotifyExpired(GradientCacheData* aObject)
     {
--- a/image/SurfaceCache.cpp
+++ b/image/SurfaceCache.cpp
@@ -936,17 +936,18 @@ private:
     } else {
       mExpirationTracker.MarkUsed(aSurface);
     }
   }
 
   struct SurfaceTracker : public nsExpirationTracker<CachedSurface, 2>
   {
     explicit SurfaceTracker(uint32_t aSurfaceCacheExpirationTimeMS)
-      : nsExpirationTracker<CachedSurface, 2>(aSurfaceCacheExpirationTimeMS)
+      : nsExpirationTracker<CachedSurface, 2>(aSurfaceCacheExpirationTimeMS,
+                                              "SurfaceTracker")
     { }
 
   protected:
     virtual void NotifyExpired(CachedSurface* aSurface) override
     {
       if (sInstance) {
         MutexAutoLock lock(sInstance->GetMutex());
         sInstance->Remove(aSurface);
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1064,17 +1064,18 @@ class imgCacheExpirationTracker final
 public:
   imgCacheExpirationTracker();
 
 protected:
   void NotifyExpired(imgCacheEntry* entry);
 };
 
 imgCacheExpirationTracker::imgCacheExpirationTracker()
- : nsExpirationTracker<imgCacheEntry, 3>(TIMEOUT_SECONDS * 1000)
+ : nsExpirationTracker<imgCacheEntry, 3>(TIMEOUT_SECONDS * 1000,
+                                         "imgCacheExpirationTracker")
 { }
 
 void
 imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
 {
   // Hold on to a reference to this entry, because the expiration tracker
   // mechanism doesn't.
   nsRefPtr<imgCacheEntry> kungFuDeathGrip(entry);
--- a/layout/base/ActiveLayerTracker.cpp
+++ b/layout/base/ActiveLayerTracker.cpp
@@ -95,17 +95,19 @@ public:
   bool mContentActive;
 };
 
 class LayerActivityTracker final : public nsExpirationTracker<LayerActivity,4> {
 public:
   // 75-100ms is a good timeout period. We use 4 generations of 25ms each.
   enum { GENERATION_MS = 100 };
   LayerActivityTracker()
-    : nsExpirationTracker<LayerActivity,4>(GENERATION_MS) {}
+    : nsExpirationTracker<LayerActivity,4>(GENERATION_MS,
+                                           "LayerActivityTracker")
+  {}
   ~LayerActivityTracker() {
     AgeAllGenerations();
   }
 
   virtual void NotifyExpired(LayerActivity* aObject);
 };
 
 static LayerActivityTracker* gLayerActivityTracker = nullptr;
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -1777,17 +1777,19 @@ ScrollFrameHelper::IsSmoothScrollingEnab
 }
 
 class ScrollFrameActivityTracker final : public nsExpirationTracker<ScrollFrameHelper,4> {
 public:
   // Wait for 3-4s between scrolls before we remove our layers.
   // That's 4 generations of 1s each.
   enum { TIMEOUT_MS = 1000 };
   ScrollFrameActivityTracker()
-    : nsExpirationTracker<ScrollFrameHelper,4>(TIMEOUT_MS) {}
+    : nsExpirationTracker<ScrollFrameHelper,4>(TIMEOUT_MS,
+                                               "ScrollFrameActivityTracker")
+  {}
   ~ScrollFrameActivityTracker() {
     AgeAllGenerations();
   }
 
   virtual void NotifyExpired(ScrollFrameHelper *aObject) {
     RemoveObject(aObject);
     aObject->MarkNotRecentlyScrolled();
   }
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -551,17 +551,19 @@ static FrameTextRunCache *gTextRuns = nu
 
 /*
  * Cache textruns and expire them after 3*10 seconds of no use.
  */
 class FrameTextRunCache final : public nsExpirationTracker<gfxTextRun,3> {
 public:
   enum { TIMEOUT_SECONDS = 10 };
   FrameTextRunCache()
-      : nsExpirationTracker<gfxTextRun,3>(TIMEOUT_SECONDS*1000) {}
+    : nsExpirationTracker<gfxTextRun,3>(TIMEOUT_SECONDS * 1000,
+                                        "FrameTextRunCache")
+  {}
   ~FrameTextRunCache() {
     AgeAllGenerations();
   }
 
   void RemoveFromCache(gfxTextRun* aTextRun) {
     if (aTextRun->GetExpirationState()->IsTracked()) {
       RemoveObject(aTextRun);
     }
--- a/layout/style/RuleProcessorCache.h
+++ b/layout/style/RuleProcessorCache.h
@@ -66,17 +66,18 @@ public:
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
 
 private:
   class ExpirationTracker : public nsExpirationTracker<nsCSSRuleProcessor,3>
   {
   public:
     explicit ExpirationTracker(RuleProcessorCache* aCache)
-      : nsExpirationTracker<nsCSSRuleProcessor,3>(10000)
+      : nsExpirationTracker<nsCSSRuleProcessor,3>(
+          10000, "RuleProcessorCache::ExpirationTracker")
       , mCache(aCache) {}
 
     void RemoveObjectIfTracked(nsCSSRuleProcessor* aRuleProcessor);
 
     virtual void NotifyExpired(nsCSSRuleProcessor* aRuleProcessor) override {
       mCache->RemoveRuleProcessor(aRuleProcessor);
     }
 
--- a/xpcom/ds/nsExpirationTracker.h
+++ b/xpcom/ds/nsExpirationTracker.h
@@ -77,20 +77,21 @@ class nsExpirationTracker
 public:
   /**
    * Initialize the tracker.
    * @param aTimerPeriod the timer period in milliseconds. The guarantees
    * provided by the tracker are defined in terms of this period. If the
    * period is zero, then we don't use a timer and rely on someone calling
    * AgeOneGeneration explicitly.
    */
-  explicit nsExpirationTracker(uint32_t aTimerPeriod)
+  explicit nsExpirationTracker(uint32_t aTimerPeriod, const char* aName)
     : mTimerPeriod(aTimerPeriod)
     , mNewestGeneration(0)
     , mInAgeOneGeneration(false)
+    , mName(aName)
   {
     static_assert(K >= 2 && K <= nsExpirationState::NOT_TRACKED,
                   "Unsupported number of generations (must be 2 <= K <= 15)");
     mObserver = new ExpirationTrackerObserver();
     mObserver->Init(this);
   }
   ~nsExpirationTracker()
   {
@@ -303,16 +304,17 @@ protected:
 private:
   class ExpirationTrackerObserver;
   nsRefPtr<ExpirationTrackerObserver> mObserver;
   nsTArray<T*>       mGenerations[K];
   nsCOMPtr<nsITimer> mTimer;
   uint32_t           mTimerPeriod;
   uint32_t           mNewestGeneration;
   bool               mInAgeOneGeneration;
+  const char* const  mName;   // Used for timer firing profiling.
 
   /**
    * Whenever "memory-pressure" is observed, it calls AgeAllGenerations()
    * to minimize memory usage.
    */
   class ExpirationTrackerObserver final : public nsIObserver
   {
   public:
--- a/xpcom/tests/gtest/TestExpirationTracker.cpp
+++ b/xpcom/tests/gtest/TestExpirationTracker.cpp
@@ -38,17 +38,17 @@ static uint32_t periodMS = 100;
 static uint32_t ops = 1000;
 static uint32_t iterations = 2;
 static bool logging = 0;
 static uint32_t sleepPeriodMS = 50;
 static uint32_t slackMS = 30; // allow this much error
 
 template <uint32_t K> class Tracker : public nsExpirationTracker<Object,K> {
 public:
-  Tracker() : nsExpirationTracker<Object,K>(periodMS) {
+  Tracker() : nsExpirationTracker<Object,K>(periodMS, "Tracker") {
     Object* obj = new Object();
     mUniverse.AppendElement(obj);
     LogAction(obj, "Created");
   }
 
   nsTArray<nsAutoArrayPtr<Object> > mUniverse;
 
   void LogAction(Object* aObj, const char* aAction) {