LLVM: include/llvm/Support/Timer.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_SUPPORT_TIMER_H

10#define LLVM_SUPPORT_TIMER_H

11

16#include

17#include

18#include

19#include

20

21namespace llvm {

22

23class TimerGlobals;

24class TimerGroup;

25class raw_ostream;

26

28 double WallTime = 0.0;

29 double UserTime = 0.0;

30 double SystemTime = 0.0;

31 ssize_t MemUsed = 0;

32 uint64_t InstructionsExecuted = 0;

33public:

35

36

37

38

39

41

42 double getProcessTime() const { return UserTime + SystemTime; }

46 ssize_t getMemUsed() const { return MemUsed; }

48

50

51 return WallTime < T.WallTime;

52 }

53

55 WallTime += RHS.WallTime;

56 UserTime += RHS.UserTime;

57 SystemTime += RHS.SystemTime;

58 MemUsed += RHS.MemUsed;

59 InstructionsExecuted += RHS.InstructionsExecuted;

60 }

62 WallTime -= RHS.WallTime;

63 UserTime -= RHS.UserTime;

64 SystemTime -= RHS.SystemTime;

65 MemUsed -= RHS.MemUsed;

66 InstructionsExecuted -= RHS.InstructionsExecuted;

67 }

68

69

70

72};

73

74

75

76

77

78

79

80

82 TimeRecord Time;

83 TimeRecord StartTime;

84 std::string Name;

85 std::string Description;

86 bool Running = false;

87 bool Triggered = false;

88 TimerGroup *TG = nullptr;

89

90 Timer **Prev = nullptr;

91 Timer *Next = nullptr;

92public:

94 init(TimerName, TimerDescription);

95 }

97 init(TimerName, TimerDescription, tg);

98 }

100 assert(RHS.TG && "Can only copy uninitialized timers");

101 }

103 assert(!TG && T.TG && "Can only assign uninit timers");

104 return *this;

105 }

107

108

112

113 const std::string &getName() const { return Name; }

114 const std::string &getDescription() const { return Description; }

116

117

119

120

122

123

124

125

127

128

130

131

133

134

136

137

139

140private:

142};

143

144

145

146

147

151

152public:

154 T->startTimer();

155 }

157 if (T) T->startTimer();

158 }

160 if (T) T->stopTimer();

161 }

162};

163

164

165

166

167

172};

173

174

175

176

177

179 struct PrintRecord {

181 std::string Name;

182 std::string Description;

183

184 PrintRecord(const PrintRecord &Other) = default;

185 PrintRecord &operator=(const PrintRecord &Other) = default;

186 PrintRecord(const TimeRecord &Time, const std::string &Name,

187 const std::string &Description)

188 : Time(Time), Name(Name), Description(Description) {}

189

190 bool operator <(const PrintRecord &Other) const {

191 return Time < Other.Time;

192 }

193 };

194 std::string Name;

195 std::string Description;

196 Timer *FirstTimer = nullptr;

197 std::vector TimersToPrint;

198

199 TimerGroup **Prev;

200 TimerGroup *Next;

202 void operator=(const TimerGroup &TG) = delete;

203

207

208public:

210

213

215

218 Description.assign(NewDescription.begin(), NewDescription.end());

219 }

220

221

222

224

225

227

228

230

231

232

233

235

237

238

240

241

242

243

245

246

247

249

250private:

253 void addTimer(Timer &T);

254 void removeTimer(Timer &T);

255 void prepareToPrintList(bool reset_time = false);

257 void printJSONValue(raw_ostream &OS, const PrintRecord &R,

258 const char *suffix, double Value);

259};

260

261}

262

263#endif

This file defines the StringMap class.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...

StringRef - Represent a constant reference to a string, i.e.

double getUserTime() const

double getProcessTime() const

static TimeRecord getCurrentTime(bool Start=true)

Get the current time and memory usage.

double getWallTime() const

ssize_t getMemUsed() const

void operator-=(const TimeRecord &RHS)

void operator+=(const TimeRecord &RHS)

double getSystemTime() const

bool operator<(const TimeRecord &T) const

void print(const TimeRecord &Total, raw_ostream &OS) const

Print the current time record to OS, with a breakdown showing contributions to the Total time record.

uint64_t getInstructionsExecuted() const

The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...

The TimerGroup class is used to group together related timers into a single report that is printed wh...

static void printAll(raw_ostream &OS)

This static method prints all timers.

void setName(StringRef NewName, StringRef NewDescription)

void print(raw_ostream &OS, bool ResetAfterPrint=false)

Print any started timers in this group, optionally resetting timers after printing them.

static void clearAll()

Clear out all timers.

void clear()

Clear all timers in this group.

friend void PrintStatisticsJSON(raw_ostream &OS)

Print statistics in JSON format.

static void * acquireTimerGlobals()

This makes the timer globals unmanaged, and lets the user manage the lifetime.

static const char * printAllJSONValues(raw_ostream &OS, const char *delim)

Prints all timers as JSON key/value pairs.

const char * printJSONValues(raw_ostream &OS, const char *delim)

static void constructForStatistics()

Ensure global objects required for statistics printing are initialized.

This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...

bool hasTriggered() const

Check if startTimer() has ever been called on this timer.

void yieldTo(Timer &)

Stop the timer and start another timer.

bool isRunning() const

Check if the timer is currently running.

void stopTimer()

Stop the timer.

const Timer & operator=(const Timer &T)

const std::string & getDescription() const

void init(StringRef TimerName, StringRef TimerDescription)

void clear()

Clear the timer state.

const std::string & getName() const

Timer()=default

Create an uninitialized timer, client must use 'init'.

bool isInitialized() const

Timer(StringRef TimerName, StringRef TimerDescription)

Timer(StringRef TimerName, StringRef TimerDescription, TimerGroup &tg)

void startTimer()

Start the timer running.

TimeRecord getTotalTime() const

Return the duration for which this timer has been running.

LLVM Value Representation.

This class implements an extremely fast bulk output stream that can only output to a stream.

SmartMutex - A mutex with a compile time constant parameter that indicates whether this mutex should ...

This is an optimization pass for GlobalISel generic memory operations.

This class is basically a combination of TimeRegion and Timer.