skia2/tools/PictureBenchmark.cpp
scroggo@google.com 9a4125283a Report data from bench_pictures in the same fashion as bench.
Move SkBenchLogger into separate files and make bench_pictures use it.
Remove sk_tools::print_msg, since SkBenchLogger is now used instead.

Combine picture_benchmark with bench_pictures, since that is the
only project that uses it.

Refactor the aggregator for bench timer data into its own class and
make bench_pictures use it.

Consolidate the various virtual PictureBenchmark::run functions
into one for reuse.

BUG=https://code.google.com/p/skia/issues/detail?id=822

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

git-svn-id: http://skia.googlecode.com/svn/trunk@5432 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-09-07 15:21:18 +00:00

99 lines
2.5 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 "SkTypes.h"
#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 {
BenchTimer* PictureBenchmark::setupTimer() {
#if SK_SUPPORT_GPU
PictureRenderer* renderer = getRenderer();
if (renderer != NULL && renderer->isUsingGpuDevice()) {
return SkNEW_ARGS(BenchTimer, (renderer->getGLContext()));
} else {
return SkNEW_ARGS(BenchTimer, (NULL));
}
#else
return SkNEW_ARGS(BenchTimer, (NULL));
#endif
}
void PictureBenchmark::logProgress(const char msg[]) {
if (fLogger != NULL) {
fLogger->logProgress(msg);
}
}
void PictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (NULL == pict) {
return;
}
PictureRenderer* renderer = this->getRenderer();
SkASSERT(renderer != NULL);
if (NULL == renderer) {
return;
}
renderer->init(pict);
// We throw this away to remove first time effects (such as paging in this
// program)
renderer->setup();
renderer->render(false);
renderer->resetState();
BenchTimer* timer = this->setupTimer();
bool usingGpu = false;
#if SK_SUPPORT_GPU
usingGpu = renderer->isUsingGpuDevice();
#endif
TimerData timerData(renderer->getPerIterTimeFormat(), renderer->getNormalTimeFormat());
for (int i = 0; i < fRepeats; ++i) {
renderer->setup();
timer->start();
renderer->render(false);
timer->truncatedEnd();
// Finishes gl context
renderer->resetState();
timer->end();
timerData.appendTimes(timer, fRepeats - 1 == i);
}
// FIXME: Pass these options on the command line.
bool logPerIter = false;
bool printMin = false;
const char* configName = usingGpu ? "gpu" : "raster";
bool showWallTime = true;
bool showTruncatedWallTime = false;
bool showCpuTime = false;
bool showTruncatedCpuTime = false;
SkString result = timerData.getResult(logPerIter, printMin, fRepeats,
configName, showWallTime, showTruncatedWallTime,
showCpuTime, showTruncatedCpuTime, usingGpu);
result.append("\n");
this->logProgress(result.c_str());
renderer->end();
SkDELETE(timer);
}
}