annotate include/llvm/Support/Timer.h @ 128:c347d3398279 default tip

fix
author mir3636
date Wed, 06 Dec 2017 14:37:17 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===-- llvm/Support/Timer.h - Interval Timing Support ----------*- C++ -*-===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #ifndef LLVM_SUPPORT_TIMER_H
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #define LLVM_SUPPORT_TIMER_H
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "llvm/ADT/StringRef.h"
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "llvm/Support/DataTypes.h"
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #include <cassert>
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #include <string>
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include <utility>
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 #include <vector>
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 namespace llvm {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 class Timer;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 class TimerGroup;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 class raw_ostream;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 class TimeRecord {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
27 double WallTime; ///< Wall clock time elapsed in seconds.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
28 double UserTime; ///< User time elapsed.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
29 double SystemTime; ///< System time elapsed.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
30 ssize_t MemUsed; ///< Memory allocated (in bytes).
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 public:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 TimeRecord() : WallTime(0), UserTime(0), SystemTime(0), MemUsed(0) {}
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
33
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
34 /// Get the current time and memory usage. If Start is true we get the memory
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
35 /// usage before the time, otherwise we get time before memory usage. This
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
36 /// matters if the time to get the memory usage is significant and shouldn't
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
37 /// be counted as part of a duration.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 static TimeRecord getCurrentTime(bool Start = true);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
39
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
40 double getProcessTime() const { return UserTime + SystemTime; }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 double getUserTime() const { return UserTime; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 double getSystemTime() const { return SystemTime; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 double getWallTime() const { return WallTime; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ssize_t getMemUsed() const { return MemUsed; }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
45
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 bool operator<(const TimeRecord &T) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 // Sort by Wall Time elapsed, as it is the only thing really accurate
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 return WallTime < T.WallTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
50
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 void operator+=(const TimeRecord &RHS) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 WallTime += RHS.WallTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 UserTime += RHS.UserTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 SystemTime += RHS.SystemTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 MemUsed += RHS.MemUsed;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 void operator-=(const TimeRecord &RHS) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 WallTime -= RHS.WallTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 UserTime -= RHS.UserTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 SystemTime -= RHS.SystemTime;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 MemUsed -= RHS.MemUsed;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
63
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
64 /// Print the current time record to \p OS, with a breakdown showing
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
65 /// contributions to the \p Total time record.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 void print(const TimeRecord &Total, raw_ostream &OS) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 };
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
68
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
69 /// This class is used to track the amount of time spent between invocations of
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
70 /// its startTimer()/stopTimer() methods. Given appropriate OS support it can
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
71 /// also keep track of the RSS of the program at various points. By default,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
72 /// the Timer will print the amount of time it has captured to standard error
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
73 /// when the last timer is destroyed, otherwise it is printed when its
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
74 /// TimerGroup is destroyed. Timers do not print their information if they are
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
75 /// never started.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 class Timer {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
77 TimeRecord Time; ///< The total time captured.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
78 TimeRecord StartTime; ///< The time startTimer() was last called.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
79 std::string Name; ///< The name of this time variable.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
80 std::string Description; ///< Description of this time variable.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
81 bool Running; ///< Is the timer currently running?
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
82 bool Triggered; ///< Has the timer ever been triggered?
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
83 TimerGroup *TG = nullptr; ///< The TimerGroup this Timer is in.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
84
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
85 Timer **Prev; ///< Pointer to \p Next of previous timer in group.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
86 Timer *Next; ///< Next timer in the group.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 public:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
88 explicit Timer(StringRef Name, StringRef Description) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
89 init(Name, Description);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
90 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
91 Timer(StringRef Name, StringRef Description, TimerGroup &tg) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
92 init(Name, Description, tg);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
93 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
94 Timer(const Timer &RHS) {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
95 assert(!RHS.TG && "Can only copy uninitialized timers");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 const Timer &operator=(const Timer &T) {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
98 assert(!TG && !T.TG && "Can only assign uninit timers");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 return *this;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ~Timer();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
103 /// Create an uninitialized timer, client must use 'init'.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
104 explicit Timer() {}
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
105 void init(StringRef Name, StringRef Description);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
106 void init(StringRef Name, StringRef Description, TimerGroup &tg);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
107
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 const std::string &getName() const { return Name; }
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
109 const std::string &getDescription() const { return Description; }
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
110 bool isInitialized() const { return TG != nullptr; }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
111
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
112 /// Check if the timer is currently running.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
113 bool isRunning() const { return Running; }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
114
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
115 /// Check if startTimer() has ever been called on this timer.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
116 bool hasTriggered() const { return Triggered; }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
117
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
118 /// Start the timer running. Time between calls to startTimer/stopTimer is
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
119 /// counted by the Timer class. Note that these calls must be correctly
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
120 /// paired.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 void startTimer();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
123 /// Stop the timer.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 void stopTimer();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
126 /// Clear the timer state.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
127 void clear();
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
128
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
129 /// Return the duration for which this timer has been running.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
130 TimeRecord getTotalTime() const { return Time; }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
131
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 private:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 friend class TimerGroup;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 /// The TimeRegion class is used as a helper class to call the startTimer() and
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 /// stopTimer() methods of the Timer class. When the object is constructed, it
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 /// starts the timer specified as its argument. When it is destroyed, it stops
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 /// the relevant timer. This makes it easy to time a region of code.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 class TimeRegion {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 Timer *T;
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
142 TimeRegion(const TimeRegion &) = delete;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
143
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 public:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 explicit TimeRegion(Timer &t) : T(&t) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 T->startTimer();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 explicit TimeRegion(Timer *t) : T(t) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 if (T) T->startTimer();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 ~TimeRegion() {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 if (T) T->stopTimer();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
156 /// This class is basically a combination of TimeRegion and Timer. It allows
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
157 /// you to declare a new timer, AND specify the region to time, all in one
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
158 /// statement. All timers with the same name are merged. This is primarily
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
159 /// used for debugging and for hunting performance problems.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 struct NamedRegionTimer : public TimeRegion {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
161 explicit NamedRegionTimer(StringRef Name, StringRef Description,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
162 StringRef GroupName,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
163 StringRef GroupDescription, bool Enabled = true);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 /// The TimerGroup class is used to group together related timers into a single
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 /// report that is printed when the TimerGroup is destroyed. It is illegal to
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 /// destroy a TimerGroup object before all of the Timers in it are gone. A
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 /// TimerGroup can be specified for a newly created timer in its constructor.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 class TimerGroup {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
171 struct PrintRecord {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
172 TimeRecord Time;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
173 std::string Name;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
174 std::string Description;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
175
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
176 PrintRecord(const PrintRecord &Other) = default;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
177 PrintRecord(const TimeRecord &Time, const std::string &Name,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
178 const std::string &Description)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
179 : Time(Time), Name(Name), Description(Description) {}
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
180
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
181 bool operator <(const PrintRecord &Other) const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
182 return Time < Other.Time;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
183 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
184 };
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 std::string Name;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
186 std::string Description;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
187 Timer *FirstTimer = nullptr; ///< First timer in the group.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
188 std::vector<PrintRecord> TimersToPrint;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
189
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
190 TimerGroup **Prev; ///< Pointer to Next field of previous timergroup in list.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
191 TimerGroup *Next; ///< Pointer to next timergroup in list.
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
192 TimerGroup(const TimerGroup &TG) = delete;
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
193 void operator=(const TimerGroup &TG) = delete;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
194
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 public:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
196 explicit TimerGroup(StringRef Name, StringRef Description);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 ~TimerGroup();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
199 void setName(StringRef NewName, StringRef NewDescription) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
200 Name.assign(NewName.begin(), NewName.end());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
201 Description.assign(NewDescription.begin(), NewDescription.end());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
202 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
204 /// Print any started timers in this group and zero them.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 void print(raw_ostream &OS);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
206
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
207 /// This static method prints all timers and clears them all out.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 static void printAll(raw_ostream &OS);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
209
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
210 /// Prints all timers as JSON key/value pairs, and clears them all out.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
211 static const char *printAllJSONValues(raw_ostream &OS, const char *delim);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
212
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
213 /// Ensure global timer group lists are initialized. This function is mostly
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
214 /// used by the Statistic code to influence the construction and destruction
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
215 /// order of the global timer lists.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
216 static void ConstructTimerLists();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 private:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 friend class Timer;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
219 friend void PrintStatisticsJSON(raw_ostream &OS);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 void addTimer(Timer &T);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 void removeTimer(Timer &T);
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
222 void prepareToPrintList();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 void PrintQueuedTimers(raw_ostream &OS);
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
224 void printJSONValue(raw_ostream &OS, const PrintRecord &R,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
225 const char *suffix, double Value);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
226 const char *printJSONValues(raw_ostream &OS, const char *delim);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
229 } // end namespace llvm
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 #endif