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 12 matching lines...) Expand all Loading... |
23 #endif // __clang__ | 23 #endif // __clang__ |
24 | 24 |
25 #include "llvm/Support/Timer.h" | 25 #include "llvm/Support/Timer.h" |
26 | 26 |
27 #ifdef __clang__ | 27 #ifdef __clang__ |
28 #pragma clang diagnostic pop | 28 #pragma clang diagnostic pop |
29 #endif // __clang__ | 29 #endif // __clang__ |
30 | 30 |
31 namespace Ice { | 31 namespace Ice { |
32 | 32 |
33 TimerStack::TimerStack(const IceString &Name) | 33 TimerStack::TimerStack(const std::string &Name) |
34 : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp) { | 34 : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp) { |
35 if (!BuildDefs::timers()) | 35 if (!BuildDefs::timers()) |
36 return; | 36 return; |
37 Nodes.resize(1); // Reserve Nodes[0] for the root node (sentinel). | 37 Nodes.resize(1); // Reserve Nodes[0] for the root node (sentinel). |
38 IDs.resize(TT__num); | 38 IDs.resize(TT__num); |
39 LeafTimes.resize(TT__num); | 39 LeafTimes.resize(TT__num); |
40 LeafCounts.resize(TT__num); | 40 LeafCounts.resize(TT__num); |
41 #define STR(s) #s | 41 #define STR(s) #s |
42 #define X(tag) \ | 42 #define X(tag) \ |
43 IDs[TT_##tag] = STR(tag); \ | 43 IDs[TT_##tag] = STR(tag); \ |
44 IDsIndex[STR(tag)] = TT_##tag; | 44 IDsIndex[STR(tag)] = TT_##tag; |
45 TIMERTREE_TABLE; | 45 TIMERTREE_TABLE; |
46 #undef X | 46 #undef X |
47 #undef STR | 47 #undef STR |
48 } | 48 } |
49 | 49 |
50 // Returns the unique timer ID for the given Name, creating a new ID if needed. | 50 // Returns the unique timer ID for the given Name, creating a new ID if needed. |
51 TimerIdT TimerStack::getTimerID(const IceString &Name) { | 51 TimerIdT TimerStack::getTimerID(const std::string &Name) { |
52 if (!BuildDefs::timers()) | 52 if (!BuildDefs::timers()) |
53 return 0; | 53 return 0; |
54 if (IDsIndex.find(Name) == IDsIndex.end()) { | 54 if (IDsIndex.find(Name) == IDsIndex.end()) { |
55 IDsIndex[Name] = IDs.size(); | 55 IDsIndex[Name] = IDs.size(); |
56 IDs.push_back(Name); | 56 IDs.push_back(Name); |
57 LeafTimes.push_back(decltype(LeafTimes)::value_type()); | 57 LeafTimes.push_back(decltype(LeafTimes)::value_type()); |
58 LeafCounts.push_back(decltype(LeafCounts)::value_type()); | 58 LeafCounts.push_back(decltype(LeafCounts)::value_type()); |
59 } | 59 } |
60 return IDsIndex[Name]; | 60 return IDsIndex[Name]; |
61 } | 61 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 LeafTimes.assign(LeafTimes.size(), 0); | 217 LeafTimes.assign(LeafTimes.size(), 0); |
218 LeafCounts.assign(LeafCounts.size(), 0); | 218 LeafCounts.assign(LeafCounts.size(), 0); |
219 for (TimerTreeNode &Node : Nodes) { | 219 for (TimerTreeNode &Node : Nodes) { |
220 Node.Time = 0; | 220 Node.Time = 0; |
221 Node.UpdateCount = 0; | 221 Node.UpdateCount = 0; |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 namespace { | 225 namespace { |
226 | 226 |
227 using DumpMapType = std::multimap<double, IceString>; | 227 using DumpMapType = std::multimap<double, std::string>; |
228 | 228 |
229 // Dump the Map items in reverse order of their time contribution. | 229 // Dump the Map items in reverse order of their time contribution. |
230 void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) { | 230 void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) { |
231 if (!BuildDefs::timers()) | 231 if (!BuildDefs::timers()) |
232 return; | 232 return; |
233 for (auto &I : reverse_range(Map)) { | 233 for (auto &I : reverse_range(Map)) { |
234 char buf[80]; | 234 char buf[80]; |
235 snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I.first, | 235 snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I.first, |
236 I.first * 100 / TotalTime); | 236 I.first * 100 / TotalTime); |
237 Str << buf << I.second << "\n"; | 237 Str << buf << I.second << "\n"; |
(...skipping 30 matching lines...) Expand all Loading... |
268 Str << Name << " - Cumulative times:\n"; | 268 Str << Name << " - Cumulative times:\n"; |
269 size_t MaxInternalCount = 0; | 269 size_t MaxInternalCount = 0; |
270 for (TimerTreeNode &Node : Nodes) | 270 for (TimerTreeNode &Node : Nodes) |
271 MaxInternalCount = std::max(MaxInternalCount, Node.UpdateCount); | 271 MaxInternalCount = std::max(MaxInternalCount, Node.UpdateCount); |
272 makePrintfFormatString(FmtString, llvm::array_lengthof(FmtString), | 272 makePrintfFormatString(FmtString, llvm::array_lengthof(FmtString), |
273 MaxInternalCount); | 273 MaxInternalCount); |
274 | 274 |
275 DumpMapType CumulativeMap; | 275 DumpMapType CumulativeMap; |
276 for (TTindex i = 1; i < Nodes.size(); ++i) { | 276 for (TTindex i = 1; i < Nodes.size(); ++i) { |
277 TTindex Prefix = i; | 277 TTindex Prefix = i; |
278 IceString Suffix = ""; | 278 std::string Suffix = ""; |
279 while (Prefix) { | 279 while (Prefix) { |
280 if (Suffix.empty()) | 280 if (Suffix.empty()) |
281 Suffix = IDs[Nodes[Prefix].Interior]; | 281 Suffix = IDs[Nodes[Prefix].Interior]; |
282 else | 282 else |
283 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; | 283 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; |
284 assert(Nodes[Prefix].Parent < Prefix); | 284 assert(Nodes[Prefix].Parent < Prefix); |
285 Prefix = Nodes[Prefix].Parent; | 285 Prefix = Nodes[Prefix].Parent; |
286 } | 286 } |
287 snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), FmtString, | 287 snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), FmtString, |
288 Nodes[i].UpdateCount); | 288 Nodes[i].UpdateCount); |
(...skipping 18 matching lines...) Expand all Loading... |
307 dumpHelper(Str, FlatMap, TotalTime); | 307 dumpHelper(Str, FlatMap, TotalTime); |
308 Str << "Number of timer updates: " << StateChangeCount << "\n"; | 308 Str << "Number of timer updates: " << StateChangeCount << "\n"; |
309 } | 309 } |
310 | 310 |
311 double TimerStack::timestamp() { | 311 double TimerStack::timestamp() { |
312 // TODO: Implement in terms of std::chrono for C++11. | 312 // TODO: Implement in terms of std::chrono for C++11. |
313 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); | 313 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); |
314 } | 314 } |
315 | 315 |
316 } // end of namespace Ice | 316 } // end of namespace Ice |
OLD | NEW |