OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "LazyDecodeBitmap.h" | 9 #include "LazyDecodeBitmap.h" |
10 #include "PictureBenchmark.h" | 10 #include "PictureBenchmark.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 break; | 290 break; |
291 } | 291 } |
292 do_benchmark_work(&renderer, benchControl.fType, | 292 do_benchmark_work(&renderer, benchControl.fType, |
293 path, pic, numRecordings, "recording", timer); | 293 path, pic, numRecordings, "recording", timer); |
294 } | 294 } |
295 | 295 |
296 /** | 296 /** |
297 * Takes argc,argv along with one of the benchmark functions defined above. | 297 * Takes argc,argv along with one of the benchmark functions defined above. |
298 * Will loop along all skp files and perform measurments. | 298 * Will loop along all skp files and perform measurments. |
299 * | 299 * |
300 * Returns a SkScalar representing CPU time taken during benchmark. | 300 * Returns a SkScalar representing CPU time taken during benchmark. |
mtklein
2014/03/05 15:04:53
While we're here, this comment seems at least two
iancottrell
2014/03/05 15:41:11
Done.
| |
301 * As a side effect, it spits the timer result to stdout. | 301 * As a side effect, it spits the timer result to stdout. |
302 * Will return -1.0 on error. | 302 * Will return -1.0 on error. |
303 */ | 303 */ |
304 static bool benchmark_loop( | 304 static void benchmark_loop( |
305 int argc, | 305 int argc, |
306 char **argv, | 306 char **argv, |
307 const BenchmarkControl& benchControl, | 307 const BenchmarkControl& benchControl, |
308 SkTArray<Histogram>& histogram) { | 308 SkTArray<Histogram>& histogram) { |
309 static const SkString timeFormat("%f"); | 309 static const SkString timeFormat("%f"); |
mtklein
2014/03/05 15:04:53
Now unused?
iancottrell
2014/03/05 15:41:11
Done.
| |
310 TimerData timerData(argc - 1); | |
311 for (int index = 1; index < argc; ++index) { | 310 for (int index = 1; index < argc; ++index) { |
312 BenchTimer timer; | 311 BenchTimer timer; |
313 SkString path(argv[index]); | 312 SkString path(argv[index]); |
314 SkAutoTUnref<SkPicture> pic(pic_from_path(path.c_str())); | 313 SkAutoTUnref<SkPicture> pic(pic_from_path(path.c_str())); |
315 if (NULL == pic) { | 314 if (NULL == pic) { |
316 SkDebugf("Couldn't create picture. Ignoring path: %s\n", path.c_str( )); | 315 SkDebugf("Couldn't create picture. Ignoring path: %s\n", path.c_str( )); |
317 continue; | 316 continue; |
318 } | 317 } |
319 benchControl.fFunction(benchControl, path, pic, &timer); | 318 benchControl.fFunction(benchControl, path, pic, &timer); |
320 | |
321 histogram[index - 1].fPath = path; | 319 histogram[index - 1].fPath = path; |
322 histogram[index - 1].fCpuTime = SkDoubleToScalar(timer.fCpu); | 320 histogram[index - 1].fCpuTime = SkDoubleToScalar(timer.fCpu); |
323 } | 321 } |
324 | |
325 const SkString timerResult = timerData.getResult( | |
326 /*doubleFormat = */ timeFormat.c_str(), | |
327 /*result = */ TimerData::kAvg_Result, | |
328 /*configName = */ benchControl.fName.c_str(), | |
329 /*timerFlags = */ TimerData::kCpu_Flag); | |
330 | |
331 const char findStr[] = "= "; | |
332 int pos = timerResult.find(findStr); | |
333 if (-1 == pos) { | |
334 SkDebugf("Unexpected output from TimerData::getResult(...). Unable to pa rse.\n"); | |
335 return false; | |
336 } | |
337 | |
338 SkScalar cpuTime = SkDoubleToScalar(atof(timerResult.c_str() + pos + sizeof( findStr) - 1)); | |
339 if (cpuTime == 0) { // atof returns 0.0 on error. | |
340 SkDebugf("Unable to read value from timer result.\n"); | |
341 return false; | |
342 } | |
343 return true; | |
344 } | 322 } |
345 | 323 |
346 int tool_main(int argc, char** argv); | 324 int tool_main(int argc, char** argv); |
347 int tool_main(int argc, char** argv) { | 325 int tool_main(int argc, char** argv) { |
348 SkAutoGraphics ag; | 326 SkAutoGraphics ag; |
349 SkString usage; | 327 SkString usage; |
350 usage.printf("Usage: filename [filename]*\n"); | 328 usage.printf("Usage: filename [filename]*\n"); |
351 | 329 |
352 if (argc < 2) { | 330 if (argc < 2) { |
353 SkDebugf("%s\n", usage.c_str()); | 331 SkDebugf("%s\n", usage.c_str()); |
354 return -1; | 332 return -1; |
355 } | 333 } |
356 | 334 |
357 SkTArray<Histogram> histograms[kNumBenchmarks]; | 335 SkTArray<Histogram> histograms[kNumBenchmarks]; |
358 | 336 |
359 for (size_t i = 0; i < kNumBenchmarks; ++i) { | 337 for (size_t i = 0; i < kNumBenchmarks; ++i) { |
360 histograms[i].reset(argc - 1); | 338 histograms[i].reset(argc - 1); |
361 bool success = benchmark_loop( | 339 benchmark_loop( |
362 argc, argv, | 340 argc, argv, |
mtklein
2014/03/05 15:04:53
Funky alignment now.
iancottrell
2014/03/05 15:41:11
Done.
| |
363 BenchmarkControl::Make(i), | 341 BenchmarkControl::Make(i), |
364 histograms[i]); | 342 histograms[i]); |
365 if (!success) { | |
366 SkDebugf("benchmark_loop failed at index %d\n", i); | |
367 } | |
368 } | 343 } |
369 | 344 |
370 // Output gnuplot readable histogram data.. | 345 // Output gnuplot readable histogram data.. |
371 const char* pbTitle = "bbh_shootout_playback.dat"; | 346 const char* pbTitle = "bbh_shootout_playback.dat"; |
372 const char* recTitle = "bbh_shootout_record.dat"; | 347 const char* recTitle = "bbh_shootout_record.dat"; |
373 SkFILEWStream playbackOut(pbTitle); | 348 SkFILEWStream playbackOut(pbTitle); |
374 SkFILEWStream recordOut(recTitle); | 349 SkFILEWStream recordOut(recTitle); |
375 recordOut.writeText("# "); | 350 recordOut.writeText("# "); |
376 playbackOut.writeText("# "); | 351 playbackOut.writeText("# "); |
377 for (size_t i = 0; i < kNumBenchmarks; ++i) { | 352 for (size_t i = 0; i < kNumBenchmarks; ++i) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 SkDebugf("\nWrote data to gnuplot-readable files: %s %s\n", pbTitle, recTitl e); | 406 SkDebugf("\nWrote data to gnuplot-readable files: %s %s\n", pbTitle, recTitl e); |
432 | 407 |
433 return 0; | 408 return 0; |
434 } | 409 } |
435 | 410 |
436 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 411 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
437 int main(int argc, char** argv) { | 412 int main(int argc, char** argv) { |
438 return tool_main(argc, argv); | 413 return tool_main(argc, argv); |
439 } | 414 } |
440 #endif | 415 #endif |
OLD | NEW |