Chromium Code Reviews| Index: src/IceTimerTree.cpp |
| diff --git a/src/IceTimerTree.cpp b/src/IceTimerTree.cpp |
| index 847941fa0aa59d270f725c1acb4c7836c89cd4bf..a45d07cf03ce6619c113672e3161653ec77b647b 100644 |
| --- a/src/IceTimerTree.cpp |
| +++ b/src/IceTimerTree.cpp |
| @@ -19,23 +19,28 @@ |
| namespace Ice { |
| -std::vector<IceString> TimerStack::IDs; |
| - |
| -TimerStack::TimerStack(const IceString &TopLevelName) |
| - : FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), |
| +TimerStack::TimerStack(const IceString &Name) |
| + : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), |
| StateChangeCount(0), StackTop(0) { |
| Nodes.resize(1); // Reserve Nodes[0] for the root node. |
| - push(getTimerID(TopLevelName)); |
| + IDs.resize(TT__num); |
| +#define STR(s) #s |
| +#define X(tag) IDs[TT_##tag] = STR(tag); |
| + TIMERTREE_TABLE; |
| +#undef X |
| +#undef STR |
| } |
| // Returns the unique timer ID for the given Name, creating a new ID |
| -// if needed. For performance reasons, it's best to make only one |
| -// call per Name and cache the result, e.g. via a static initializer. |
| +// if needed. |
| TimerIdT TimerStack::getTimerID(const IceString &Name) { |
| TimerIdT Size = IDs.size(); |
| - for (TimerIdT i = 0; i < Size; ++i) { |
| - if (IDs[i] == Name) |
| - return i; |
| + TimerIdT Result = Size - 1; |
| + // Iterate in reverse order because the predefined timer IDs are at |
| + // the beginning. |
| + 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
|
| + if (*I == Name) |
| + return Result; |
| } |
| IDs.push_back(Name); |
| return Size; |
| @@ -112,27 +117,29 @@ void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) { |
| } // end of anonymous namespace |
| -void TimerStack::dump(Ostream &Str) { |
| +void TimerStack::dump(Ostream &Str, bool DumpCumulative) { |
| update(); |
| double TotalTime = LastTimestamp - FirstTimestamp; |
| assert(TotalTime); |
| - Str << "Cumulative function times:\n"; |
| - DumpMapType CumulativeMap; |
| - for (TTindex i = 1; i < Nodes.size(); ++i) { |
| - TTindex Prefix = i; |
| - IceString Suffix = ""; |
| - while (Prefix) { |
| - if (Suffix.empty()) |
| - Suffix = IDs[Nodes[Prefix].Interior]; |
| - else |
| - Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; |
| - assert(Nodes[Prefix].Parent < Prefix); |
| - Prefix = Nodes[Prefix].Parent; |
| + if (DumpCumulative) { |
| + Str << Name << " - Cumulative times:\n"; |
| + DumpMapType CumulativeMap; |
| + for (TTindex i = 1; i < Nodes.size(); ++i) { |
| + TTindex Prefix = i; |
| + IceString Suffix = ""; |
| + while (Prefix) { |
| + if (Suffix.empty()) |
| + Suffix = IDs[Nodes[Prefix].Interior]; |
| + else |
| + Suffix = IDs[Nodes[Prefix].Interior] + "." + Suffix; |
| + assert(Nodes[Prefix].Parent < Prefix); |
| + Prefix = Nodes[Prefix].Parent; |
| + } |
| + CumulativeMap.insert(std::make_pair(Nodes[i].Time, Suffix)); |
| } |
| - CumulativeMap.insert(std::make_pair(Nodes[i].Time, Suffix)); |
| + dumpHelper(Str, CumulativeMap, TotalTime); |
| } |
| - dumpHelper(Str, CumulativeMap, TotalTime); |
| - Str << "Flat function times:\n"; |
| + Str << Name << " - Flat times:\n"; |
| DumpMapType FlatMap; |
| for (TimerIdT i = 0; i < LeafTimes.size(); ++i) { |
| FlatMap.insert(std::make_pair(LeafTimes[i], IDs[i])); |