| OLD | NEW |
| 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 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 str += cpuStr; | 133 str += cpuStr; |
| 134 } | 134 } |
| 135 if (timerFlags & kTruncatedCpu_Flag) { | 135 if (timerFlags & kTruncatedCpu_Flag) { |
| 136 str += truncCpuStr; | 136 str += truncCpuStr; |
| 137 } | 137 } |
| 138 if ((timerFlags & kGpu_Flag) && gpuSum > 0) { | 138 if ((timerFlags & kGpu_Flag) && gpuSum > 0) { |
| 139 str += gpuStr; | 139 str += gpuStr; |
| 140 } | 140 } |
| 141 return str; | 141 return str; |
| 142 } | 142 } |
| 143 | |
| 144 Json::Value TimerData::getJSON(uint32_t timerFlags, | |
| 145 Result result, | |
| 146 int itersPerTiming) { | |
| 147 SkASSERT(itersPerTiming >= 1); | |
| 148 Json::Value dataNode; | |
| 149 Json::Value wallNode, truncWall, cpuNode, truncCpu, gpuNode; | |
| 150 if (!fCurrTiming) { | |
| 151 return dataNode; | |
| 152 } | |
| 153 | |
| 154 int numTimings = fCurrTiming; | |
| 155 | |
| 156 double wallMin = std::numeric_limits<double>::max(); | |
| 157 double truncWallMin = std::numeric_limits<double>::max(); | |
| 158 double cpuMin = std::numeric_limits<double>::max(); | |
| 159 double truncCpuMin = std::numeric_limits<double>::max(); | |
| 160 double gpuMin = std::numeric_limits<double>::max(); | |
| 161 | |
| 162 double wallSum = 0; | |
| 163 double truncWallSum = 0; | |
| 164 double cpuSum = 0; | |
| 165 double truncCpuSum = 0; | |
| 166 double gpuSum = 0; | |
| 167 | |
| 168 for (int i = 0; i < numTimings; ++i) { | |
| 169 if (kPerIter_Result == result) { | |
| 170 wallNode.append(fWallTimes[i] / itersPerTiming); | |
| 171 truncWall.append(fTruncatedWallTimes[i] / itersPerTiming); | |
| 172 cpuNode.append(fCpuTimes[i] / itersPerTiming); | |
| 173 truncCpu.append(fTruncatedCpuTimes[i] / itersPerTiming); | |
| 174 gpuNode.append(fGpuTimes[i] / itersPerTiming); | |
| 175 } else if (kMin_Result == result) { | |
| 176 wallMin = SkTMin(wallMin, fWallTimes[i]); | |
| 177 truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]); | |
| 178 cpuMin = SkTMin(cpuMin, fCpuTimes[i]); | |
| 179 truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]); | |
| 180 gpuMin = SkTMin(gpuMin, fGpuTimes[i]); | |
| 181 } else { | |
| 182 SkASSERT(kAvg_Result == result); | |
| 183 wallSum += fWallTimes[i]; | |
| 184 truncWallSum += fTruncatedWallTimes[i]; | |
| 185 cpuSum += fCpuTimes[i]; | |
| 186 truncCpuSum += fTruncatedCpuTimes[i]; | |
| 187 } | |
| 188 | |
| 189 // We always track the GPU sum because whether it is non-zero indicates
if valid gpu times | |
| 190 // were recorded at all. | |
| 191 gpuSum += fGpuTimes[i]; | |
| 192 } | |
| 193 | |
| 194 if (kMin_Result == result) { | |
| 195 wallNode.append(wallMin / itersPerTiming); | |
| 196 truncWall.append(truncWallMin / itersPerTiming); | |
| 197 cpuNode.append(cpuMin / itersPerTiming); | |
| 198 truncCpu.append(truncCpuMin / itersPerTiming); | |
| 199 gpuNode.append(gpuMin / itersPerTiming); | |
| 200 } else if (kAvg_Result == result) { | |
| 201 int divisor = numTimings * itersPerTiming; | |
| 202 wallNode.append(wallSum / divisor); | |
| 203 truncWall.append(truncWallSum / divisor); | |
| 204 cpuNode.append(cpuSum / divisor); | |
| 205 truncCpu.append(truncCpuSum / divisor); | |
| 206 gpuNode.append(gpuSum / divisor); | |
| 207 } | |
| 208 | |
| 209 if (timerFlags & kWall_Flag) { | |
| 210 dataNode["wall"] = wallNode; | |
| 211 } | |
| 212 if (timerFlags & kTruncatedWall_Flag) { | |
| 213 dataNode["truncWall"] = truncWall; | |
| 214 } | |
| 215 if (timerFlags & kCpu_Flag) { | |
| 216 dataNode["cpu"] = cpuNode; | |
| 217 } | |
| 218 if (timerFlags & kTruncatedCpu_Flag) { | |
| 219 dataNode["trucCpu"] = truncCpu; | |
| 220 } | |
| 221 if ((timerFlags & kGpu_Flag) && gpuSum > 0) { | |
| 222 dataNode["gpu"] = gpuNode; | |
| 223 } | |
| 224 return dataNode; | |
| 225 } | |
| OLD | NEW |