OLD | NEW |
1 //===- subzero/src/IceTimerTree.h - Pass timer defs -------------*- C++ -*-===// | 1 //===- subzero/src/IceTimerTree.h - Pass timer defs -------------*- C++ -*-===// |
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 declares the TimerTree class, which allows flat and | 10 // This file declares the TimerTree class, which allows 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 #ifndef SUBZERO_SRC_ICETIMERTREE_H | 15 #ifndef SUBZERO_SRC_ICETIMERTREE_H |
16 #define SUBZERO_SRC_ICETIMERTREE_H | 16 #define SUBZERO_SRC_ICETIMERTREE_H |
17 | 17 |
18 #include "IceTimerTree.def" | 18 #include "IceTimerTree.def" |
19 | 19 |
20 namespace Ice { | 20 namespace Ice { |
21 | 21 |
22 class TimerStack { | 22 class TimerStack { |
23 TimerStack &operator=(const TimerStack &) = delete; | 23 TimerStack &operator=(const TimerStack &) = delete; |
24 | 24 |
25 // Timer tree index type | 25 // Timer tree index type. A variable of this type is used to access |
| 26 // an interior, not-necessarily-leaf node of the tree. |
26 typedef std::vector<class TimerTreeNode>::size_type TTindex; | 27 typedef std::vector<class TimerTreeNode>::size_type TTindex; |
| 28 // Representation of a path of leaf values leading to a particular |
| 29 // node. The representation happens to be in "reverse" order, |
| 30 // i.e. from leaf/interior to root, for implementation efficiency. |
| 31 typedef llvm::SmallVector<TTindex, 8> PathType; |
| 32 // Representation of a mapping of leaf node indexes from one timer |
| 33 // stack to another. |
| 34 typedef std::vector<TimerIdT> TranslationType; |
27 | 35 |
28 // TimerTreeNode represents an interior or leaf node in the call tree. | 36 // TimerTreeNode represents an interior or leaf node in the call tree. |
29 // It contains a list of children, a pointer to its parent, and the | 37 // It contains a list of children, a pointer to its parent, and the |
30 // timer ID for the node. It also holds the cumulative time spent at | 38 // timer ID for the node. It also holds the cumulative time spent at |
31 // this node and below. The children are always at a higher index in | 39 // this node and below. The children are always at a higher index in |
32 // the TimerTreeNode::Nodes array, and the parent is always at a lower | 40 // the TimerTreeNode::Nodes array, and the parent is always at a lower |
33 // index. | 41 // index. |
34 class TimerTreeNode { | 42 class TimerTreeNode { |
35 TimerTreeNode &operator=(const TimerTreeNode &) = delete; | 43 TimerTreeNode &operator=(const TimerTreeNode &) = delete; |
36 | 44 |
(...skipping 10 matching lines...) Expand all Loading... |
47 public: | 55 public: |
48 enum TimerTag { | 56 enum TimerTag { |
49 #define X(tag) TT_##tag, | 57 #define X(tag) TT_##tag, |
50 TIMERTREE_TABLE | 58 TIMERTREE_TABLE |
51 #undef X | 59 #undef X |
52 TT__num | 60 TT__num |
53 }; | 61 }; |
54 TimerStack(const IceString &Name); | 62 TimerStack(const IceString &Name); |
55 TimerStack(const TimerStack &) = default; | 63 TimerStack(const TimerStack &) = default; |
56 TimerIdT getTimerID(const IceString &Name); | 64 TimerIdT getTimerID(const IceString &Name); |
| 65 void mergeFrom(const TimerStack &Src); |
57 void setName(const IceString &NewName) { Name = NewName; } | 66 void setName(const IceString &NewName) { Name = NewName; } |
| 67 const IceString &getName() const { return Name; } |
58 void push(TimerIdT ID); | 68 void push(TimerIdT ID); |
59 void pop(TimerIdT ID); | 69 void pop(TimerIdT ID); |
60 void reset(); | 70 void reset(); |
61 void dump(Ostream &Str, bool DumpCumulative); | 71 void dump(Ostream &Str, bool DumpCumulative); |
62 | 72 |
63 private: | 73 private: |
64 void update(bool UpdateCounts); | 74 void update(bool UpdateCounts); |
65 static double timestamp(); | 75 static double timestamp(); |
| 76 TranslationType translateIDsFrom(const TimerStack &Src); |
| 77 PathType getPath(TTindex Index, const TranslationType &Mapping) const; |
| 78 TTindex getChildIndex(TTindex Parent, TimerIdT ID); |
| 79 TTindex findPath(const PathType &Path); |
66 IceString Name; | 80 IceString Name; |
67 double FirstTimestamp; | 81 double FirstTimestamp; |
68 double LastTimestamp; | 82 double LastTimestamp; |
69 uint64_t StateChangeCount; | 83 uint64_t StateChangeCount; |
70 // IDsIndex maps a symbolic timer name to its integer ID. | 84 // IDsIndex maps a symbolic timer name to its integer ID. |
71 std::map<IceString, TimerIdT> IDsIndex; | 85 std::map<IceString, TimerIdT> IDsIndex; |
72 std::vector<IceString> IDs; // indexed by TimerIdT | 86 std::vector<IceString> IDs; // indexed by TimerIdT |
73 std::vector<TimerTreeNode> Nodes; // indexed by TTindex | 87 std::vector<TimerTreeNode> Nodes; // indexed by TTindex |
74 std::vector<double> LeafTimes; // indexed by TimerIdT | 88 std::vector<double> LeafTimes; // indexed by TimerIdT |
75 std::vector<size_t> LeafCounts; // indexed by TimerIdT | 89 std::vector<size_t> LeafCounts; // indexed by TimerIdT |
76 TTindex StackTop; | 90 TTindex StackTop; |
77 }; | 91 }; |
78 | 92 |
79 } // end of namespace Ice | 93 } // end of namespace Ice |
80 | 94 |
81 #endif // SUBZERO_SRC_ICETIMERTREE_H | 95 #endif // SUBZERO_SRC_ICETIMERTREE_H |
OLD | NEW |