Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: tools/bench_pictures_main.cpp

Issue 12393046: Add a way to monitor cache hits and misses for deferred decoding. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/lazy/SkLazyPixelRef.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "BenchTimer.h" 8 #include "BenchTimer.h"
9 #include "CopyTilesRenderer.h" 9 #include "CopyTilesRenderer.h"
10 #include "PictureBenchmark.h" 10 #include "PictureBenchmark.h"
(...skipping 26 matching lines...) Expand all
37 DEFINE_string(logFile, "", "Destination for writing log output, in addition to s tdout."); 37 DEFINE_string(logFile, "", "Destination for writing log output, in addition to s tdout.");
38 DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean."); 38 DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean.");
39 DEFINE_bool(min, false, "Print the minimum times (instead of average)."); 39 DEFINE_bool(min, false, "Print the minimum times (instead of average).");
40 DECLARE_int32(multi); 40 DECLARE_int32(multi);
41 DECLARE_string(r); 41 DECLARE_string(r);
42 DEFINE_int32(repeat, 1, "Set the number of times to repeat each test."); 42 DEFINE_int32(repeat, 1, "Set the number of times to repeat each test.");
43 DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual til es, rather than " 43 DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual til es, rather than "
44 "times for drawing the whole page. Requires tiled rendering."); 44 "times for drawing the whole page. Requires tiled rendering.");
45 DEFINE_string(timers, "", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or t runcated cpu time" 45 DEFINE_string(timers, "", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or t runcated cpu time"
46 " for each picture."); 46 " for each picture.");
47 DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecod ing and "
48 "LAZY_CACHE_STATS set to true. Report percentage of cache hits when using deferred "
49 "image decoding.");
47 50
48 static char const * const gFilterTypes[] = { 51 static char const * const gFilterTypes[] = {
49 "paint", 52 "paint",
50 "point", 53 "point",
51 "line", 54 "line",
52 "bitmap", 55 "bitmap",
53 "rect", 56 "rect",
54 "oval", 57 "oval",
55 "path", 58 "path",
56 "text", 59 "text",
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 136 }
134 if (index < kFilterFlagsCount - 1) { 137 if (index < kFilterFlagsCount - 1) {
135 result += " | "; 138 result += " | ";
136 } 139 }
137 } 140 }
138 return result; 141 return result;
139 } 142 }
140 143
141 #include "SkData.h" 144 #include "SkData.h"
142 #include "SkLruImageCache.h" 145 #include "SkLruImageCache.h"
146 #include "SkLazyPixelRef.h"
143 147
144 static SkLruImageCache gLruImageCache(1024*1024); 148 static SkLruImageCache gLruImageCache(1024*1024);
145 149
146 static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap ) { 150 static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap ) {
147 void* copiedBuffer = sk_malloc_throw(size); 151 void* copiedBuffer = sk_malloc_throw(size);
148 memcpy(copiedBuffer, buffer, size); 152 memcpy(copiedBuffer, buffer, size);
149 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size)); 153 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size));
150 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); 154 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget);
151 factory.setImageCache(&gLruImageCache); 155 factory.setImageCache(&gLruImageCache);
152 return factory.installPixelRef(data, bitmap); 156 return factory.installPixelRef(data, bitmap);
153 } 157 }
154 158
159 #if LAZY_CACHE_STATS
160 static int32_t gTotalCacheHits;
161 static int32_t gTotalCacheMisses;
162 #endif
163
155 static bool run_single_benchmark(const SkString& inputPath, 164 static bool run_single_benchmark(const SkString& inputPath,
156 sk_tools::PictureBenchmark& benchmark) { 165 sk_tools::PictureBenchmark& benchmark) {
157 SkFILEStream inputStream; 166 SkFILEStream inputStream;
158 167
159 inputStream.setPath(inputPath.c_str()); 168 inputStream.setPath(inputPath.c_str());
160 if (!inputStream.isValid()) { 169 if (!inputStream.isValid()) {
161 SkString err; 170 SkString err;
162 err.printf("Could not open file %s\n", inputPath.c_str()); 171 err.printf("Could not open file %s\n", inputPath.c_str());
163 gLogger.logError(err); 172 gLogger.logError(err);
164 return false; 173 return false;
(...skipping 17 matching lines...) Expand all
182 191
183 SkString filename; 192 SkString filename;
184 sk_tools::get_basename(&filename, inputPath); 193 sk_tools::get_basename(&filename, inputPath);
185 194
186 SkString result; 195 SkString result;
187 result.printf("running bench [%i %i] %s ", picture->width(), picture->height (), 196 result.printf("running bench [%i %i] %s ", picture->width(), picture->height (),
188 filename.c_str()); 197 filename.c_str());
189 gLogger.logProgress(result); 198 gLogger.logProgress(result);
190 199
191 benchmark.run(picture); 200 benchmark.run(picture);
201
202 #if LAZY_CACHE_STATS
203 if (FLAGS_trackDeferredCaching) {
204 int32_t cacheHits = SkLazyPixelRef::GetCacheHits();
205 int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses();
206 SkLazyPixelRef::ResetCacheStats();
207 SkDebugf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cache Misses));
208 gTotalCacheHits += cacheHits;
209 gTotalCacheMisses += cacheMisses;
210 }
211 #endif
212
192 return true; 213 return true;
193 } 214 }
194 215
195 static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) { 216 static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
196 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCo unt]; 217 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCo unt];
197 sk_bzero(drawFilters, sizeof(drawFilters)); 218 sk_bzero(drawFilters, sizeof(drawFilters));
198 219
199 if (FLAGS_filter.count() > 0) { 220 if (FLAGS_filter.count() > 0) {
200 const char* filters = FLAGS_filter[0]; 221 const char* filters = FLAGS_filter[0];
201 const char* colon = strchr(filters, ':'); 222 const char* colon = strchr(filters, ':');
202 if (colon) { 223 if (colon) {
203 int type = -1; 224 int32_t type = -1;
204 size_t typeLen = colon - filters; 225 size_t typeLen = colon - filters;
205 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) { 226 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
206 if (typeLen == strlen(gFilterTypes[tIndex]) 227 if (typeLen == strlen(gFilterTypes[tIndex])
207 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) { 228 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
208 type = tIndex; 229 type = SkToS32(tIndex);
209 break; 230 break;
210 } 231 }
211 } 232 }
212 if (type < 0) { 233 if (type < 0) {
213 SkString err; 234 SkString err;
214 err.printf("Unknown type for --filter %s\n", filters); 235 err.printf("Unknown type for --filter %s\n", filters);
215 gLogger.logError(err); 236 gLogger.logError(err);
216 exit(-1); 237 exit(-1);
217 } 238 }
218 int flag = -1; 239 int flag = -1;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 for (int i = 0; i < FLAGS_r.count(); ++i) { 410 for (int i = 0; i < FLAGS_r.count(); ++i) {
390 failures += process_input(FLAGS_r[i], benchmark); 411 failures += process_input(FLAGS_r[i], benchmark);
391 } 412 }
392 413
393 if (failures != 0) { 414 if (failures != 0) {
394 SkString err; 415 SkString err;
395 err.printf("Failed to run %i benchmarks.\n", failures); 416 err.printf("Failed to run %i benchmarks.\n", failures);
396 gLogger.logError(err); 417 gLogger.logError(err);
397 return 1; 418 return 1;
398 } 419 }
420 #if LAZY_CACHE_STATS
421 if (FLAGS_trackDeferredCaching) {
422 SkDebugf("Total cache hit rate: %f\n",
423 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses ));
424 }
425 #endif
399 return 0; 426 return 0;
400 } 427 }
401 428
402 #if !defined SK_BUILD_FOR_IOS 429 #if !defined SK_BUILD_FOR_IOS
403 int main(int argc, char * const argv[]) { 430 int main(int argc, char * const argv[]) {
404 return tool_main(argc, (char**) argv); 431 return tool_main(argc, (char**) argv);
405 } 432 }
406 #endif 433 #endif
OLDNEW
« no previous file with comments | « src/lazy/SkLazyPixelRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698