From af3d79a8c81f3f224a5eff53b0ca8615b884f922 Mon Sep 17 00:00:00 2001 From: "bensong@google.com" Date: Mon, 2 Jul 2012 20:48:51 +0000 Subject: [PATCH] git-svn-id: http://skia.googlecode.com/svn/trunk@4433 2bbb7eff-a529-9590-31e7-b0007b416f81 --- bench/bench_util.py | 6 +++-- bench/benchmain.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/bench/bench_util.py b/bench/bench_util.py index e36e6c6..f3dd7af 100644 --- a/bench/bench_util.py +++ b/bench/bench_util.py @@ -55,7 +55,7 @@ def parse(settings, lines): setting_re = '([^\s=]+)(?:=(\S+))?' settings_re = 'skia bench:((?:\s+' + setting_re + ')*)' bench_re = 'running bench (?:\[\d+ \d+\] )?\s*(\S+)' - time_re = '(?:(\w*)msecs = )?\s*(\d+\.\d+)' + time_re = '(?:(\w*)msecs = )?\s*((?:\d+\.\d+)(?:,\d+\.\d+)*)' config_re = '(\S+): ((?:' + time_re + '\s+)+)' for line in lines: @@ -82,7 +82,9 @@ def parse(settings, lines): times = new_config.group(2) for new_time in re.finditer(time_re, times): current_time_type = new_time.group(1) - current_time = float(new_time.group(2)) + iters = [float[i] for i in + new_time.group(2).strip().split(',')] + current_time = sum(iters) / len(iters) benches.append(BenchDataPoint( current_bench , current_config diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index ec4f3a2..e088d12 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -328,7 +328,7 @@ static bool skip_name(const SkTDArray array, const char name[]) { } static void help() { - SkDebugf("Usage: bench [-o outDir] [-repeat nr] " + SkDebugf("Usage: bench [-o outDir] [-repeat nr] [-logPerIter 1|0] " "[-timers [wcg]*] [-rotate]\n" " [-scale] [-clip] [-forceAA 1|0] [-forceFilter 1|0]\n" " [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n" @@ -338,6 +338,8 @@ static void help() { SkDebugf("\n\n"); SkDebugf(" -o outDir : Image of each bench will be put in outDir.\n"); SkDebugf(" -repeat nr : Each bench repeats for nr times.\n"); + SkDebugf(" -logPerIter 1|0 : " + "Log each repeat timer instead of mean, default is disabled.\n"); SkDebugf(" -timers [wcg]* : " "Display wall time, cpu time or gpu time for each bench.\n"); SkDebugf(" -rotate : Rotate before each bench runs.\n"); @@ -366,6 +368,7 @@ int main (int argc, char * const argv[]) { SkTDict defineDict(1024); int repeatDraw = 1; + bool logPerIter = false; int forceAlpha = 0xFF; bool forceAA = true; bool forceFilter = false; @@ -411,6 +414,12 @@ int main (int argc, char * const argv[]) { help(); return -1; } + } else if (strcmp(*argv, "-logPerIter") == 0) { + if (!parse_bool_arg(++argv, stop, &logPerIter)) { + log_error("missing arg for -logPerIter\n"); + help(); + return -1; + } } else if (strcmp(*argv, "-timers") == 0) { argv++; if (argv < stop) { @@ -542,8 +551,9 @@ int main (int argc, char * const argv[]) { // report our current settings { SkString str; - str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d deferred=%d", - forceAlpha, forceAA, forceFilter, forceDeferred); + str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d " + "deferred=%d logperiter=%d", + forceAlpha, forceAA, forceFilter, forceDeferred, logPerIter); str.appendf(" rotate=%d scale=%d clip=%d", doRotate, doScale, doClip); @@ -605,8 +615,8 @@ int main (int argc, char * const argv[]) { gANGLEGLHelper.init(angleGLCtx.get(), contextWidth, contextHeight); #endif #endif - BenchTimer timer = BenchTimer(gRealGLHelper.glContext()); + BenchTimer timer = BenchTimer(gRealGLHelper.glContext()); Iter iter(&defineDict); SkBenchmark* bench; while ((bench = iter.next()) != NULL) { @@ -668,7 +678,7 @@ int main (int argc, char * const argv[]) { performRotate(canvas, dim.fX, dim.fY); } - //warm up caches if needed + // warm up caches if needed if (repeatDraw > 1) { SkAutoCanvasRestore acr(canvas, true); bench->draw(canvas); @@ -678,32 +688,60 @@ int main (int argc, char * const argv[]) { SK_GL(*glHelper->glContext(), Finish()); } } - - timer.start(); + + // record timer values for each repeat, and their sum + SkString fWallStr(" msecs = "); + SkString fCpuStr(" cmsecs = "); + SkString fGpuStr(" gmsecs = "); + double fWallSum = 0.0; + double fCpuSum = 0.0; + double fGpuSum = 0.0; for (int i = 0; i < repeatDraw; i++) { + timer.start(); SkAutoCanvasRestore acr(canvas, true); bench->draw(canvas); canvas->flush(); if (glHelper) { glHelper->grContext()->flush(); } + timer.end(); + + if (i == repeatDraw - 1) { + // no comma after the last value + fWallStr.appendf("%.2f", timer.fWall); + fCpuStr.appendf("%.2f", timer.fCpu); + fGpuStr.appendf("%.2f", timer.fGpu); + } else { + fWallStr.appendf("%.2f,", timer.fWall); + fCpuStr.appendf("%.2f,", timer.fCpu); + fGpuStr.appendf("%.2f,", timer.fGpu); + } + fWallSum += timer.fWall; + fCpuSum += timer.fCpu; + fGpuSum += timer.fGpu; } if (glHelper) { SK_GL(*glHelper->glContext(), Finish()); } - timer.end(); - + if (repeatDraw > 1) { + // output each repeat (no average) if logPerIter is set, + // otherwise output only the average + if (!logPerIter) { + fWallStr.printf(" msecs = %6.2f", fWallSum / repeatDraw); + fCpuStr.printf(" cmsecs = %6.2f", fCpuSum / repeatDraw); + fGpuStr.printf(" gmsecs = %6.2f", fGpuSum / repeatDraw); + } SkString str; str.printf(" %4s:", configName); if (timerWall) { - str.appendf(" msecs = %6.2f", timer.fWall / repeatDraw); + str += fWallStr; } if (timerCpu) { - str.appendf(" cmsecs = %6.2f", timer.fCpu / repeatDraw); + str += fCpuStr; } - if (timerGpu && glHelper && timer.fGpu > 0) { - str.appendf(" gmsecs = %6.2f", timer.fGpu / repeatDraw); + if (timerGpu && glHelper && fGpuSum > 0) { + str += fGpuStr; } log_progress(str); } -- 2.7.4