| 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 std::vector<IceString> TimerStack::IDs; | 22 std::vector<IceString> TimerStack::IDs; |
| 23 | 23 |
| 24 TimerStack::TimerStack(const IceString &TopLevelName) | 24 TimerStack::TimerStack() |
| 25 : FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), | 25 : FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), |
| 26 StateChangeCount(0), StackTop(0) { | 26 StateChangeCount(0), StackTop(0) { |
| 27 Nodes.resize(1); // Reserve Nodes[0] for the root node. | 27 Nodes.resize(1); // Reserve Nodes[0] for the root node. |
| 28 push(getTimerID(TopLevelName)); | |
| 29 } | 28 } |
| 30 | 29 |
| 31 // Returns the unique timer ID for the given Name, creating a new ID | 30 // Returns the unique timer ID for the given Name, creating a new ID |
| 32 // if needed. For performance reasons, it's best to make only one | 31 // if needed. For performance reasons, it's best to make only one |
| 33 // call per Name and cache the result, e.g. via a static initializer. | 32 // call per Name and cache the result, e.g. via a static initializer. |
| 34 TimerIdT TimerStack::getTimerID(const IceString &Name) { | 33 TimerIdT TimerStack::getTimerID(const IceString &Name) { |
| 35 TimerIdT Size = IDs.size(); | 34 TimerIdT Size = IDs.size(); |
| 36 for (TimerIdT i = 0; i < Size; ++i) { | 35 for (TimerIdT i = 0; i < Size; ++i) { |
| 37 if (IDs[i] == Name) | 36 if (IDs[i] == Name) |
| 38 return i; | 37 return i; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 for (auto I = Map.rbegin(), E = Map.rend(); I != E; ++I) { | 104 for (auto I = Map.rbegin(), E = Map.rend(); I != E; ++I) { |
| 106 char buf[80]; | 105 char buf[80]; |
| 107 snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first, | 106 snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first, |
| 108 I->first * 100 / TotalTime); | 107 I->first * 100 / TotalTime); |
| 109 Str << buf << I->second << "\n"; | 108 Str << buf << I->second << "\n"; |
| 110 } | 109 } |
| 111 } | 110 } |
| 112 | 111 |
| 113 } // end of anonymous namespace | 112 } // end of anonymous namespace |
| 114 | 113 |
| 115 void TimerStack::dump(Ostream &Str) { | 114 void TimerStack::dump(Ostream &Str, bool DumpCumulative) { |
| 116 update(); | 115 update(); |
| 117 double TotalTime = LastTimestamp - FirstTimestamp; | 116 double TotalTime = LastTimestamp - FirstTimestamp; |
| 118 assert(TotalTime); | 117 assert(TotalTime); |
| 119 Str << "Cumulative function times:\n"; | 118 if (DumpCumulative) { |
| 120 DumpMapType CumulativeMap; | 119 Str << "Cumulative times:\n"; |
| 121 for (TTindex i = 1; i < Nodes.size(); ++i) { | 120 DumpMapType CumulativeMap; |
| 122 TTindex Prefix = i; | 121 for (TTindex i = 1; i < Nodes.size(); ++i) { |
| 123 IceString Suffix = ""; | 122 TTindex Prefix = i; |
| 124 while (Prefix) { | 123 IceString Suffix = ""; |
| 125 if (Suffix.empty()) | 124 while (Prefix) { |
| 126 Suffix = IDs[Nodes[Prefix].Interior]; | 125 if (Suffix.empty()) |
| 127 else | 126 Suffix = IDs[Nodes[Prefix].Interior]; |
| 128 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; | 127 else |
| 129 assert(Nodes[Prefix].Parent < Prefix); | 128 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; |
| 130 Prefix = Nodes[Prefix].Parent; | 129 assert(Nodes[Prefix].Parent < Prefix); |
| 130 Prefix = Nodes[Prefix].Parent; |
| 131 } |
| 132 CumulativeMap.insert(std::make_pair(Nodes[i].Time, Suffix)); |
| 131 } | 133 } |
| 132 CumulativeMap.insert(std::make_pair(Nodes[i].Time, Suffix)); | 134 dumpHelper(Str, CumulativeMap, TotalTime); |
| 133 } | 135 } |
| 134 dumpHelper(Str, CumulativeMap, TotalTime); | 136 Str << "Flat times:\n"; |
| 135 Str << "Flat function times:\n"; | |
| 136 DumpMapType FlatMap; | 137 DumpMapType FlatMap; |
| 137 for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { | 138 for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { |
| 138 FlatMap.insert(std::make_pair(LeafTimes[i], IDs[i])); | 139 FlatMap.insert(std::make_pair(LeafTimes[i], IDs[i])); |
| 139 } | 140 } |
| 140 dumpHelper(Str, FlatMap, TotalTime); | 141 dumpHelper(Str, FlatMap, TotalTime); |
| 141 Str << "Number of timer updates: " << StateChangeCount << "\n"; | 142 Str << "Number of timer updates: " << StateChangeCount << "\n"; |
| 142 } | 143 } |
| 143 | 144 |
| 144 double TimerStack::timestamp() { | 145 double TimerStack::timestamp() { |
| 145 // TODO: Implement in terms of std::chrono for C++11. | 146 // TODO: Implement in terms of std::chrono for C++11. |
| 146 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); | 147 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 } // end of namespace Ice | 150 } // end of namespace Ice |
| OLD | NEW |