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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// This file declares the TimerTree class, which allows flat and |
| 12 | /// cumulative execution time collection of call chains. |
| 13 | /// |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICETIMERTREE_H |
| 17 | #define SUBZERO_SRC_ICETIMERTREE_H |
| 18 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 19 | // TODO(jpp): Refactor IceDefs. |
| 20 | #include "IceDefs.h" |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 21 | #include "IceTimerTree.def" |
| 22 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 23 | namespace Ice { |
| 24 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 25 | class TimerStack { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 26 | TimerStack() = delete; |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 27 | TimerStack &operator=(const TimerStack &) = delete; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 28 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 29 | /// Timer tree index type. A variable of this type is used to access |
| 30 | /// an interior, not-necessarily-leaf node of the tree. |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 31 | typedef std::vector<class TimerTreeNode>::size_type TTindex; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 32 | /// Representation of a path of leaf values leading to a particular |
| 33 | /// node. The representation happens to be in "reverse" order, |
| 34 | /// i.e. from leaf/interior to root, for implementation efficiency. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 35 | typedef llvm::SmallVector<TTindex, 8> PathType; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 36 | /// Representation of a mapping of leaf node indexes from one timer |
| 37 | /// stack to another. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 38 | typedef std::vector<TimerIdT> TranslationType; |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 39 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 40 | /// TimerTreeNode represents an interior or leaf node in the call tree. |
| 41 | /// It contains a list of children, a pointer to its parent, and the |
| 42 | /// timer ID for the node. It also holds the cumulative time spent at |
| 43 | /// this node and below. The children are always at a higher index in |
| 44 | /// the TimerTreeNode::Nodes array, and the parent is always at a lower |
| 45 | /// index. |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 46 | class TimerTreeNode { |
| 47 | TimerTreeNode &operator=(const TimerTreeNode &) = delete; |
| 48 | |
| 49 | public: |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 50 | TimerTreeNode() = default; |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 51 | TimerTreeNode(const TimerTreeNode &) = default; |
| 52 | std::vector<TTindex> Children; // indexed by TimerIdT |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 53 | TTindex Parent = 0; |
| 54 | TimerIdT Interior = 0; |
| 55 | double Time = 0; |
| 56 | size_t UpdateCount = 0; |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 59 | public: |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 60 | enum TimerTag { |
| 61 | #define X(tag) TT_##tag, |
| 62 | TIMERTREE_TABLE |
| 63 | #undef X |
| 64 | TT__num |
| 65 | }; |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 66 | explicit TimerStack(const IceString &Name); |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 67 | TimerStack(const TimerStack &) = default; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 68 | TimerIdT getTimerID(const IceString &Name); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 69 | void mergeFrom(const TimerStack &Src); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 70 | void setName(const IceString &NewName) { Name = NewName; } |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 71 | const IceString &getName() const { return Name; } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 72 | void push(TimerIdT ID); |
| 73 | void pop(TimerIdT ID); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 74 | void reset(); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 75 | void dump(Ostream &Str, bool DumpCumulative); |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
Jim Stichnoth | abce6e5 | 2014-10-14 11:09:27 -0700 | [diff] [blame] | 78 | void update(bool UpdateCounts); |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 79 | static double timestamp(); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 80 | TranslationType translateIDsFrom(const TimerStack &Src); |
| 81 | PathType getPath(TTindex Index, const TranslationType &Mapping) const; |
| 82 | TTindex getChildIndex(TTindex Parent, TimerIdT ID); |
| 83 | TTindex findPath(const PathType &Path); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 84 | IceString Name; |
| 85 | double FirstTimestamp; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 86 | double LastTimestamp; |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 87 | uint64_t StateChangeCount = 0; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 88 | /// IDsIndex maps a symbolic timer name to its integer ID. |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 89 | std::map<IceString, TimerIdT> IDsIndex; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 90 | std::vector<IceString> IDs; /// indexed by TimerIdT |
| 91 | std::vector<TimerTreeNode> Nodes; /// indexed by TTindex |
| 92 | std::vector<double> LeafTimes; /// indexed by TimerIdT |
| 93 | std::vector<size_t> LeafCounts; /// indexed by TimerIdT |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 94 | TTindex StackTop = 0; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // end of namespace Ice |
| 98 | |
| 99 | #endif // SUBZERO_SRC_ICETIMERTREE_H |