OLD | NEW |
---|---|
1 //===- subzero/src/IceTimerTree.cpp - Pass timer defs ---------------------===// | 1 //===- subzero/src/IceTimerTree.cpp - Pass timer defs ---------------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 Node.Time = 0; | 221 Node.Time = 0; |
222 Node.UpdateCount = 0; | 222 Node.UpdateCount = 0; |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 namespace { | 226 namespace { |
227 | 227 |
228 using DumpMapType = std::multimap<double, std::string>; | 228 using DumpMapType = std::multimap<double, std::string>; |
229 | 229 |
230 // Dump the Map items in reverse order of their time contribution. | 230 // Dump the Map items in reverse order of their time contribution. |
231 void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) { | 231 void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime, |
John
2016/04/08 21:04:31
TotalTime should be a local...
Jim Stichnoth
2016/04/08 21:09:48
Actually if AddPercents==false, then TotalTime nee
| |
232 bool AddPercents) { | |
232 if (!BuildDefs::timers()) | 233 if (!BuildDefs::timers()) |
233 return; | 234 return; |
235 if (AddPercents) { | |
236 // Recompute TotalTime as the sum of the individual times. This is because | |
237 // the individual times generally add up to less than 100% because of timer | |
238 // overhead. | |
239 TotalTime = 0; | |
240 for (auto &I : Map) { | |
John
2016/04/08 21:04:32
const
Jim Stichnoth
2016/04/08 21:09:47
Done.
| |
241 TotalTime += I.first; | |
242 } | |
243 } | |
244 double Sum = 0; | |
234 for (auto &I : reverse_range(Map)) { | 245 for (auto &I : reverse_range(Map)) { |
235 Str << llvm::format(" %10.6f (%4.1f%%): ", I.first, | 246 Sum += I.first; |
236 I.first * 100 / TotalTime) << I.second << "\n"; | 247 if (AddPercents) { |
248 Str << llvm::format(" %10.6f %4.1f%% %5.1f%% ", I.first, | |
249 I.first * 100 / TotalTime, Sum * 100 / TotalTime) | |
250 << I.second << "\n"; | |
251 } else { | |
252 Str << llvm::format(" %10.6f %4.1f%% ", I.first, | |
253 I.first * 100 / TotalTime) << I.second << "\n"; | |
254 } | |
237 } | 255 } |
238 } | 256 } |
239 | 257 |
240 // Write a printf() format string into Buf[], in the format "[%5lu] ", where | |
241 // "5" is actually the number of digits in MaxVal. E.g., | |
242 // MaxVal=0 ==> "[%1lu] " | |
243 // MaxVal=5 ==> "[%1lu] " | |
244 // MaxVal=9876 ==> "[%4lu] " | |
245 void makePrintfFormatString(char *Buf, size_t BufLen, size_t MaxVal) { | |
246 if (!BuildDefs::timers()) | |
247 return; | |
248 int NumDigits = 0; | |
249 do { | |
250 ++NumDigits; | |
251 MaxVal /= 10; | |
252 } while (MaxVal); | |
253 snprintf(Buf, BufLen, "[%%%dlu] ", NumDigits); | |
254 } | |
255 | |
256 } // end of anonymous namespace | 258 } // end of anonymous namespace |
257 | 259 |
258 void TimerStack::dump(Ostream &Str, bool DumpCumulative) { | 260 void TimerStack::dump(Ostream &Str, bool DumpCumulative) { |
259 if (!BuildDefs::timers()) | 261 if (!BuildDefs::timers()) |
260 return; | 262 return; |
261 constexpr bool UpdateCounts = true; | 263 constexpr bool UpdateCounts = true; |
262 update(UpdateCounts); | 264 update(UpdateCounts); |
263 double TotalTime = LastTimestamp - FirstTimestamp; | 265 double TotalTime = LastTimestamp - FirstTimestamp; |
264 assert(TotalTime); | 266 assert(TotalTime); |
265 char FmtString[30], PrefixStr[30]; | 267 char PrefixStr[30]; |
266 if (DumpCumulative) { | 268 if (DumpCumulative) { |
267 Str << Name << " - Cumulative times:\n"; | 269 Str << Name << " - Cumulative times:\n"; |
John
2016/04/08 21:04:31
Suggestion: don't end the Str << in the previous l
Jim Stichnoth
2016/04/08 21:09:47
Done.
| |
268 size_t MaxInternalCount = 0; | 270 Str << " Seconds Pct EventCnt TimerPath\n"; |
269 for (TimerTreeNode &Node : Nodes) | |
270 MaxInternalCount = std::max(MaxInternalCount, Node.UpdateCount); | |
271 makePrintfFormatString(FmtString, llvm::array_lengthof(FmtString), | |
272 MaxInternalCount); | |
273 | |
274 DumpMapType CumulativeMap; | 271 DumpMapType CumulativeMap; |
275 for (TTindex i = 1; i < Nodes.size(); ++i) { | 272 for (TTindex i = 1; i < Nodes.size(); ++i) { |
276 TTindex Prefix = i; | 273 TTindex Prefix = i; |
277 std::string Suffix = ""; | 274 std::string Suffix = ""; |
278 while (Prefix) { | 275 while (Prefix) { |
279 if (Suffix.empty()) | 276 if (Suffix.empty()) |
280 Suffix = IDs[Nodes[Prefix].Interior]; | 277 Suffix = IDs[Nodes[Prefix].Interior]; |
281 else | 278 else |
282 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; | 279 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; |
283 assert(Nodes[Prefix].Parent < Prefix); | 280 assert(Nodes[Prefix].Parent < Prefix); |
284 Prefix = Nodes[Prefix].Parent; | 281 Prefix = Nodes[Prefix].Parent; |
285 } | 282 } |
286 snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), FmtString, | 283 snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), "%9lu ", |
287 Nodes[i].UpdateCount); | 284 Nodes[i].UpdateCount); |
288 CumulativeMap.insert(std::make_pair(Nodes[i].Time, PrefixStr + Suffix)); | 285 CumulativeMap.insert(std::make_pair(Nodes[i].Time, PrefixStr + Suffix)); |
289 } | 286 } |
290 dumpHelper(Str, CumulativeMap, TotalTime); | 287 constexpr bool NoAddPercents = false; |
288 dumpHelper(Str, CumulativeMap, TotalTime, NoAddPercents); | |
291 } | 289 } |
292 Str << Name << " - Flat times:\n"; | 290 Str << Name << " - Flat times:\n"; |
293 size_t MaxLeafCount = 0; | 291 Str << " Seconds Pct CumPct EventCnt TimerName\n"; |
294 for (size_t Count : LeafCounts) | |
295 MaxLeafCount = std::max(MaxLeafCount, Count); | |
296 makePrintfFormatString(FmtString, llvm::array_lengthof(FmtString), | |
297 MaxLeafCount); | |
298 DumpMapType FlatMap; | 292 DumpMapType FlatMap; |
299 for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { | 293 for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { |
300 if (LeafCounts[i]) { | 294 if (LeafCounts[i]) { |
301 snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), FmtString, | 295 snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), "%9lu ", |
302 LeafCounts[i]); | 296 LeafCounts[i]); |
303 FlatMap.insert(std::make_pair(LeafTimes[i], PrefixStr + IDs[i])); | 297 FlatMap.insert(std::make_pair(LeafTimes[i], PrefixStr + IDs[i])); |
304 } | 298 } |
305 } | 299 } |
306 dumpHelper(Str, FlatMap, TotalTime); | 300 constexpr bool AddPercents = true; |
301 dumpHelper(Str, FlatMap, TotalTime, AddPercents); | |
307 Str << "Number of timer updates: " << StateChangeCount << "\n"; | 302 Str << "Number of timer updates: " << StateChangeCount << "\n"; |
308 } | 303 } |
309 | 304 |
310 double TimerStack::timestamp() { | 305 double TimerStack::timestamp() { |
311 // TODO: Implement in terms of std::chrono for C++11. | 306 // TODO: Implement in terms of std::chrono for C++11. |
312 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); | 307 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); |
313 } | 308 } |
314 | 309 |
315 } // end of namespace Ice | 310 } // end of namespace Ice |
OLD | NEW |