1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "VisualLightweightBenchModule.h"
#include "ProcStats.h"
#include "SkApplication.h"
#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
#include "SkGraphics.h"
#include "SkGr.h"
#include "SkOSFile.h"
#include "SkStream.h"
#include "Stats.h"
#include "gl/GrGLInterface.h"
// Between samples we reset context
// Between frames we swap buffers
DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
DEFINE_string(key, "",
"Space-separated key/value pairs to add to JSON identifying this builder.");
DEFINE_string(properties, "",
"Space-separated key/value pairs to add to JSON identifying this run.");
DEFINE_int32(samples, 10, "Number of times to time each skp.");
static SkString humanize(double ms) {
if (FLAGS_verbose) {
return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
}
return HumanizeMs(ms);
}
#define HUMANIZE(time) humanize(time).c_str()
VisualLightweightBenchModule::VisualLightweightBenchModule(VisualBench* owner)
: INHERITED(owner)
, fCurrentSample(0)
, fResults(new ResultsWriter) {
// Print header
SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
FLAGS_samples, "samples");
// setup json logging if required
if (!FLAGS_outResultsFile.isEmpty()) {
fResults.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0]));
}
if (1 == FLAGS_key.count() % 2) {
SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
} else {
for (int i = 1; i < FLAGS_key.count(); i += 2) {
fResults->key(FLAGS_key[i - 1], FLAGS_key[i]);
}
}
if (1 == FLAGS_properties.count() % 2) {
SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
} else {
for (int i = 1; i < FLAGS_properties.count(); i += 2) {
fResults->property(FLAGS_properties[i - 1], FLAGS_properties[i]);
}
}
// seed an initial record
fRecords.push_back();
}
void VisualLightweightBenchModule::renderFrame(SkCanvas* canvas, Benchmark* benchmark, int loops) {
benchmark->draw(loops, canvas);
canvas->flush();
}
void VisualLightweightBenchModule::printStats(Benchmark* benchmark, int loops) {
const SkTArray<double>& measurements = fRecords.back().fMeasurements;
const char* shortName = benchmark->getUniqueName();
// update log
// Note: We currently log only the minimum. It would be interesting to log more information
SkString configName;
if (FLAGS_cpu) {
configName.append("cpu");
} else if (FLAGS_nvpr) {
if (FLAGS_offscreen) {
configName.appendf("nvpr_%d", FLAGS_msaa);
} else {
configName.appendf("nvpr_msaa_%d", FLAGS_msaa);
}
} else if (FLAGS_msaa > 0) {
if (FLAGS_offscreen) {
configName.appendf("offscreen_msaa_%d", FLAGS_msaa);
} else {
configName.appendf("msaa_%d", FLAGS_msaa);
}
} else {
if (FLAGS_offscreen) {
configName.append("offscreen");
} else {
configName.append("gpu");
}
}
// Log bench name
fResults->bench(shortName, benchmark->getSize().fX, benchmark->getSize().fY);
fResults->config(configName.c_str());
fResults->configOption("name", shortName);
SkASSERT(measurements.count());
Stats stats(measurements);
fResults->metric("min_ms", stats.min);
// Print output
if (FLAGS_verbose) {
for (int i = 0; i < measurements.count(); i++) {
SkDebugf("%s ", HUMANIZE(measurements[i]));
}
SkDebugf("%s\n", shortName);
} else {
const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean;
SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n",
sk_tools::getCurrResidentSetSizeMB(),
sk_tools::getMaxResidentSetSizeMB(),
loops,
HUMANIZE(stats.min),
HUMANIZE(stats.median),
HUMANIZE(stats.mean),
HUMANIZE(stats.max),
stdDevPercent,
stats.plot.c_str(),
configName.c_str(),
shortName);
}
}
bool VisualLightweightBenchModule::timingFinished(Benchmark* benchmark, int loops,
double measurement) {
fRecords.back().fMeasurements.push_back(measurement);
if (++fCurrentSample > FLAGS_samples) {
this->printStats(benchmark, loops);
fRecords.push_back();
fCurrentSample = 0;
return true;
}
return false;
}
bool VisualLightweightBenchModule::onHandleChar(SkUnichar c) {
return true;
}
|