skia2/tools/PictureBenchmark.cpp
scroggo@google.com 08085f808b Change the method for timing individual tiles in bench_pictures.
When timing individual tiles in bench_pictures, keep a timer running
across all repeats, and then take the average. The former method of
timing each iteration separately runs into precision errors on some
platforms.

Running on my Mac Pro with OSX 10.8, the cmsecs for the new method
and the old method are roughly the same when checking the CPU time.
When checking the wall time, the old method often gives me 0ms,
while the new method gives me a larger value. I don't think this
can be entirely attributed to rounding though, since on occasion I
see the old method showing a short time period (.05 - .15ms) while
the new method shows .15ms higher (which is in range for the
difference I'm seeing for other tiles where the old method reports
0ms).

Some other changes:
PictureRenderer::resetState now takes a boolean parameter. If called
with false, it will only do a flush, while if called with true, it
will also call finish.

resetState is now called with true everywhere except in between
iterations of drawing the same tile (when timing individual tiles).

render_pictures_main no longer calls resetState directly, since it
already calls end, which calls resetState.

BUG=http://code.google.com/p/skia/issues/detail?id=1066

Review URL: https://codereview.appspot.com/7101060

git-svn-id: http://skia.googlecode.com/svn/trunk@7424 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-01-28 20:40:24 +00:00

174 lines
6.2 KiB
C++

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBenchLogger.h"
#include "BenchTimer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkString.h"
#include "picture_utils.h"
#include "TimerData.h"
namespace sk_tools {
PictureBenchmark::PictureBenchmark()
: fRepeats(1)
, fLogger(NULL)
, fRenderer(NULL)
, fLogPerIter(false)
, fPrintMin(false)
, fShowWallTime(false)
, fShowTruncatedWallTime(false)
, fShowCpuTime(true)
, fShowTruncatedCpuTime(false)
, fShowGpuTime(false)
, fTimeIndividualTiles(false)
{}
PictureBenchmark::~PictureBenchmark() {
SkSafeUnref(fRenderer);
}
BenchTimer* PictureBenchmark::setupTimer() {
#if SK_SUPPORT_GPU
if (fRenderer != NULL && fRenderer->isUsingGpuDevice()) {
return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext()));
}
#endif
return SkNEW_ARGS(BenchTimer, (NULL));
}
void PictureBenchmark::logProgress(const char msg[]) {
if (fLogger != NULL) {
fLogger->logProgress(msg);
}
}
PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) {
SkRefCnt_SafeAssign(fRenderer, renderer);
return renderer;
}
void PictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (NULL == pict) {
return;
}
SkASSERT(fRenderer != NULL);
if (NULL == fRenderer) {
return;
}
fRenderer->init(pict);
// We throw this away to remove first time effects (such as paging in this program)
fRenderer->setup();
fRenderer->render(NULL);
fRenderer->resetState(true);
bool usingGpu = false;
#if SK_SUPPORT_GPU
usingGpu = fRenderer->isUsingGpuDevice();
#endif
if (fTimeIndividualTiles) {
TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer();
SkASSERT(tiledRenderer);
if (NULL == tiledRenderer) {
return;
}
int xTiles, yTiles;
if (!tiledRenderer->tileDimensions(xTiles, yTiles)) {
return;
}
// Insert a newline so that each tile is reported on its own line (separate from the line
// that describes the skp being run).
this->logProgress("\n");
int x, y;
while (tiledRenderer->nextTile(x, y)) {
// There are two timers, which will behave slightly differently:
// 1) longRunningTimer, along with perTileTimerData, will time how long it takes to draw
// one tile fRepeats times, and take the average. As such, it will not respect the
// logPerIter or printMin options, since it does not know the time per iteration. It
// will also be unable to call flush() for each tile.
// The goal of this timer is to make up for a system timer that is not precise enough to
// measure the small amount of time it takes to draw one tile once.
//
// 2) perTileTimer, along with perTileTimerData, will record each run separately, and
// then take the average. As such, it supports logPerIter and printMin options.
SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer());
TimerData longRunningTimerData(tiledRenderer->getPerIterTimeFormat(),
tiledRenderer->getNormalTimeFormat());
SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer());
TimerData perTileTimerData(tiledRenderer->getPerIterTimeFormat(),
tiledRenderer->getNormalTimeFormat());
longRunningTimer->start();
for (int i = 0; i < fRepeats; ++i) {
perTileTimer->start();
tiledRenderer->drawCurrentTile();
perTileTimer->truncatedEnd();
tiledRenderer->resetState(false);
perTileTimer->end();
perTileTimerData.appendTimes(perTileTimer.get(), fRepeats - 1 == i);
}
longRunningTimer->truncatedEnd();
tiledRenderer->resetState(true);
longRunningTimer->end();
longRunningTimerData.appendTimes(longRunningTimer.get(), true);
SkString configName = tiledRenderer->getConfigName();
configName.appendf(": tile [%i,%i] out of [%i,%i]", x, y, xTiles, yTiles);
SkString result = perTileTimerData.getResult(fLogPerIter, fPrintMin, fRepeats,
configName.c_str(), fShowWallTime,
fShowTruncatedWallTime, fShowCpuTime,
fShowTruncatedCpuTime,
usingGpu && fShowGpuTime);
result.append("\n");
this->logProgress(result.c_str());
configName.append(" <averaged>");
SkString longRunningResult = longRunningTimerData.getResult(false, false, fRepeats,
configName.c_str(), fShowWallTime, fShowTruncatedWallTime,
fShowCpuTime, fShowTruncatedCpuTime, usingGpu && fShowGpuTime);
longRunningResult.append("\n");
this->logProgress(longRunningResult.c_str());
}
} else {
SkAutoTDelete<BenchTimer> timer(this->setupTimer());
TimerData timerData(fRenderer->getPerIterTimeFormat(), fRenderer->getNormalTimeFormat());
for (int i = 0; i < fRepeats; ++i) {
fRenderer->setup();
timer->start();
fRenderer->render(NULL);
timer->truncatedEnd();
// Finishes gl context
fRenderer->resetState(true);
timer->end();
timerData.appendTimes(timer.get(), fRepeats - 1 == i);
}
SkString configName = fRenderer->getConfigName();
SkString result = timerData.getResult(fLogPerIter, fPrintMin, fRepeats,
configName.c_str(), fShowWallTime,
fShowTruncatedWallTime, fShowCpuTime,
fShowTruncatedCpuTime, usingGpu && fShowGpuTime);
result.append("\n");
this->logProgress(result.c_str());
}
fRenderer->end();
}
}