Chromium Code Reviews| 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 // This file defines the TimerTree class, which tracks flat and | 10 // This file defines the TimerTree class, which tracks flat and |
| 11 // cumulative execution time collection of call chains. | 11 // cumulative execution time collection of call chains. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "llvm/Support/Timer.h" | 15 #include "llvm/Support/Timer.h" |
| 16 | 16 |
| 17 #include "IceDefs.h" | 17 #include "IceDefs.h" |
| 18 #include "IceTimerTree.h" | 18 #include "IceTimerTree.h" |
| 19 | 19 |
| 20 namespace Ice { | 20 namespace Ice { |
| 21 | 21 |
| 22 TimerStack::TimerStack(const IceString &Name) | 22 TimerStack::TimerStack(const IceString &Name) |
| 23 : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), | 23 : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), |
| 24 StateChangeCount(0), StackTop(0) { | 24 StateChangeCount(0), StackTop(0) { |
| 25 if (!ALLOW_DUMP) | |
| 26 return; | |
| 25 Nodes.resize(1); // Reserve Nodes[0] for the root node. | 27 Nodes.resize(1); // Reserve Nodes[0] for the root node. |
| 26 IDs.resize(TT__num); | 28 IDs.resize(TT__num); |
| 27 #define STR(s) #s | 29 #define STR(s) #s |
| 28 #define X(tag) \ | 30 #define X(tag) \ |
| 29 IDs[TT_##tag] = STR(tag); \ | 31 IDs[TT_##tag] = STR(tag); \ |
| 30 IDsIndex[STR(tag)] = TT_##tag; | 32 IDsIndex[STR(tag)] = TT_##tag; |
| 31 TIMERTREE_TABLE; | 33 TIMERTREE_TABLE; |
| 32 #undef X | 34 #undef X |
| 33 #undef STR | 35 #undef STR |
| 34 } | 36 } |
| 35 | 37 |
| 36 // Returns the unique timer ID for the given Name, creating a new ID | 38 // Returns the unique timer ID for the given Name, creating a new ID |
| 37 // if needed. | 39 // if needed. |
| 38 TimerIdT TimerStack::getTimerID(const IceString &Name) { | 40 TimerIdT TimerStack::getTimerID(const IceString &Name) { |
| 41 if (!ALLOW_DUMP) | |
| 42 return 0; | |
| 39 if (IDsIndex.find(Name) == IDsIndex.end()) { | 43 if (IDsIndex.find(Name) == IDsIndex.end()) { |
| 40 IDsIndex[Name] = IDs.size(); | 44 IDsIndex[Name] = IDs.size(); |
| 41 IDs.push_back(Name); | 45 IDs.push_back(Name); |
| 42 } | 46 } |
| 43 return IDsIndex[Name]; | 47 return IDsIndex[Name]; |
| 44 } | 48 } |
| 45 | 49 |
| 46 // Pushes a new marker onto the timer stack. | 50 // Pushes a new marker onto the timer stack. |
| 47 void TimerStack::push(TimerIdT ID) { | 51 void TimerStack::push(TimerIdT ID) { |
|
Karl
2014/12/08 21:08:01
Suggest adding quick cutoff here as well. That way
Jim Stichnoth
2014/12/08 21:33:57
Done.
| |
| 48 const bool UpdateCounts = false; | 52 const bool UpdateCounts = false; |
| 49 update(UpdateCounts); | 53 update(UpdateCounts); |
| 50 if (Nodes[StackTop].Children.size() <= ID) | 54 if (Nodes[StackTop].Children.size() <= ID) |
| 51 Nodes[StackTop].Children.resize(ID + 1); | 55 Nodes[StackTop].Children.resize(ID + 1); |
| 52 if (Nodes[StackTop].Children[ID] == 0) { | 56 if (Nodes[StackTop].Children[ID] == 0) { |
| 53 TTindex Size = Nodes.size(); | 57 TTindex Size = Nodes.size(); |
| 54 Nodes[StackTop].Children[ID] = Size; | 58 Nodes[StackTop].Children[ID] = Size; |
| 55 Nodes.resize(Size + 1); | 59 Nodes.resize(Size + 1); |
| 56 Nodes[Size].Parent = StackTop; | 60 Nodes[Size].Parent = StackTop; |
| 57 Nodes[Size].Interior = ID; | 61 Nodes[Size].Interior = ID; |
| 58 } | 62 } |
| 59 StackTop = Nodes[StackTop].Children[ID]; | 63 StackTop = Nodes[StackTop].Children[ID]; |
| 60 } | 64 } |
| 61 | 65 |
| 62 // Pop the top marker from the timer stack. Validates via assert() | 66 // Pop the top marker from the timer stack. Validates via assert() |
| 63 // that the expected marker is popped. | 67 // that the expected marker is popped. |
| 64 void TimerStack::pop(TimerIdT ID) { | 68 void TimerStack::pop(TimerIdT ID) { |
|
Karl
2014/12/08 21:08:01
Same here.
Jim Stichnoth
2014/12/08 21:33:57
Done.
| |
| 65 const bool UpdateCounts = true; | 69 const bool UpdateCounts = true; |
| 66 update(UpdateCounts); | 70 update(UpdateCounts); |
| 67 assert(StackTop); | 71 assert(StackTop); |
| 68 assert(Nodes[StackTop].Parent < StackTop); | 72 assert(Nodes[StackTop].Parent < StackTop); |
| 69 // Verify that the expected ID is being popped. | 73 // Verify that the expected ID is being popped. |
| 70 assert(Nodes[StackTop].Interior == ID); | 74 assert(Nodes[StackTop].Interior == ID); |
| 71 (void)ID; | 75 (void)ID; |
| 72 // Verify that the parent's child points to the current stack top. | 76 // Verify that the parent's child points to the current stack top. |
| 73 assert(Nodes[Nodes[StackTop].Parent].Children[ID] == StackTop); | 77 assert(Nodes[Nodes[StackTop].Parent].Children[ID] == StackTop); |
| 74 StackTop = Nodes[StackTop].Parent; | 78 StackTop = Nodes[StackTop].Parent; |
| 75 } | 79 } |
| 76 | 80 |
| 77 // At a state change (e.g. push or pop), updates the flat and | 81 // At a state change (e.g. push or pop), updates the flat and |
| 78 // cumulative timings for everything on the timer stack. | 82 // cumulative timings for everything on the timer stack. |
| 79 void TimerStack::update(bool UpdateCounts) { | 83 void TimerStack::update(bool UpdateCounts) { |
|
Karl
2014/12/08 21:08:01
Same here.
Jim Stichnoth
2014/12/08 21:33:57
Done.
| |
| 80 ++StateChangeCount; | 84 ++StateChangeCount; |
| 81 // Whenever the stack is about to change, we grab the time delta | 85 // Whenever the stack is about to change, we grab the time delta |
| 82 // since the last change and add it to all active cumulative | 86 // since the last change and add it to all active cumulative |
| 83 // elements and to the flat element for the top of the stack. | 87 // elements and to the flat element for the top of the stack. |
| 84 double Current = timestamp(); | 88 double Current = timestamp(); |
| 85 double Delta = Current - LastTimestamp; | 89 double Delta = Current - LastTimestamp; |
| 86 if (StackTop) { | 90 if (StackTop) { |
| 87 TimerIdT Leaf = Nodes[StackTop].Interior; | 91 TimerIdT Leaf = Nodes[StackTop].Interior; |
| 88 if (Leaf >= LeafTimes.size()) { | 92 if (Leaf >= LeafTimes.size()) { |
| 89 LeafTimes.resize(Leaf + 1); | 93 LeafTimes.resize(Leaf + 1); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 103 assert(Next < Prefix); | 107 assert(Next < Prefix); |
| 104 Prefix = Next; | 108 Prefix = Next; |
| 105 } | 109 } |
| 106 // Capture the next timestamp *after* the updates are finished. | 110 // Capture the next timestamp *after* the updates are finished. |
| 107 // This minimizes how much the timer can perturb the reported | 111 // This minimizes how much the timer can perturb the reported |
| 108 // timing. The numbers may not sum to 100%, and the missing amount | 112 // timing. The numbers may not sum to 100%, and the missing amount |
| 109 // is indicative of the overhead of timing. | 113 // is indicative of the overhead of timing. |
| 110 LastTimestamp = timestamp(); | 114 LastTimestamp = timestamp(); |
| 111 } | 115 } |
| 112 | 116 |
| 113 void TimerStack::reset() { | 117 void TimerStack::reset() { |
|
Karl
2014/12/08 21:08:01
Same here.
Jim Stichnoth
2014/12/08 21:33:57
Done.
| |
| 114 StateChangeCount = 0; | 118 StateChangeCount = 0; |
| 115 FirstTimestamp = LastTimestamp = timestamp(); | 119 FirstTimestamp = LastTimestamp = timestamp(); |
| 116 LeafTimes.assign(LeafTimes.size(), 0); | 120 LeafTimes.assign(LeafTimes.size(), 0); |
| 117 LeafCounts.assign(LeafCounts.size(), 0); | 121 LeafCounts.assign(LeafCounts.size(), 0); |
| 118 for (TimerTreeNode &Node : Nodes) { | 122 for (TimerTreeNode &Node : Nodes) { |
| 119 Node.Time = 0; | 123 Node.Time = 0; |
| 120 Node.UpdateCount = 0; | 124 Node.UpdateCount = 0; |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 dumpHelper(Str, FlatMap, TotalTime); | 211 dumpHelper(Str, FlatMap, TotalTime); |
| 208 Str << "Number of timer updates: " << StateChangeCount << "\n"; | 212 Str << "Number of timer updates: " << StateChangeCount << "\n"; |
| 209 } | 213 } |
| 210 | 214 |
| 211 double TimerStack::timestamp() { | 215 double TimerStack::timestamp() { |
| 212 // TODO: Implement in terms of std::chrono for C++11. | 216 // TODO: Implement in terms of std::chrono for C++11. |
| 213 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); | 217 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); |
| 214 } | 218 } |
| 215 | 219 |
| 216 } // end of namespace Ice | 220 } // end of namespace Ice |
| OLD | NEW |