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

17#include

18#include

19#include

20

21namespace llvm {

22

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 }

73

74

75

76

78};

79

80

81

82

83

84

85

86

88 TimeRecord Time;

89 TimeRecord StartTime;

90 std::string Name;

91 std::string Description;

92 bool Running = false;

93 bool Triggered = false;

94 TimerGroup *TG = nullptr;

95

96 Timer **Prev = nullptr;

97 Timer *Next = nullptr;

98public:

100 init(TimerName, TimerDescription);

101 }

103 init(TimerName, TimerDescription, tg);

104 }

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

107 }

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

110 return *this;

111 }

113

114

119

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

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

123

124

126

127

129

130

131

132

134

135

137

138

140

141

143

144

146

147private:

149};

150

151

152

153

154

155class TimeRegion {

157 TimeRegion(const TimeRegion &) = delete;

158

159public:

161 T->startTimer();

162 }

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

165 }

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

168 }

169};

170

171

172

173

174

186

187

188

189

190

191class TimerGroup {

192 struct PrintRecord {

194 std::string Name;

195 std::string Description;

196

197 PrintRecord(const PrintRecord &Other) = default;

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

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

200 const std::string &Description)

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

202

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

204 return Time < Other.Time;

205 }

206 };

207 std::string Name;

208 std::string Description;

209 Timer *FirstTimer = nullptr;

210 std::vector TimersToPrint;

211 bool PrintOnExit;

212

213 TimerGroup **Prev;

214 TimerGroup *Next;

215 TimerGroup(const TimerGroup &TG) = delete;

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

217

221

222public:

224 bool PrintOnExit = true);

225

228 bool PrintOnExit = true);

229

231

233 Name.assign(NewName.begin(), NewName.end());

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

235 }

236

237

238

240

241

243

244

246

247

248

249

251

253

254

256 const char *delim);

257

258

259

260

262

263

264

266

267private:

270 void addTimer(Timer &T);

271 void removeTimer(Timer &T);

272 void prepareToPrintList(bool reset_time = false);

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

275 const char *suffix, double Value);

276};

277

278}

279

280#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines the StringMap class.

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

Definition Timer.h:43

double getProcessTime() const

Definition Timer.h:42

static LLVM_ABI TimeRecord getCurrentTime(bool Start=true)

Get the current time and memory usage.

double getWallTime() const

Definition Timer.h:45

TimeRecord operator-(const TimeRecord &RHS) const

Definition Timer.h:68

ssize_t getMemUsed() const

Definition Timer.h:46

void operator-=(const TimeRecord &RHS)

Definition Timer.h:61

void operator+=(const TimeRecord &RHS)

Definition Timer.h:54

double getSystemTime() const

Definition Timer.h:44

bool operator<(const TimeRecord &T) const

Definition Timer.h:49

LLVM_ABI 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

Definition Timer.h:47

~TimeRegion()

Definition Timer.h:166

TimeRegion(Timer &t)

Definition Timer.h:160

TimeRegion(Timer *t)

Definition Timer.h:163

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

Definition Timer.h:191

static LLVM_ABI void printAll(raw_ostream &OS)

This static method prints all timers.

void setName(StringRef NewName, StringRef NewDescription)

Definition Timer.h:232

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

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

friend class Timer

Definition Timer.h:268

static LLVM_ABI void clearAll()

Clear out all timers.

LLVM_ABI void clear()

Clear all timers in this group.

LLVM_ABI friend void PrintStatisticsJSON(raw_ostream &OS)

Print statistics in JSON format.

friend class TimerGlobals

Definition Timer.h:218

static LLVM_ABI void * acquireTimerGlobals()

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

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

Prints all timers as JSON key/value pairs.

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

static LLVM_ABI 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...

Definition Timer.h:87

bool hasTriggered() const

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

Definition Timer.h:128

LLVM_ABI void yieldTo(Timer &)

Stop the timer and start another timer.

bool isRunning() const

Check if the timer is currently running.

Definition Timer.h:125

LLVM_ABI void stopTimer()

Stop the timer.

const Timer & operator=(const Timer &T)

Definition Timer.h:108

const std::string & getDescription() const

Definition Timer.h:121

LLVM_ABI void init(StringRef TimerName, StringRef TimerDescription)

LLVM_ABI void clear()

Clear the timer state.

friend class TimerGroup

Definition Timer.h:148

const std::string & getName() const

Definition Timer.h:120

Timer()=default

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

Timer(const Timer &RHS)

Definition Timer.h:105

bool isInitialized() const

Definition Timer.h:122

Timer(StringRef TimerName, StringRef TimerDescription)

Definition Timer.h:99

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

Definition Timer.h:102

LLVM_ABI void startTimer()

Start the timer running.

TimeRecord getTotalTime() const

Return the duration for which this timer has been running.

Definition Timer.h:145

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.

@ Enabled

Convert any .debug_str_offsets tables to DWARF64 if needed.

LLVM_ABI NamedRegionTimer(StringRef Name, StringRef Description, StringRef GroupName, StringRef GroupDescription, bool Enabled=true)

static LLVM_ABI TimerGroup & getNamedTimerGroup(StringRef GroupName, StringRef GroupDescription)