Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: src/IceTimerTree.cpp

Issue 620373004: Subzero: Add a few performance measurement tools. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes; remove the static initializer pattern Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 TimerStack::TimerStack(const IceString &Name)
23 23 : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp),
24 TimerStack::TimerStack(const IceString &TopLevelName)
25 : FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp),
26 StateChangeCount(0), StackTop(0) { 24 StateChangeCount(0), StackTop(0) {
27 Nodes.resize(1); // Reserve Nodes[0] for the root node. 25 Nodes.resize(1); // Reserve Nodes[0] for the root node.
28 push(getTimerID(TopLevelName)); 26 IDs.resize(TT__num);
27 #define STR(s) #s
28 #define X(tag) IDs[TT_##tag] = STR(tag);
29 TIMERTREE_TABLE;
30 #undef X
31 #undef STR
29 } 32 }
30 33
31 // Returns the unique timer ID for the given Name, creating a new ID 34 // 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 35 // if needed.
33 // call per Name and cache the result, e.g. via a static initializer.
34 TimerIdT TimerStack::getTimerID(const IceString &Name) { 36 TimerIdT TimerStack::getTimerID(const IceString &Name) {
35 TimerIdT Size = IDs.size(); 37 TimerIdT Size = IDs.size();
36 for (TimerIdT i = 0; i < Size; ++i) { 38 TimerIdT Result = Size - 1;
37 if (IDs[i] == Name) 39 // Iterate in reverse order because the predefined timer IDs are at
38 return i; 40 // the beginning.
41 for (auto I = IDs.rbegin(), E = IDs.rend(); I != E; ++I, --Result) {
jvoung (off chromium) 2014/10/06 23:01:52 I wonder if this should be a map, or unorder_map,
jvoung (off chromium) 2014/10/06 23:02:36 Err... except for the PNaClTranslator use, where t
Jim Stichnoth 2014/10/06 23:54:39 Good point, thanks! Done, by having two container
42 if (*I == Name)
43 return Result;
39 } 44 }
40 IDs.push_back(Name); 45 IDs.push_back(Name);
41 return Size; 46 return Size;
42 } 47 }
43 48
44 // Pushes a new marker onto the timer stack. 49 // Pushes a new marker onto the timer stack.
45 void TimerStack::push(TimerIdT ID) { 50 void TimerStack::push(TimerIdT ID) {
46 update(); 51 update();
47 if (Nodes[StackTop].Children.size() <= ID) 52 if (Nodes[StackTop].Children.size() <= ID)
48 Nodes[StackTop].Children.resize(ID + 1); 53 Nodes[StackTop].Children.resize(ID + 1);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 for (auto I = Map.rbegin(), E = Map.rend(); I != E; ++I) { 110 for (auto I = Map.rbegin(), E = Map.rend(); I != E; ++I) {
106 char buf[80]; 111 char buf[80];
107 snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first, 112 snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first,
108 I->first * 100 / TotalTime); 113 I->first * 100 / TotalTime);
109 Str << buf << I->second << "\n"; 114 Str << buf << I->second << "\n";
110 } 115 }
111 } 116 }
112 117
113 } // end of anonymous namespace 118 } // end of anonymous namespace
114 119
115 void TimerStack::dump(Ostream &Str) { 120 void TimerStack::dump(Ostream &Str, bool DumpCumulative) {
116 update(); 121 update();
117 double TotalTime = LastTimestamp - FirstTimestamp; 122 double TotalTime = LastTimestamp - FirstTimestamp;
118 assert(TotalTime); 123 assert(TotalTime);
119 Str << "Cumulative function times:\n"; 124 if (DumpCumulative) {
120 DumpMapType CumulativeMap; 125 Str << Name << " - Cumulative times:\n";
121 for (TTindex i = 1; i < Nodes.size(); ++i) { 126 DumpMapType CumulativeMap;
122 TTindex Prefix = i; 127 for (TTindex i = 1; i < Nodes.size(); ++i) {
123 IceString Suffix = ""; 128 TTindex Prefix = i;
124 while (Prefix) { 129 IceString Suffix = "";
125 if (Suffix.empty()) 130 while (Prefix) {
126 Suffix = IDs[Nodes[Prefix].Interior]; 131 if (Suffix.empty())
127 else 132 Suffix = IDs[Nodes[Prefix].Interior];
128 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; 133 else
129 assert(Nodes[Prefix].Parent < Prefix); 134 Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix;
130 Prefix = Nodes[Prefix].Parent; 135 assert(Nodes[Prefix].Parent < Prefix);
136 Prefix = Nodes[Prefix].Parent;
137 }
138 CumulativeMap.insert(std::make_pair(Nodes[i].Time, Suffix));
131 } 139 }
132 CumulativeMap.insert(std::make_pair(Nodes[i].Time, Suffix)); 140 dumpHelper(Str, CumulativeMap, TotalTime);
133 } 141 }
134 dumpHelper(Str, CumulativeMap, TotalTime); 142 Str << Name << " - Flat times:\n";
135 Str << "Flat function times:\n";
136 DumpMapType FlatMap; 143 DumpMapType FlatMap;
137 for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { 144 for (TimerIdT i = 0; i < LeafTimes.size(); ++i) {
138 FlatMap.insert(std::make_pair(LeafTimes[i], IDs[i])); 145 FlatMap.insert(std::make_pair(LeafTimes[i], IDs[i]));
139 } 146 }
140 dumpHelper(Str, FlatMap, TotalTime); 147 dumpHelper(Str, FlatMap, TotalTime);
141 Str << "Number of timer updates: " << StateChangeCount << "\n"; 148 Str << "Number of timer updates: " << StateChangeCount << "\n";
142 } 149 }
143 150
144 double TimerStack::timestamp() { 151 double TimerStack::timestamp() {
145 // TODO: Implement in terms of std::chrono for C++11. 152 // TODO: Implement in terms of std::chrono for C++11.
146 return llvm::TimeRecord::getCurrentTime(false).getWallTime(); 153 return llvm::TimeRecord::getCurrentTime(false).getWallTime();
147 } 154 }
148 155
149 } // end of namespace Ice 156 } // end of namespace Ice
OLDNEW
« src/IceGlobalContext.cpp ('K') | « src/IceTimerTree.h ('k') | src/IceTimerTree.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698