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 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 // At a state change (e.g. push or pop), updates the flat and | 75 // At a state change (e.g. push or pop), updates the flat and |
76 // cumulative timings for everything on the timer stack. | 76 // cumulative timings for everything on the timer stack. |
77 void TimerStack::update() { | 77 void TimerStack::update() { |
78 ++StateChangeCount; | 78 ++StateChangeCount; |
79 // Whenever the stack is about to change, we grab the time delta | 79 // Whenever the stack is about to change, we grab the time delta |
80 // since the last change and add it to all active cumulative | 80 // since the last change and add it to all active cumulative |
81 // elements and to the flat element for the top of the stack. | 81 // elements and to the flat element for the top of the stack. |
82 double Current = timestamp(); | 82 double Current = timestamp(); |
83 double Delta = Current - LastTimestamp; | 83 double Delta = Current - LastTimestamp; |
84 LastTimestamp = Current; | |
85 if (StackTop) { | 84 if (StackTop) { |
86 TimerIdT Leaf = Nodes[StackTop].Interior; | 85 TimerIdT Leaf = Nodes[StackTop].Interior; |
87 if (Leaf >= LeafTimes.size()) | 86 if (Leaf >= LeafTimes.size()) |
88 LeafTimes.resize(Leaf + 1); | 87 LeafTimes.resize(Leaf + 1); |
89 LeafTimes[Leaf] += Delta; | 88 LeafTimes[Leaf] += Delta; |
90 } | 89 } |
91 TTindex Prefix = StackTop; | 90 TTindex Prefix = StackTop; |
92 while (Prefix) { | 91 while (Prefix) { |
93 Nodes[Prefix].Time += Delta; | 92 Nodes[Prefix].Time += Delta; |
94 TTindex Next = Nodes[Prefix].Parent; | 93 TTindex Next = Nodes[Prefix].Parent; |
95 assert(Next < Prefix); | 94 assert(Next < Prefix); |
96 Prefix = Next; | 95 Prefix = Next; |
97 } | 96 } |
| 97 // Capture the next timestamp *after* the updates are finished. |
| 98 // This minimizes how much the timer can perturb the reported |
| 99 // timing. The numbers may not sum to 100%, and the missing amount |
| 100 // is indicative of the overhead of timing. |
| 101 LastTimestamp = timestamp(); |
98 } | 102 } |
99 | 103 |
100 void TimerStack::reset() { | 104 void TimerStack::reset() { |
101 StateChangeCount = 0; | 105 StateChangeCount = 0; |
102 FirstTimestamp = LastTimestamp = timestamp(); | 106 FirstTimestamp = LastTimestamp = timestamp(); |
103 LeafTimes.assign(LeafTimes.size(), 0); | 107 LeafTimes.assign(LeafTimes.size(), 0); |
104 for (TimerTreeNode &Node : Nodes) { | 108 for (TimerTreeNode &Node : Nodes) { |
105 Node.Time = 0; | 109 Node.Time = 0; |
106 } | 110 } |
107 } | 111 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 dumpHelper(Str, FlatMap, TotalTime); | 157 dumpHelper(Str, FlatMap, TotalTime); |
154 Str << "Number of timer updates: " << StateChangeCount << "\n"; | 158 Str << "Number of timer updates: " << StateChangeCount << "\n"; |
155 } | 159 } |
156 | 160 |
157 double TimerStack::timestamp() { | 161 double TimerStack::timestamp() { |
158 // TODO: Implement in terms of std::chrono for C++11. | 162 // TODO: Implement in terms of std::chrono for C++11. |
159 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); | 163 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); |
160 } | 164 } |
161 | 165 |
162 } // end of namespace Ice | 166 } // end of namespace Ice |
OLD | NEW |