Add measurement command line args to SampleApp

This way, we may be able to use SampleApp as a performance benchmark
tool that's closer to real-world use cases than nanobench.

For example, we can now run

./out/Release/SampleApp --slide Chart --backendTiles 8 --measureMS 2000

to test the threaded backend.

Bug: skia:
Change-Id: I92b177624bc8d16c5b4d3ad122319882e8783101
Reviewed-on: https://skia-review.googlesource.com/50801
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
This commit is contained in:
Yuqian Li 2017-09-25 14:45:25 -04:00 committed by Skia Commit-Bot
parent b449666fa2
commit 94fddf8381
2 changed files with 31 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "SampleApp.h"
#include "SkCommonFlags.h"
#include "OverView.h"
#include "Resources.h"
#include "SampleCode.h"
@ -757,6 +758,10 @@ DEFINE_pathrenderer_flag;
DEFINE_int32(msaa, 0, "Request multisampling with this count.");
DEFINE_bool(deepColor, false, "Request deep color (10-bit/channel or more) display buffer.");
#endif
DEFINE_int32(backendTiles, 0, "Number of tiles in the experimental threaded backend.");
DEFINE_int32(backendThreads, 0, "Number of threads in the experimental threaded backend.");
DEFINE_int32(measureMS, 0, "Number of miliseconds to measure the FPS before closing the SampleApp. "
"If it's 0, we won't measure the FPS or close SampleApp automatically.");
#include "SkTaskGroup.h"
@ -923,6 +928,22 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fSaveToPdf = false;
fSaveToSKP = false;
gSkUseAnalyticAA = FLAGS_analyticAA;
gSkUseDeltaAA = FLAGS_deltaAA;
if (FLAGS_forceAnalyticAA) {
gSkForceAnalyticAA = true;
}
if (FLAGS_forceDeltaAA) {
gSkForceDeltaAA = true;
}
fTiles = FLAGS_backendTiles;
fThreads = FLAGS_backendThreads;
fMeasureMS = FLAGS_measureMS;
if (FLAGS_measureMS > 0) {
SkASSERT(fMeasureFPS == false);
toggleFPS();
}
if (true) {
fPipeSerializer.setTypefaceSerializer(new SampleTFSerializer);
fPipeDeserializer.setTypefaceDeserializer(new SampleTFDeserializer);
@ -1042,6 +1063,10 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
}
SampleWindow::~SampleWindow() {
if (fMeasureFPS) {
SkDebugf("Average frame time of the last slide: %.4f ms\n",
fCumulativeFPS_Time / (float)SkTMax(1, fCumulativeFPS_Count));
}
SkSafeUnref(fDevManager);
}
@ -2261,6 +2286,10 @@ bool SampleWindow::getRawTitle(SkString* title) {
}
void SampleWindow::updateTitle() {
if (fMeasureMS > 0 && (int)gAnimTimer.msec() > fMeasureMS) {
this->closeWindow();
}
SkString title;
if (!this->getRawTitle(&title)) {
title.set("<unknown>");

View File

@ -254,6 +254,8 @@ private:
int fThreads = 0;
std::unique_ptr<SkExecutor> fExecutor;
int fMeasureMS; // the number of milliseconds to measure the FPS before we close the SampleApp
void loadView(SkView*);
void updateTitle();
bool getRawTitle(SkString*);