Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTimerTree.h - Pass timer defs -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the TimerTree class, which allows flat and |
| 11 | // cumulative execution time collection of call chains. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef SUBZERO_SRC_ICETIMERTREE_H |
| 16 | #define SUBZERO_SRC_ICETIMERTREE_H |
| 17 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 18 | #include "IceTimerTree.def" |
| 19 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 20 | namespace Ice { |
| 21 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 22 | class TimerStack { |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 23 | TimerStack &operator=(const TimerStack &) = delete; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 24 | |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 25 | // Timer tree index type |
| 26 | typedef std::vector<class TimerTreeNode>::size_type TTindex; |
| 27 | |
| 28 | // 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 |
| 30 | // 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 |
| 32 | // the TimerTreeNode::Nodes array, and the parent is always at a lower |
| 33 | // index. |
| 34 | class TimerTreeNode { |
| 35 | TimerTreeNode &operator=(const TimerTreeNode &) = delete; |
| 36 | |
| 37 | public: |
| 38 | TimerTreeNode() : Parent(0), Interior(0), Time(0), UpdateCount(0) {} |
| 39 | TimerTreeNode(const TimerTreeNode &) = default; |
| 40 | std::vector<TTindex> Children; // indexed by TimerIdT |
| 41 | TTindex Parent; |
| 42 | TimerIdT Interior; |
| 43 | double Time; |
| 44 | size_t UpdateCount; |
| 45 | }; |
| 46 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 47 | public: |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 48 | enum TimerTag { |
| 49 | #define X(tag) TT_##tag, |
| 50 | TIMERTREE_TABLE |
| 51 | #undef X |
| 52 | TT__num |
| 53 | }; |
| 54 | TimerStack(const IceString &Name); |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 55 | TimerStack(const TimerStack &) = default; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 56 | TimerIdT getTimerID(const IceString &Name); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 57 | void setName(const IceString &NewName) { Name = NewName; } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 58 | void push(TimerIdT ID); |
| 59 | void pop(TimerIdT ID); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 60 | void reset(); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 61 | void dump(Ostream &Str, bool DumpCumulative); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 64 | void update(bool UpdateCounts); |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 65 | static double timestamp(); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 66 | IceString Name; |
| 67 | double FirstTimestamp; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 68 | double LastTimestamp; |
| 69 | uint64_t StateChangeCount; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 70 | // IDsIndex maps a symbolic timer name to its integer ID. |
| 71 | std::map<IceString, TimerIdT> IDsIndex; |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 72 | std::vector<IceString> IDs; // indexed by TimerIdT |
| 73 | std::vector<TimerTreeNode> Nodes; // indexed by TTindex |
| 74 | std::vector<double> LeafTimes; // indexed by TimerIdT |
| 75 | std::vector<size_t> LeafCounts; // indexed by TimerIdT |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 76 | TTindex StackTop; |
| 77 | }; |
| 78 | |
| 79 | } // end of namespace Ice |
| 80 | |
| 81 | #endif // SUBZERO_SRC_ICETIMERTREE_H |