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

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: on top of tot Created 7 years, 4 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
« no previous file with comments | « bench/TimerData.h ('k') | bench/benchmain.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()) 23 , fGpuTimes(maxNumTimings){
24 , fTruncatedWallSum(0.0)
25 , fTruncatedWallMin(numeric_limits<double>::max())
26 , fCpuSum(0.0)
27 , fCpuMin(numeric_limits<double>::max())
28 , fTruncatedCpuSum(0.0)
29 , fTruncatedCpuMin(numeric_limits<double>::max())
30 , fGpuSum(0.0)
31 , fGpuMin(numeric_limits<double>::max())
32 , fPerIterTimeFormat(perIterTimeFormat)
33 , fNormalTimeFormat(normalTimeFormat)
34 {}
35
36 static double Min(double a, double b) {
37 return (a < b) ? a : b;
38 } 24 }
39 25
40 void TimerData::appendTimes(BenchTimer* timer, bool last) { 26 bool TimerData::appendTimes(BenchTimer* timer) {
41 SkASSERT(timer != NULL); 27 SkASSERT(timer != NULL);
42 SkString formatString(fPerIterTimeFormat); 28 if (fCurrTiming >= fMaxNumTimings) {
43 if (!last) { 29 return false;
44 formatString.append(",");
45 } 30 }
46 const char* format = formatString.c_str();
47 fWallStr.appendf(format, timer->fWall);
48 fCpuStr.appendf(format, timer->fCpu);
49 fTruncatedWallStr.appendf(format, timer->fTruncatedWall);
50 fTruncatedCpuStr.appendf(format, timer->fTruncatedCpu);
51 fGpuStr.appendf(format, timer->fGpu);
52 31
53 // Store the minimum values. We do not need to special case the first time s ince we initialized 32 fWallTimes[fCurrTiming] = timer->fWall;
54 // to max double. 33 fTruncatedWallTimes[fCurrTiming] = timer->fTruncatedWall;
55 fWallMin = Min(fWallMin, timer->fWall); 34 fCpuTimes[fCurrTiming] = timer->fCpu;
56 fCpuMin = Min(fCpuMin, timer->fCpu); 35 fTruncatedCpuTimes[fCurrTiming] = timer->fTruncatedCpu;
57 fTruncatedWallMin = Min(fTruncatedWallMin, timer->fTruncatedWall); 36 fGpuTimes[fCurrTiming] = timer->fGpu;
58 fTruncatedCpuMin = Min(fTruncatedCpuMin, timer->fTruncatedCpu);
59 fGpuMin = Min(fGpuMin, timer->fGpu);
60 37
61 // Tally the sum of each timer type. 38 ++fCurrTiming;
62 fWallSum += timer->fWall;
63 fCpuSum += timer->fCpu;
64 fTruncatedWallSum += timer->fTruncatedWall;
65 fTruncatedCpuSum += timer->fTruncatedCpu;
66 fGpuSum += timer->fGpu;
67 39
40 return true;
68 } 41 }
69 42
70 SkString TimerData::getResult(bool logPerIter, bool printMin, int repeatDraw, 43 SkString TimerData::getResult(const char* doubleFormat,
71 const char *configName, bool showWallTime, bool sh owTruncatedWallTime, 44 Result result,
72 bool showCpuTime, bool showTruncatedCpuTime, bool showGpuTime) { 45 const char *configName,
73 // output each repeat (no average) if logPerIter is set, 46 uint32_t timerFlags,
74 // otherwise output only the average 47 int itersPerTiming) {
75 if (!logPerIter) { 48 SkASSERT(itersPerTiming >= 1);
76 const char* format = fNormalTimeFormat.c_str(); 49
77 fWallStr.set(" msecs = "); 50 if (!fCurrTiming) {
78 fWallStr.appendf(format, printMin ? fWallMin : fWallSum / repeatDraw); 51 return SkString("");
79 fCpuStr.set(" cmsecs = ");
80 fCpuStr.appendf(format, printMin ? fCpuMin : fCpuSum / repeatDraw);
81 fTruncatedWallStr.set(" Wmsecs = ");
82 fTruncatedWallStr.appendf(format,
83 printMin ? fTruncatedWallMin : fTruncatedWallS um / repeatDraw);
84 fTruncatedCpuStr.set(" Cmsecs = ");
85 fTruncatedCpuStr.appendf(format,
86 printMin ? fTruncatedCpuMin : fTruncatedCpuSum / repeatDraw);
87 fGpuStr.set(" gmsecs = ");
88 fGpuStr.appendf(format, printMin ? fGpuMin : fGpuSum / repeatDraw);
89 } 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
90 SkString str; 124 SkString str;
91 str.printf(" %4s:", configName); 125 str.printf(" %4s:", configName);
92 if (showWallTime) { 126 if (timerFlags & kWall_Flag) {
93 str += fWallStr; 127 str += wallStr;
94 } 128 }
95 if (showTruncatedWallTime) { 129 if (timerFlags & kTruncatedWall_Flag) {
96 str += fTruncatedWallStr; 130 str += truncWallStr;
97 } 131 }
98 if (showCpuTime) { 132 if (timerFlags & kCpu_Flag) {
99 str += fCpuStr; 133 str += cpuStr;
100 } 134 }
101 if (showTruncatedCpuTime) { 135 if (timerFlags & kTruncatedCpu_Flag) {
102 str += fTruncatedCpuStr; 136 str += truncCpuStr;
103 } 137 }
104 if (showGpuTime && fGpuSum > 0) { 138 if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
105 str += fGpuStr; 139 str += gpuStr;
106 } 140 }
107 return str; 141 return str;
108 } 142 }
OLDNEW
« no previous file with comments | « bench/TimerData.h ('k') | bench/benchmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698