blob: 795bbee395cd7397dc6db56818b62c63cfb7c9d9 [file] [log] [blame]
Jim Stichnothc4554d72014-09-30 16:49:38 -07001//===- 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 Stichnoth8363a062014-10-07 10:02:38 -070018#include "IceTimerTree.def"
19
Jim Stichnothc4554d72014-09-30 16:49:38 -070020namespace Ice {
21
Jim Stichnothc4554d72014-09-30 16:49:38 -070022class TimerStack {
Jim Stichnoth0795ba02014-10-01 14:23:01 -070023 TimerStack &operator=(const TimerStack &) = delete;
Jim Stichnothc4554d72014-09-30 16:49:38 -070024
Jim Stichnoth7e571362015-01-09 11:43:26 -080025 // 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 Stichnothc4554d72014-09-30 16:49:38 -070047public:
Jim Stichnoth8363a062014-10-07 10:02:38 -070048 enum TimerTag {
49#define X(tag) TT_##tag,
50 TIMERTREE_TABLE
51#undef X
52 TT__num
53 };
54 TimerStack(const IceString &Name);
Jim Stichnoth7e571362015-01-09 11:43:26 -080055 TimerStack(const TimerStack &) = default;
Jim Stichnoth8363a062014-10-07 10:02:38 -070056 TimerIdT getTimerID(const IceString &Name);
Jim Stichnothd14b1a02014-10-08 08:28:36 -070057 void setName(const IceString &NewName) { Name = NewName; }
Jim Stichnothc4554d72014-09-30 16:49:38 -070058 void push(TimerIdT ID);
59 void pop(TimerIdT ID);
Jim Stichnothd14b1a02014-10-08 08:28:36 -070060 void reset();
Jim Stichnoth8363a062014-10-07 10:02:38 -070061 void dump(Ostream &Str, bool DumpCumulative);
Jim Stichnothc4554d72014-09-30 16:49:38 -070062
63private:
Jim Stichnothabce6e52014-10-14 11:09:27 -070064 void update(bool UpdateCounts);
Jim Stichnoth9c234e22014-10-01 09:28:21 -070065 static double timestamp();
Jim Stichnothd14b1a02014-10-08 08:28:36 -070066 IceString Name;
67 double FirstTimestamp;
Jim Stichnothc4554d72014-09-30 16:49:38 -070068 double LastTimestamp;
69 uint64_t StateChangeCount;
Jim Stichnoth8363a062014-10-07 10:02:38 -070070 // IDsIndex maps a symbolic timer name to its integer ID.
71 std::map<IceString, TimerIdT> IDsIndex;
Jim Stichnothdd842db2015-01-27 12:53:53 -080072 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 Stichnothc4554d72014-09-30 16:49:38 -070076 TTindex StackTop;
77};
78
79} // end of namespace Ice
80
81#endif // SUBZERO_SRC_ICETIMERTREE_H