Added resource cache debug output to help track changes

http://codereview.appspot.com/6463079/



git-svn-id: http://skia.googlecode.com/svn/trunk@5220 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 07e57a4..feee33d 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -1148,7 +1148,22 @@
     for (int i = 0; i < failedTests.count(); ++i) {
         SkDebugf("\t\t%s\n", failedTests[i].c_str());
     }
+
 #if SK_SUPPORT_GPU
+
+#if SK_DEBUG
+    for (int i = 0; i < configs.count(); i++) {
+        ConfigData config = gRec[configs[i]];
+
+        if (kGPU_Backend == config.fBackend) {
+            GrContext* gr = grFactory->get(config.fGLContextType);
+
+            SkDebugf("config: %s %x\n", config.fName, gr);
+            gr->printCacheStats();
+        }
+    }
+#endif
+
     delete grFactory;
 #endif
     SkGraphics::Term();
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index dbb404f..077493f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -752,6 +752,10 @@
                                     bool antiAlias,
                                     bool allowSW);
 
+#ifdef GR_DEBUG
+    void printCacheStats() const;
+#endif
+
 private:
     // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer.
     enum BufferedDraw {
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 49d220f..b517a54 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1899,3 +1899,8 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+#if GR_DEBUG
+void GrContext::printCacheStats() const {
+    fTextureCache->printStats();
+}
+#endif
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 982d45e..7e0b892 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -38,11 +38,19 @@
 GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) :
         fMaxCount(maxCount),
         fMaxBytes(maxBytes) {
-    fEntryCount          = 0;
-    fUnlockedEntryCount  = 0;
-    fEntryBytes          = 0;
-    fClientDetachedCount = 0;
-    fClientDetachedBytes = 0;
+#if GR_DEBUG
+    fHighWaterEntryCount          = 0;
+    fHighWaterUnlockedEntryCount  = 0;
+    fHighWaterEntryBytes          = 0;
+    fHighWaterClientDetachedCount = 0;
+    fHighWaterClientDetachedBytes = 0;
+#endif
+
+    fEntryCount                   = 0;
+    fUnlockedEntryCount           = 0;
+    fEntryBytes                   = 0;
+    fClientDetachedCount          = 0;
+    fClientDetachedBytes          = 0;
 
     fHead = fTail = NULL;
     fPurging = false;
@@ -100,6 +108,16 @@
     if (clientDetach) {
         fClientDetachedCount += 1;
         fClientDetachedBytes += entry->resource()->sizeInBytes();
+
+#if GR_DEBUG
+        if (fHighWaterClientDetachedCount < fClientDetachedCount) {
+            fHighWaterClientDetachedCount = fClientDetachedCount;
+        }
+        if (fHighWaterClientDetachedBytes < fClientDetachedBytes) {
+            fHighWaterClientDetachedBytes = fClientDetachedBytes;
+        }
+#endif
+
     } else {
         fEntryCount -= 1;
         fEntryBytes -= entry->resource()->sizeInBytes();
@@ -119,6 +137,11 @@
     }
     if (!entry->isLocked()) {
         ++fUnlockedEntryCount;
+#if GR_DEBUG
+        if (fHighWaterUnlockedEntryCount < fUnlockedEntryCount) {
+            fHighWaterUnlockedEntryCount = fUnlockedEntryCount;
+        }
+#endif
     }
 
     // update our stats
@@ -128,6 +151,15 @@
     } else {
         fEntryCount += 1;
         fEntryBytes += entry->resource()->sizeInBytes();
+
+#if GR_DEBUG
+        if (fHighWaterEntryCount < fEntryCount) {
+            fHighWaterEntryCount = fEntryCount;
+        }
+        if (fHighWaterEntryBytes < fEntryBytes) {
+            fHighWaterEntryBytes = fEntryBytes;
+        }
+#endif
     }
 }
 
@@ -269,6 +301,11 @@
     entry->unlock();
     if (!entry->isLocked()) {
         ++fUnlockedEntryCount;
+#if GR_DEBUG
+        if (fHighWaterUnlockedEntryCount < fUnlockedEntryCount) {
+            fHighWaterUnlockedEntryCount = fUnlockedEntryCount;
+        }
+#endif
     }
     this->purgeAsNeeded();
 }
@@ -409,4 +446,19 @@
         GrAssert(1 == matches);
     }
 }
+
+void GrResourceCache::printStats() const {
+    SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
+    SkDebugf("\t\tEntry Count: current %d high %d\n",
+                fEntryCount, fHighWaterEntryCount);
+    SkDebugf("\t\tUnlocked Entry Count: current %d high %d\n",
+                fUnlockedEntryCount, fHighWaterUnlockedEntryCount);
+    SkDebugf("\t\tEntry Bytes: current %d high %d\n",
+                fEntryBytes, fHighWaterEntryBytes);
+    SkDebugf("\t\tDetached Entry Count: current %d high %d\n",
+                fClientDetachedCount, fHighWaterClientDetachedCount);
+    SkDebugf("\t\tDetached Bytes: current %d high %d\n",
+                fClientDetachedBytes, fHighWaterClientDetachedBytes);
+}
+
 #endif
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index d708e0a..838b3b8 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -280,6 +280,7 @@
 
 #if GR_DEBUG
     void validate() const;
+    void printStats() const;
 #else
     void validate() const {}
 #endif
@@ -301,6 +302,14 @@
     size_t fMaxBytes;
 
     // our current stats, related to our budget
+#if GR_DEBUG
+    int fHighWaterEntryCount;
+    int fHighWaterUnlockedEntryCount;
+    size_t fHighWaterEntryBytes;
+    int fHighWaterClientDetachedCount;
+    size_t fHighWaterClientDetachedBytes;
+#endif
+
     int fEntryCount;
     int fUnlockedEntryCount;
     size_t fEntryBytes;