Add a way to monitor cache hits and misses for deferred decoding.
Adds a new flag to bench_pictures in order to do this. Also fix
a warning.
Review URL: https://codereview.chromium.org/12393046
git-svn-id: http://skia.googlecode.com/svn/trunk@7965 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index ffcab74..0c7644f 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -44,6 +44,9 @@
"times for drawing the whole page. Requires tiled rendering.");
DEFINE_string(timers, "", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time"
" for each picture.");
+DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and "
+ "LAZY_CACHE_STATS set to true. Report percentage of cache hits when using deferred "
+ "image decoding.");
static char const * const gFilterTypes[] = {
"paint",
@@ -140,6 +143,7 @@
#include "SkData.h"
#include "SkLruImageCache.h"
+#include "SkLazyPixelRef.h"
static SkLruImageCache gLruImageCache(1024*1024);
@@ -152,6 +156,11 @@
return factory.installPixelRef(data, bitmap);
}
+#if LAZY_CACHE_STATS
+static int32_t gTotalCacheHits;
+static int32_t gTotalCacheMisses;
+#endif
+
static bool run_single_benchmark(const SkString& inputPath,
sk_tools::PictureBenchmark& benchmark) {
SkFILEStream inputStream;
@@ -189,6 +198,18 @@
gLogger.logProgress(result);
benchmark.run(picture);
+
+#if LAZY_CACHE_STATS
+ if (FLAGS_trackDeferredCaching) {
+ int32_t cacheHits = SkLazyPixelRef::GetCacheHits();
+ int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses();
+ SkLazyPixelRef::ResetCacheStats();
+ SkDebugf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
+ gTotalCacheHits += cacheHits;
+ gTotalCacheMisses += cacheMisses;
+ }
+#endif
+
return true;
}
@@ -200,12 +221,12 @@
const char* filters = FLAGS_filter[0];
const char* colon = strchr(filters, ':');
if (colon) {
- int type = -1;
+ int32_t type = -1;
size_t typeLen = colon - filters;
for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
if (typeLen == strlen(gFilterTypes[tIndex])
&& !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
- type = tIndex;
+ type = SkToS32(tIndex);
break;
}
}
@@ -396,6 +417,12 @@
gLogger.logError(err);
return 1;
}
+#if LAZY_CACHE_STATS
+ if (FLAGS_trackDeferredCaching) {
+ SkDebugf("Total cache hit rate: %f\n",
+ (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
+ }
+#endif
return 0;
}