Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: bench/TimerData.cpp

Issue 19862002: Do timer allocation and string building outside of bench loops (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix bbh_shootout Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "TimerData.h" 9 #include "TimerData.h"
10 10
11 #include "BenchTimer.h" 11 #include "BenchTimer.h"
12 #include <limits> 12 #include <limits>
13 13
14 using namespace std; 14 using namespace std;
15 15
16 TimerData::TimerData(const SkString& perIterTimeFormat, const SkString& normalTi meFormat) 16 TimerData::TimerData(int maxNumTimings)
17 : fWallStr(" msecs = ") 17 : fMaxNumTimings(maxNumTimings)
18 , fTruncatedWallStr(" Wmsecs = ") 18 , fCurrTiming(0)
19 , fCpuStr(" cmsecs = ") 19 , fWallTimes(maxNumTimings)
20 , fTruncatedCpuStr(" Cmsecs = ") 20 , fTruncatedWallTimes(maxNumTimings)
21 , fGpuStr(" gmsecs = ") 21 , fCpuTimes(maxNumTimings)
22 , fWallSum(0.0) 22 , fTruncatedCpuTimes(maxNumTimings)
23 , fWallMin((numeric_limits<double>::max)()) // Extra parens to make the windows build work, due to 23 , fGpuTimes(maxNumTimings){
24 // 'max' macro
25 , fTruncatedWallSum(0.0)
26 , fTruncatedWallMin((numeric_limits<double>::max)())
27 , fCpuSum(0.0)
28 , fCpuMin((numeric_limits<double>::max)())
29 , fTruncatedCpuSum(0.0)
30 , fTruncatedCpuMin((numeric_limits<double>::max)())
31 , fGpuSum(0.0)
32 , fGpuMin((numeric_limits<double>::max)())
33 , fPerIterTimeFormat(perIterTimeFormat)
34 , fNormalTimeFormat(normalTimeFormat)
35 {}
36
37 static double Min(double a, double b) {
38 return (a < b) ? a : b;
39 } 24 }
40 25
41 void TimerData::appendTimes(BenchTimer* timer, bool last) { 26 bool TimerData::appendTimes(BenchTimer* timer) {
42 SkASSERT(timer != NULL); 27 SkASSERT(timer != NULL);
43 SkString formatString(fPerIterTimeFormat); 28 if (fCurrTiming >= fMaxNumTimings) {
44 if (!last) { 29 return false;
45 formatString.append(",");
46 } 30 }
47 const char* format = formatString.c_str();
48 fWallStr.appendf(format, timer->fWall);
49 fCpuStr.appendf(format, timer->fCpu);
50 fTruncatedWallStr.appendf(format, timer->fTruncatedWall);
51 fTruncatedCpuStr.appendf(format, timer->fTruncatedCpu);
52 fGpuStr.appendf(format, timer->fGpu);
53 31
54 // Store the minimum values. We do not need to special case the first time s ince we initialized 32 fWallTimes[fCurrTiming] = timer->fWall;
55 // to max double. 33 fTruncatedWallTimes[fCurrTiming] = timer->fTruncatedWall;
56 fWallMin = Min(fWallMin, timer->fWall); 34 fCpuTimes[fCurrTiming] = timer->fCpu;
57 fCpuMin = Min(fCpuMin, timer->fCpu); 35 fTruncatedCpuTimes[fCurrTiming] = timer->fTruncatedCpu;
58 fTruncatedWallMin = Min(fTruncatedWallMin, timer->fTruncatedWall); 36 fGpuTimes[fCurrTiming] = timer->fGpu;
59 fTruncatedCpuMin = Min(fTruncatedCpuMin, timer->fTruncatedCpu);
60 fGpuMin = Min(fGpuMin, timer->fGpu);
61 37
62 // Tally the sum of each timer type. 38 ++fCurrTiming;
63 fWallSum += timer->fWall;
64 fCpuSum += timer->fCpu;
65 fTruncatedWallSum += timer->fTruncatedWall;
66 fTruncatedCpuSum += timer->fTruncatedCpu;
67 fGpuSum += timer->fGpu;
68 39
40 return true;
69 } 41 }
70 42
71 SkString TimerData::getResult(bool logPerIter, bool printMin, int repeatDraw, 43 SkString TimerData::getResult(const char* doubleFormat,
72 const char *configName, bool showWallTime, bool sh owTruncatedWallTime, 44 Result result,
73 bool showCpuTime, bool showTruncatedCpuTime, bool showGpuTime) { 45 const char *configName,
74 // output each repeat (no average) if logPerIter is set, 46 uint32_t timerFlags,
75 // otherwise output only the average 47 int itersPerTiming) {
76 if (!logPerIter) { 48 SkASSERT(itersPerTiming >= 1);
77 const char* format = fNormalTimeFormat.c_str(); 49
78 fWallStr.set(" msecs = "); 50 if (!fCurrTiming) {
79 fWallStr.appendf(format, printMin ? fWallMin : fWallSum / repeatDraw); 51 return SkString("");
80 fCpuStr.set(" cmsecs = ");
81 fCpuStr.appendf(format, printMin ? fCpuMin : fCpuSum / repeatDraw);
82 fTruncatedWallStr.set(" Wmsecs = ");
83 fTruncatedWallStr.appendf(format,
84 printMin ? fTruncatedWallMin : fTruncatedWallS um / repeatDraw);
85 fTruncatedCpuStr.set(" Cmsecs = ");
86 fTruncatedCpuStr.appendf(format,
87 printMin ? fTruncatedCpuMin : fTruncatedCpuSum / repeatDraw);
88 fGpuStr.set(" gmsecs = ");
89 fGpuStr.appendf(format, printMin ? fGpuMin : fGpuSum / repeatDraw);
90 } 52 }
53
54 int numTimings = fCurrTiming;
55
56 SkString wallStr(" msecs = ");
57 SkString truncWallStr(" Wmsecs = ");
58 SkString cpuStr(" cmsecs = ");
59 SkString truncCpuStr(" Cmsecs = ");
60 SkString gpuStr(" gmsecs = ");
61
62 double wallMin = std::numeric_limits<double>::max();
63 double truncWallMin = std::numeric_limits<double>::max();
64 double cpuMin = std::numeric_limits<double>::max();
65 double truncCpuMin = std::numeric_limits<double>::max();
66 double gpuMin = std::numeric_limits<double>::max();
67
68 double wallSum = 0;
69 double truncWallSum = 0;
70 double cpuSum = 0;
71 double truncCpuSum = 0;
72 double gpuSum = 0;
73
74 for (int i = 0; i < numTimings; ++i) {
75 if (kPerIter_Result == result) {
76 wallStr.appendf(doubleFormat, fWallTimes[i]);
77 truncWallStr.appendf(doubleFormat, fTruncatedWallTimes[i]);
78 cpuStr.appendf(doubleFormat, fCpuTimes[i]);
79 truncCpuStr.appendf(doubleFormat, fTruncatedCpuTimes[i]);
80 gpuStr.appendf(doubleFormat, fGpuTimes[i]);
81
82 if (i != numTimings - 1) {
83 static const char kSep[] = ", ";
84 wallStr.append(kSep);
85 truncWallStr.append(kSep);
86 cpuStr.append(kSep);
87 truncCpuStr.append(kSep);
88 gpuStr.append(kSep);
89 }
90 } else if (kMin_Result == result) {
91 wallMin = SkTMin(wallMin, fWallTimes[i]);
92 truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]);
93 cpuMin = SkTMin(cpuMin, fCpuTimes[i]);
94 truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]);
95 gpuMin = SkTMin(gpuMin, fGpuTimes[i]);
96 } else {
97 SkASSERT(kAvg_Result == result);
98 wallSum += fWallTimes[i];
99 truncWallSum += fTruncatedWallTimes[i];
100 cpuSum += fCpuTimes[i];
101 truncCpuSum += fTruncatedCpuTimes[i];
102 }
103
104 // We always track the GPU sum because whether it is non-zero indicates if valid gpu times
105 // were recorded at all.
106 gpuSum += fGpuTimes[i];
107 }
108
109 if (kMin_Result == result) {
110 wallStr.appendf(doubleFormat, wallMin / itersPerTiming);
111 truncWallStr.appendf(doubleFormat, truncWallMin / itersPerTiming);
112 cpuStr.appendf(doubleFormat, cpuMin / itersPerTiming);
113 truncCpuStr.appendf(doubleFormat, truncCpuMin / itersPerTiming);
114 gpuStr.appendf(doubleFormat, gpuMin / itersPerTiming);
115 } else if (kAvg_Result == result) {
116 int divisor = numTimings * itersPerTiming;
117 wallStr.appendf(doubleFormat, wallSum / divisor);
118 truncWallStr.appendf(doubleFormat, truncWallSum / divisor);
119 cpuStr.appendf(doubleFormat, cpuSum / divisor);
120 truncCpuStr.appendf(doubleFormat, truncCpuSum / divisor);
121 gpuStr.appendf(doubleFormat, gpuSum / divisor);
122 }
123
91 SkString str; 124 SkString str;
92 str.printf(" %4s:", configName); 125 str.printf(" %4s:", configName);
93 if (showWallTime) { 126 if (timerFlags & kWall_Flag) {
94 str += fWallStr; 127 str += wallStr;
95 } 128 }
96 if (showTruncatedWallTime) { 129 if (timerFlags & kTruncatedWall_Flag) {
97 str += fTruncatedWallStr; 130 str += truncWallStr;
98 } 131 }
99 if (showCpuTime) { 132 if (timerFlags & kCpu_Flag) {
100 str += fCpuStr; 133 str += cpuStr;
101 } 134 }
102 if (showTruncatedCpuTime) { 135 if (timerFlags & kTruncatedCpu_Flag) {
103 str += fTruncatedCpuStr; 136 str += truncCpuStr;
104 } 137 }
105 if (showGpuTime && fGpuSum > 0) { 138 if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
106 str += fGpuStr; 139 str += gpuStr;
107 } 140 }
108 return str; 141 return str;
109 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698