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