Added second "truncated" cpu/wall timer to bench

http://codereview.appspot.com/6476064/

This CL will increase the bench baselines across the board



git-svn-id: http://skia.googlecode.com/svn/trunk@5305 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-08-28 12:18:40 +00:00
Родитель 2af1b188aa
Коммит 91ee3a11ed
4 изменённых файлов: 81 добавлений и 15 удалений

Просмотреть файл

@ -23,9 +23,12 @@
BenchTimer::BenchTimer(SkGLContext* gl) BenchTimer::BenchTimer(SkGLContext* gl)
: fCpu(-1.0) : fCpu(-1.0)
, fWall(-1.0) , fWall(-1.0)
, fTruncatedCpu(-1.0)
, fTruncatedWall(-1.0)
, fGpu(-1.0) , fGpu(-1.0)
{ {
fSysTimer = new BenchSysTimer(); fSysTimer = new BenchSysTimer();
fTruncatedSysTimer = new BenchSysTimer();
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (gl) { if (gl) {
fGpuTimer = new BenchGpuTimer(gl); fGpuTimer = new BenchGpuTimer(gl);
@ -37,6 +40,7 @@ BenchTimer::BenchTimer(SkGLContext* gl)
BenchTimer::~BenchTimer() { BenchTimer::~BenchTimer() {
delete fSysTimer; delete fSysTimer;
delete fTruncatedSysTimer;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
delete fGpuTimer; delete fGpuTimer;
#endif #endif
@ -44,12 +48,14 @@ BenchTimer::~BenchTimer() {
void BenchTimer::start() { void BenchTimer::start() {
fSysTimer->startWall(); fSysTimer->startWall();
fTruncatedSysTimer->startWall();
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (fGpuTimer) { if (fGpuTimer) {
fGpuTimer->startGpu(); fGpuTimer->startGpu();
} }
#endif #endif
fSysTimer->startCpu(); fSysTimer->startCpu();
fTruncatedSysTimer->startCpu();
} }
void BenchTimer::end() { void BenchTimer::end() {
@ -63,3 +69,8 @@ void BenchTimer::end() {
#endif #endif
fWall = fSysTimer->endWall(); fWall = fSysTimer->endWall();
} }
void BenchTimer::truncatedEnd() {
fTruncatedCpu = fTruncatedSysTimer->endCpu();
fTruncatedWall = fTruncatedSysTimer->endWall();
}

Просмотреть файл

@ -18,8 +18,12 @@ class SkGLContext;
/** /**
* SysTimers and GpuTimers are implemented orthogonally. * SysTimers and GpuTimers are implemented orthogonally.
* This class combines a SysTimer and a GpuTimer into one single, * This class combines 2 SysTimers and a GpuTimer into one single,
* platform specific, Timer with a simple interface. * platform specific Timer with a simple interface. The truncated
* timer doesn't include the time required for the GPU to finish
* its rendering. It should always be <= the un-truncated system
* times and (for GPU configurations) can be used to roughly (very
* roughly) gauge the GPU load/backlog.
*/ */
class BenchTimer { class BenchTimer {
public: public:
@ -27,12 +31,16 @@ public:
~BenchTimer(); ~BenchTimer();
void start(); void start();
void end(); void end();
void truncatedEnd();
double fCpu; double fCpu;
double fWall; double fWall;
double fTruncatedCpu;
double fTruncatedWall;
double fGpu; double fGpu;
private: private:
BenchSysTimer *fSysTimer; BenchSysTimer *fSysTimer;
BenchSysTimer *fTruncatedSysTimer;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
BenchGpuTimer *fGpuTimer; BenchGpuTimer *fGpuTimer;
#endif #endif

Просмотреть файл

@ -396,7 +396,7 @@ static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
static void help() { static void help() {
SkDebugf("Usage: bench [-o outDir] [-repeat nr] [-logPerIter 1|0] " SkDebugf("Usage: bench [-o outDir] [-repeat nr] [-logPerIter 1|0] "
"[-timers [wcg]*] [-rotate]\n" "[-timers [wcgWC]*] [-rotate]\n"
" [-scale] [-clip] [-min] [-forceAA 1|0] [-forceFilter 1|0]\n" " [-scale] [-clip] [-min] [-forceAA 1|0] [-forceFilter 1|0]\n"
" [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n" " [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n"
" [-match name] [-mode normal|deferred|record|picturerecord]\n" " [-match name] [-mode normal|deferred|record|picturerecord]\n"
@ -407,8 +407,8 @@ static void help() {
SkDebugf(" -repeat nr : Each bench repeats for nr times.\n"); SkDebugf(" -repeat nr : Each bench repeats for nr times.\n");
SkDebugf(" -logPerIter 1|0 : " SkDebugf(" -logPerIter 1|0 : "
"Log each repeat timer instead of mean, default is disabled.\n"); "Log each repeat timer instead of mean, default is disabled.\n");
SkDebugf(" -timers [wcg]* : " SkDebugf(" -timers [wcgWC]* : "
"Display wall time, cpu time or gpu time for each bench.\n"); "Display wall, cpu, gpu, truncated wall or truncated cpu time for each bench.\n");
SkDebugf(" -rotate : Rotate before each bench runs.\n"); SkDebugf(" -rotate : Rotate before each bench runs.\n");
SkDebugf(" -scale : Scale before each bench runs.\n"); SkDebugf(" -scale : Scale before each bench runs.\n");
SkDebugf(" -clip : Clip before each bench runs.\n"); SkDebugf(" -clip : Clip before each bench runs.\n");
@ -455,7 +455,9 @@ int main (int argc, char * const argv[]) {
bool forceFilter = false; bool forceFilter = false;
SkTriState::State forceDither = SkTriState::kDefault; SkTriState::State forceDither = SkTriState::kDefault;
bool timerWall = false; bool timerWall = false;
bool truncatedTimerWall = false;
bool timerCpu = true; bool timerCpu = true;
bool truncatedTimerCpu = false;
bool timerGpu = true; bool timerGpu = true;
bool doScale = false; bool doScale = false;
bool doRotate = false; bool doRotate = false;
@ -508,12 +510,16 @@ int main (int argc, char * const argv[]) {
argv++; argv++;
if (argv < stop) { if (argv < stop) {
timerWall = false; timerWall = false;
truncatedTimerWall = false;
timerCpu = false; timerCpu = false;
truncatedTimerCpu = false;
timerGpu = false; timerGpu = false;
for (char* t = *argv; *t; ++t) { for (char* t = *argv; *t; ++t) {
switch (*t) { switch (*t) {
case 'w': timerWall = true; break; case 'w': timerWall = true; break;
case 'c': timerCpu = true; break; case 'c': timerCpu = true; break;
case 'W': truncatedTimerWall = true; break;
case 'C': truncatedTimerCpu = true; break;
case 'g': timerGpu = true; break; case 'g': timerGpu = true; break;
} }
} }
@ -836,6 +842,12 @@ int main (int argc, char * const argv[]) {
// warm up caches if needed // warm up caches if needed
if (repeatDraw > 1) { if (repeatDraw > 1) {
#if SK_SUPPORT_GPU
if (glHelper) {
// purge the GPU resources to reduce variance
glHelper->grContext()->freeGpuResources();
}
#endif
SkAutoCanvasRestore acr(canvas, true); SkAutoCanvasRestore acr(canvas, true);
if (benchMode == kPictureRecord_benchModes) { if (benchMode == kPictureRecord_benchModes) {
pictureRecordFrom.draw(canvas); pictureRecordFrom.draw(canvas);
@ -853,10 +865,14 @@ int main (int argc, char * const argv[]) {
// record timer values for each repeat, and their sum // record timer values for each repeat, and their sum
SkString fWallStr(" msecs = "); SkString fWallStr(" msecs = ");
SkString fTruncatedWallStr(" Wmsecs = ");
SkString fCpuStr(" cmsecs = "); SkString fCpuStr(" cmsecs = ");
SkString fTruncatedCpuStr(" Cmsecs = ");
SkString fGpuStr(" gmsecs = "); SkString fGpuStr(" gmsecs = ");
double fWallSum = 0.0, fWallMin; double fWallSum = 0.0, fWallMin;
double fTruncatedWallSum = 0.0, fTruncatedWallMin;
double fCpuSum = 0.0, fCpuMin; double fCpuSum = 0.0, fCpuMin;
double fTruncatedCpuSum = 0.0, fTruncatedCpuMin;
double fGpuSum = 0.0, fGpuMin; double fGpuSum = 0.0, fGpuMin;
for (int i = 0; i < repeatDraw; i++) { for (int i = 0; i < repeatDraw; i++) {
if ((benchMode == kRecord_benchModes if ((benchMode == kRecord_benchModes
@ -874,23 +890,36 @@ int main (int argc, char * const argv[]) {
bench->draw(canvas); bench->draw(canvas);
} }
canvas->flush(); canvas->flush();
// stop the truncated timer after the last canvas call but
// don't wait for all the GL calls to complete
timer.truncatedEnd();
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (glHelper) { if (glHelper) {
glHelper->grContext()->flush(); glHelper->grContext()->flush();
SK_GL(*glHelper->glContext(), Finish());
} }
#endif #endif
// stop the inclusive and gpu timers once all the GL calls
// have completed
timer.end(); timer.end();
if (i == repeatDraw - 1) { if (i == repeatDraw - 1) {
// no comma after the last value // no comma after the last value
fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall); fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall);
fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu); fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu);
fTruncatedWallStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedWall);
fTruncatedCpuStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedCpu);
fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu); fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu);
} else { } else {
fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall); fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall);
fWallStr.appendf(","); fWallStr.appendf(",");
fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu); fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu);
fCpuStr.appendf(","); fCpuStr.appendf(",");
fTruncatedWallStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedWall);
fTruncatedWallStr.appendf(",");
fTruncatedCpuStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedCpu);
fTruncatedCpuStr.appendf(",");
fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu); fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu);
fGpuStr.appendf(","); fGpuStr.appendf(",");
} }
@ -898,22 +927,23 @@ int main (int argc, char * const argv[]) {
if (0 == i) { if (0 == i) {
fWallMin = timer.fWall; fWallMin = timer.fWall;
fCpuMin = timer.fCpu; fCpuMin = timer.fCpu;
fTruncatedWallMin = timer.fTruncatedWall;
fTruncatedCpuMin = timer.fTruncatedCpu;
fGpuMin = timer.fGpu; fGpuMin = timer.fGpu;
} else { } else {
fWallMin = Min(fWallMin, timer.fWall); fWallMin = Min(fWallMin, timer.fWall);
fCpuMin = Min(fCpuMin, timer.fCpu); fCpuMin = Min(fCpuMin, timer.fCpu);
fTruncatedWallMin = Min(fTruncatedWallMin, timer.fTruncatedWall);
fTruncatedCpuMin = Min(fTruncatedCpuMin, timer.fTruncatedCpu);
fGpuMin = Min(fGpuMin, timer.fGpu); fGpuMin = Min(fGpuMin, timer.fGpu);
} }
fWallSum += timer.fWall; fWallSum += timer.fWall;
fCpuSum += timer.fCpu; fCpuSum += timer.fCpu;
fTruncatedWallSum += timer.fTruncatedWall;
fTruncatedCpuSum += timer.fTruncatedCpu;
fGpuSum += timer.fGpu; fGpuSum += timer.fGpu;
} }
#if SK_SUPPORT_GPU
if (glHelper) {
SK_GL(*glHelper->glContext(), Finish());
}
#endif
if (repeatDraw > 1) { if (repeatDraw > 1) {
// output each repeat (no average) if logPerIter is set, // output each repeat (no average) if logPerIter is set,
// otherwise output only the average // otherwise output only the average
@ -924,6 +954,12 @@ int main (int argc, char * const argv[]) {
fCpuStr.set(" cmsecs = "); fCpuStr.set(" cmsecs = ");
fCpuStr.appendf(normalTimeFormat.c_str(), fCpuStr.appendf(normalTimeFormat.c_str(),
printMin ? fCpuMin : fCpuSum / repeatDraw); printMin ? fCpuMin : fCpuSum / repeatDraw);
fTruncatedWallStr.set(" Wmsecs = ");
fTruncatedWallStr.appendf(normalTimeFormat.c_str(),
printMin ? fTruncatedWallMin : fTruncatedWallSum / repeatDraw);
fTruncatedCpuStr.set(" Cmsecs = ");
fTruncatedCpuStr.appendf(normalTimeFormat.c_str(),
printMin ? fTruncatedCpuMin : fTruncatedCpuSum / repeatDraw);
fGpuStr.set(" gmsecs = "); fGpuStr.set(" gmsecs = ");
fGpuStr.appendf(normalTimeFormat.c_str(), fGpuStr.appendf(normalTimeFormat.c_str(),
printMin ? fGpuMin : fGpuSum / repeatDraw); printMin ? fGpuMin : fGpuSum / repeatDraw);
@ -933,9 +969,15 @@ int main (int argc, char * const argv[]) {
if (timerWall) { if (timerWall) {
str += fWallStr; str += fWallStr;
} }
if (truncatedTimerWall) {
str += fTruncatedWallStr;
}
if (timerCpu) { if (timerCpu) {
str += fCpuStr; str += fCpuStr;
} }
if (truncatedTimerCpu) {
str += fTruncatedCpuStr;
}
if (timerGpu && glHelper && fGpuSum > 0) { if (timerGpu && glHelper && fGpuSum > 0) {
str += fGpuStr; str += fGpuStr;
} }

Просмотреть файл

@ -43,7 +43,7 @@ void PipePictureBenchmark::run(SkPicture* pict) {
fRenderer.resetState(); fRenderer.resetState();
BenchTimer* timer = this->setupTimer(); BenchTimer* timer = this->setupTimer();
double wall_time = 0; double wall_time = 0, truncated_wall_time = 0;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
double gpu_time = 0; double gpu_time = 0;
#endif #endif
@ -55,6 +55,7 @@ void PipePictureBenchmark::run(SkPicture* pict) {
fRenderer.resetState(); fRenderer.resetState();
wall_time += timer->fWall; wall_time += timer->fWall;
truncated_wall_time += timer->fTruncatedWall;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (fRenderer.isUsingGpuDevice()) { if (fRenderer.isUsingGpuDevice()) {
gpu_time += timer->fGpu; gpu_time += timer->fGpu;
@ -83,7 +84,7 @@ void RecordPictureBenchmark::run(SkPicture* pict) {
} }
BenchTimer* timer = setupTimer(); BenchTimer* timer = setupTimer();
double wall_time = 0; double wall_time = 0, truncated_wall_time = 0;
for (int i = 0; i < fRepeats + 1; ++i) { for (int i = 0; i < fRepeats + 1; ++i) {
SkPicture replayer; SkPicture replayer;
@ -96,6 +97,7 @@ void RecordPictureBenchmark::run(SkPicture* pict) {
// We want to ignore first time effects // We want to ignore first time effects
if (i > 0) { if (i > 0) {
wall_time += timer->fWall; wall_time += timer->fWall;
truncated_wall_time += timer->fTruncatedWall;
} }
} }
@ -121,7 +123,7 @@ void SimplePictureBenchmark::run(SkPicture* pict) {
BenchTimer* timer = this->setupTimer(); BenchTimer* timer = this->setupTimer();
double wall_time = 0; double wall_time = 0, truncated_wall_time = 0;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
double gpu_time = 0; double gpu_time = 0;
#endif #endif
@ -133,6 +135,7 @@ void SimplePictureBenchmark::run(SkPicture* pict) {
fRenderer.resetState(); fRenderer.resetState();
wall_time += timer->fWall; wall_time += timer->fWall;
truncated_wall_time += timer->fTruncatedWall;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (fRenderer.isUsingGpuDevice()) { if (fRenderer.isUsingGpuDevice()) {
gpu_time += timer->fGpu; gpu_time += timer->fGpu;
@ -169,7 +172,7 @@ void TiledPictureBenchmark::run(SkPicture* pict) {
fRenderer.resetState(); fRenderer.resetState();
BenchTimer* timer = setupTimer(); BenchTimer* timer = setupTimer();
double wall_time = 0; double wall_time = 0, truncated_wall_time = 0;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
double gpu_time = 0; double gpu_time = 0;
#endif #endif
@ -181,6 +184,7 @@ void TiledPictureBenchmark::run(SkPicture* pict) {
fRenderer.resetState(); fRenderer.resetState();
wall_time += timer->fWall; wall_time += timer->fWall;
truncated_wall_time += timer->fTruncatedWall;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (fRenderer.isUsingGpuDevice()) { if (fRenderer.isUsingGpuDevice()) {
gpu_time += timer->fGpu; gpu_time += timer->fGpu;
@ -216,7 +220,7 @@ void UnflattenPictureBenchmark::run(SkPicture* pict) {
} }
BenchTimer* timer = setupTimer(); BenchTimer* timer = setupTimer();
double wall_time = 0; double wall_time = 0, truncated_wall_time = 0;
for (int i = 0; i < fRepeats + 1; ++i) { for (int i = 0; i < fRepeats + 1; ++i) {
SkPicture replayer; SkPicture replayer;
@ -231,6 +235,7 @@ void UnflattenPictureBenchmark::run(SkPicture* pict) {
// We want to ignore first time effects // We want to ignore first time effects
if (i > 0) { if (i > 0) {
wall_time += timer->fWall; wall_time += timer->fWall;
truncated_wall_time += timer->fTruncatedWall;
} }
} }