Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTimerTree.cpp - Pass timer defs ---------------------===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame^] | 11 | /// \brief Defines the TimerTree class, which tracks flat and cumulative |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 12 | /// execution time collection of call chains. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 13 | /// |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 16 | #include "IceTimerTree.h" |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 17 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 18 | #include "IceDefs.h" |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 19 | |
| 20 | #pragma clang diagnostic push |
| 21 | #pragma clang diagnostic ignored "-Wunused-parameter" |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 22 | #include "llvm/Support/Timer.h" |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 23 | #pragma clang diagnostic pop |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 24 | |
| 25 | namespace Ice { |
| 26 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 27 | TimerStack::TimerStack(const IceString &Name) |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 28 | : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 29 | if (!BuildDefs::dump()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 30 | return; |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 31 | Nodes.resize(1); // Reserve Nodes[0] for the root node (sentinel). |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 32 | IDs.resize(TT__num); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 33 | LeafTimes.resize(TT__num); |
| 34 | LeafCounts.resize(TT__num); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 35 | #define STR(s) #s |
| 36 | #define X(tag) \ |
| 37 | IDs[TT_##tag] = STR(tag); \ |
| 38 | IDsIndex[STR(tag)] = TT_##tag; |
| 39 | TIMERTREE_TABLE; |
| 40 | #undef X |
| 41 | #undef STR |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 44 | // Returns the unique timer ID for the given Name, creating a new ID if needed. |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 45 | TimerIdT TimerStack::getTimerID(const IceString &Name) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 46 | if (!BuildDefs::dump()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 47 | return 0; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 48 | if (IDsIndex.find(Name) == IDsIndex.end()) { |
| 49 | IDsIndex[Name] = IDs.size(); |
| 50 | IDs.push_back(Name); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 51 | LeafTimes.push_back(decltype(LeafTimes)::value_type()); |
| 52 | LeafCounts.push_back(decltype(LeafCounts)::value_type()); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 53 | } |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 54 | return IDsIndex[Name]; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 57 | // Creates a mapping from TimerIdT (leaf) values in the Src timer stack into |
| 58 | // TimerIdT values in this timer stack. Creates new entries in this timer stack |
| 59 | // as needed. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 60 | TimerStack::TranslationType |
| 61 | TimerStack::translateIDsFrom(const TimerStack &Src) { |
| 62 | size_t Size = Src.IDs.size(); |
| 63 | TranslationType Mapping(Size); |
| 64 | for (TimerIdT i = 0; i < Size; ++i) { |
| 65 | Mapping[i] = getTimerID(Src.IDs[i]); |
| 66 | } |
| 67 | return Mapping; |
| 68 | } |
| 69 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 70 | // Merges two timer stacks, by combining and summing corresponding entries. |
| 71 | // This timer stack is updated from Src. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 72 | void TimerStack::mergeFrom(const TimerStack &Src) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 73 | if (!BuildDefs::dump()) |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 74 | return; |
| 75 | TranslationType Mapping = translateIDsFrom(Src); |
| 76 | TTindex SrcIndex = 0; |
| 77 | for (const TimerTreeNode &SrcNode : Src.Nodes) { |
| 78 | // The first node is reserved as a sentinel, so avoid it. |
| 79 | if (SrcIndex > 0) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 80 | // Find the full path to the Src node, translated to path components |
| 81 | // corresponding to this timer stack. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 82 | PathType MyPath = Src.getPath(SrcIndex, Mapping); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 83 | // Find a node in this timer stack corresponding to the given path, |
| 84 | // creating new interior nodes as necessary. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 85 | TTindex MyIndex = findPath(MyPath); |
| 86 | Nodes[MyIndex].Time += SrcNode.Time; |
| 87 | Nodes[MyIndex].UpdateCount += SrcNode.UpdateCount; |
| 88 | } |
| 89 | ++SrcIndex; |
| 90 | } |
| 91 | for (TimerIdT i = 0; i < Src.LeafTimes.size(); ++i) { |
| 92 | LeafTimes[Mapping[i]] += Src.LeafTimes[i]; |
| 93 | LeafCounts[Mapping[i]] += Src.LeafCounts[i]; |
| 94 | } |
| 95 | StateChangeCount += Src.StateChangeCount; |
| 96 | } |
| 97 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 98 | // Constructs a path consisting of the sequence of leaf values leading to a |
| 99 | // given node, with the Mapping translation applied to the leaf values. The |
| 100 | // path ends up being in "reverse" order, i.e. from leaf to root. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 101 | TimerStack::PathType TimerStack::getPath(TTindex Index, |
| 102 | const TranslationType &Mapping) const { |
| 103 | PathType Path; |
| 104 | while (Index) { |
| 105 | Path.push_back(Mapping[Nodes[Index].Interior]); |
| 106 | assert(Nodes[Index].Parent < Index); |
| 107 | Index = Nodes[Index].Parent; |
| 108 | } |
| 109 | return Path; |
| 110 | } |
| 111 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 112 | // Given a parent node and a leaf ID, returns the index of the parent's child |
| 113 | // ID, creating a new node for the child as necessary. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 114 | TimerStack::TTindex TimerStack::getChildIndex(TimerStack::TTindex Parent, |
| 115 | TimerIdT ID) { |
| 116 | if (Nodes[Parent].Children.size() <= ID) |
| 117 | Nodes[Parent].Children.resize(ID + 1); |
| 118 | if (Nodes[Parent].Children[ID] == 0) { |
| 119 | TTindex Size = Nodes.size(); |
| 120 | Nodes[Parent].Children[ID] = Size; |
| 121 | Nodes.resize(Size + 1); |
| 122 | Nodes[Size].Parent = Parent; |
| 123 | Nodes[Size].Interior = ID; |
| 124 | } |
| 125 | return Nodes[Parent].Children[ID]; |
| 126 | } |
| 127 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 128 | // Finds a node in the timer stack corresponding to the given path, creating |
| 129 | // new interior nodes as necessary. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 130 | TimerStack::TTindex TimerStack::findPath(const PathType &Path) { |
| 131 | TTindex CurIndex = 0; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 132 | // The path is in reverse order (leaf to root), so it needs to be followed in |
| 133 | // reverse. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 134 | for (TTindex Index : reverse_range(Path)) { |
| 135 | CurIndex = getChildIndex(CurIndex, Index); |
| 136 | } |
| 137 | assert(CurIndex); // shouldn't be the sentinel node |
| 138 | return CurIndex; |
| 139 | } |
| 140 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 141 | // Pushes a new marker onto the timer stack. |
| 142 | void TimerStack::push(TimerIdT ID) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 143 | if (!BuildDefs::dump()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 144 | return; |
Jim Stichnoth | 5bff61c | 2015-10-28 09:26:00 -0700 | [diff] [blame] | 145 | constexpr bool UpdateCounts = false; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 146 | update(UpdateCounts); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 147 | StackTop = getChildIndex(StackTop, ID); |
| 148 | assert(StackTop); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 151 | // Pops the top marker from the timer stack. Validates via assert() that the |
| 152 | // expected marker is popped. |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 153 | void TimerStack::pop(TimerIdT ID) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 154 | if (!BuildDefs::dump()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 155 | return; |
Jim Stichnoth | 5bff61c | 2015-10-28 09:26:00 -0700 | [diff] [blame] | 156 | constexpr bool UpdateCounts = true; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 157 | update(UpdateCounts); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 158 | assert(StackTop); |
| 159 | assert(Nodes[StackTop].Parent < StackTop); |
| 160 | // Verify that the expected ID is being popped. |
| 161 | assert(Nodes[StackTop].Interior == ID); |
| 162 | (void)ID; |
| 163 | // Verify that the parent's child points to the current stack top. |
| 164 | assert(Nodes[Nodes[StackTop].Parent].Children[ID] == StackTop); |
| 165 | StackTop = Nodes[StackTop].Parent; |
| 166 | } |
| 167 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 168 | // At a state change (e.g. push or pop), updates the flat and cumulative |
| 169 | // timings for everything on the timer stack. |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 170 | void TimerStack::update(bool UpdateCounts) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 171 | if (!BuildDefs::dump()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 172 | return; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 173 | ++StateChangeCount; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 174 | // Whenever the stack is about to change, we grab the time delta since the |
| 175 | // last change and add it to all active cumulative elements and to the flat |
| 176 | // element for the top of the stack. |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 177 | double Current = timestamp(); |
| 178 | double Delta = Current - LastTimestamp; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 179 | if (StackTop) { |
| 180 | TimerIdT Leaf = Nodes[StackTop].Interior; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 181 | if (Leaf >= LeafTimes.size()) { |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 182 | LeafTimes.resize(Leaf + 1); |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 183 | LeafCounts.resize(Leaf + 1); |
| 184 | } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 185 | LeafTimes[Leaf] += Delta; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 186 | if (UpdateCounts) |
| 187 | ++LeafCounts[Leaf]; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 188 | } |
| 189 | TTindex Prefix = StackTop; |
| 190 | while (Prefix) { |
| 191 | Nodes[Prefix].Time += Delta; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 192 | // Only update a leaf node count, not the internal node counts. |
| 193 | if (UpdateCounts && Prefix == StackTop) |
| 194 | ++Nodes[Prefix].UpdateCount; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 195 | TTindex Next = Nodes[Prefix].Parent; |
| 196 | assert(Next < Prefix); |
| 197 | Prefix = Next; |
| 198 | } |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 199 | // Capture the next timestamp *after* the updates are finished. This |
| 200 | // minimizes how much the timer can perturb the reported timing. The numbers |
| 201 | // may not sum to 100%, and the missing amount is indicative of the overhead |
| 202 | // of timing. |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 203 | LastTimestamp = timestamp(); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 206 | void TimerStack::reset() { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 207 | if (!BuildDefs::dump()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 208 | return; |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 209 | StateChangeCount = 0; |
| 210 | FirstTimestamp = LastTimestamp = timestamp(); |
| 211 | LeafTimes.assign(LeafTimes.size(), 0); |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 212 | LeafCounts.assign(LeafCounts.size(), 0); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 213 | for (TimerTreeNode &Node : Nodes) { |
| 214 | Node.Time = 0; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 215 | Node.UpdateCount = 0; |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 219 | namespace { |
| 220 | |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 221 | using DumpMapType = std::multimap<double, IceString>; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 222 | |
| 223 | // Dump the Map items in reverse order of their time contribution. |
| 224 | void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 225 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 226 | return; |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 227 | for (auto &I : reverse_range(Map)) { |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 228 | char buf[80]; |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 229 | snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I.first, |
| 230 | I.first * 100 / TotalTime); |
| 231 | Str << buf << I.second << "\n"; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 235 | // Write a printf() format string into Buf[], in the format "[%5lu] ", where |
| 236 | // "5" is actually the number of digits in MaxVal. E.g., |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 237 | // MaxVal=0 ==> "[%1lu] " |
| 238 | // MaxVal=5 ==> "[%1lu] " |
| 239 | // MaxVal=9876 ==> "[%4lu] " |
| 240 | void makePrintfFormatString(char *Buf, size_t BufLen, size_t MaxVal) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 241 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 242 | return; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 243 | int NumDigits = 0; |
| 244 | do { |
| 245 | ++NumDigits; |
| 246 | MaxVal /= 10; |
| 247 | } while (MaxVal); |
| 248 | snprintf(Buf, BufLen, "[%%%dlu] ", NumDigits); |
| 249 | } |
| 250 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 251 | } // end of anonymous namespace |
| 252 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 253 | void TimerStack::dump(Ostream &Str, bool DumpCumulative) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 254 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 255 | return; |
Jim Stichnoth | 5bff61c | 2015-10-28 09:26:00 -0700 | [diff] [blame] | 256 | constexpr bool UpdateCounts = true; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 257 | update(UpdateCounts); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 258 | double TotalTime = LastTimestamp - FirstTimestamp; |
| 259 | assert(TotalTime); |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 260 | char FmtString[30], PrefixStr[30]; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 261 | if (DumpCumulative) { |
| 262 | Str << Name << " - Cumulative times:\n"; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 263 | size_t MaxInternalCount = 0; |
| 264 | for (TimerTreeNode &Node : Nodes) |
| 265 | MaxInternalCount = std::max(MaxInternalCount, Node.UpdateCount); |
| 266 | makePrintfFormatString(FmtString, llvm::array_lengthof(FmtString), |
| 267 | MaxInternalCount); |
| 268 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 269 | DumpMapType CumulativeMap; |
| 270 | for (TTindex i = 1; i < Nodes.size(); ++i) { |
| 271 | TTindex Prefix = i; |
| 272 | IceString Suffix = ""; |
| 273 | while (Prefix) { |
| 274 | if (Suffix.empty()) |
| 275 | Suffix = IDs[Nodes[Prefix].Interior]; |
| 276 | else |
| 277 | Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; |
| 278 | assert(Nodes[Prefix].Parent < Prefix); |
| 279 | Prefix = Nodes[Prefix].Parent; |
| 280 | } |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 281 | snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), FmtString, |
| 282 | Nodes[i].UpdateCount); |
| 283 | CumulativeMap.insert(std::make_pair(Nodes[i].Time, PrefixStr + Suffix)); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 284 | } |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 285 | dumpHelper(Str, CumulativeMap, TotalTime); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 286 | } |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 287 | Str << Name << " - Flat times:\n"; |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 288 | size_t MaxLeafCount = 0; |
| 289 | for (size_t Count : LeafCounts) |
| 290 | MaxLeafCount = std::max(MaxLeafCount, Count); |
| 291 | makePrintfFormatString(FmtString, llvm::array_lengthof(FmtString), |
| 292 | MaxLeafCount); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 293 | DumpMapType FlatMap; |
| 294 | for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 295 | if (LeafCounts[i]) { |
| 296 | snprintf(PrefixStr, llvm::array_lengthof(PrefixStr), FmtString, |
| 297 | LeafCounts[i]); |
| 298 | FlatMap.insert(std::make_pair(LeafTimes[i], PrefixStr + IDs[i])); |
| 299 | } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 300 | } |
| 301 | dumpHelper(Str, FlatMap, TotalTime); |
| 302 | Str << "Number of timer updates: " << StateChangeCount << "\n"; |
| 303 | } |
| 304 | |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 305 | double TimerStack::timestamp() { |
| 306 | // TODO: Implement in terms of std::chrono for C++11. |
| 307 | return llvm::TimeRecord::getCurrentTime(false).getWallTime(); |
| 308 | } |
| 309 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 310 | } // end of namespace Ice |