blob: 44ee1777cb574b0215f849e07c55bb574c41ada7 [file] [log] [blame]
Chris Lattner6c38a792002-10-01 19:36:54 +00001//===-- Timer.cpp - Interval Timing Support -------------------------------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner6c38a792002-10-01 19:36:54 +00009//
10// Interval Timing implementation.
11//
12//===----------------------------------------------------------------------===//
13
Reid Spencer551ccae2004-09-01 22:55:40 +000014#include "llvm/Support/Timer.h"
15#include "llvm/Support/CommandLine.h"
Chris Lattnerfc86c3c2010-03-29 21:28:41 +000016#include "llvm/Support/Debug.h"
Chris Lattner90aa8392006-10-04 21:52:35 +000017#include "llvm/Support/ManagedStatic.h"
Chris Lattnerd9ea85a2009-08-23 08:43:55 +000018#include "llvm/Support/raw_ostream.h"
19#include "llvm/Support/Format.h"
Chris Lattnerfc86c3c2010-03-29 21:28:41 +000020#include "llvm/System/Mutex.h"
Reid Spencerdf52c9a2004-12-20 00:59:04 +000021#include "llvm/System/Process.h"
Chris Lattnerecdbff82010-03-30 05:20:02 +000022#include "llvm/ADT/OwningPtr.h"
Chris Lattnera782e752010-03-30 04:03:22 +000023#include "llvm/ADT/StringMap.h"
Chris Lattnerb6d465f2003-12-14 21:27:33 +000024using namespace llvm;
Chris Lattnerf205fec2003-05-09 20:05:44 +000025
Chris Lattner49a2bb22010-03-30 05:01:08 +000026// CreateInfoOutputFile - Return a file stream to print our output on.
27namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
Brian Gaeked0fde302003-11-11 22:41:34 +000028
Chris Lattner71336a92003-07-31 19:38:34 +000029// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
30// of constructor/destructor ordering being unspecified by C++. Basically the
Chris Lattnerac0b6ae2006-12-06 17:46:33 +000031// problem is that a Statistic object gets destroyed, which ends up calling
Chris Lattner71336a92003-07-31 19:38:34 +000032// 'GetLibSupportInfoOutputFile()' (below), which calls this function.
33// LibSupportInfoOutputFilename used to be a global variable, but sometimes it
Reid Spencerf6e5a252004-12-14 03:55:21 +000034// would get destroyed before the Statistic, causing havoc to ensue. We "fix"
35// this by creating the string the first time it is needed and never destroying
36// it.
Chris Lattner90aa8392006-10-04 21:52:35 +000037static ManagedStatic<std::string> LibSupportInfoOutputFilename;
Chris Lattner71336a92003-07-31 19:38:34 +000038static std::string &getLibSupportInfoOutputFilename() {
Reid Spencerf6e5a252004-12-14 03:55:21 +000039 return *LibSupportInfoOutputFilename;
Chris Lattner71336a92003-07-31 19:38:34 +000040}
Chris Lattner6c38a792002-10-01 19:36:54 +000041
Owen Anderson46d9a642009-06-23 20:52:29 +000042static ManagedStatic<sys::SmartMutex<true> > TimerLock;
43
Chris Lattner3f398492003-01-30 23:08:50 +000044namespace {
Dan Gohman3c02aca2008-04-23 23:15:23 +000045 static cl::opt<bool>
Chris Lattner3f398492003-01-30 23:08:50 +000046 TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
47 "tracking (this may be slow)"),
48 cl::Hidden);
Chris Lattnerf205fec2003-05-09 20:05:44 +000049
Dan Gohman3c02aca2008-04-23 23:15:23 +000050 static cl::opt<std::string, true>
Chris Lattner96a54db2003-08-01 22:15:15 +000051 InfoOutputFilename("info-output-file", cl::value_desc("filename"),
Chris Lattnerf205fec2003-05-09 20:05:44 +000052 cl::desc("File to append -stats and -timer output to"),
Chris Lattner71336a92003-07-31 19:38:34 +000053 cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
Chris Lattner3f398492003-01-30 23:08:50 +000054}
55
Chris Lattner49a2bb22010-03-30 05:01:08 +000056// CreateInfoOutputFile - Return a file stream to print our output on.
57raw_ostream *llvm::CreateInfoOutputFile() {
Chris Lattnercebf5bc2010-03-30 05:34:02 +000058 const std::string &OutputFilename = getLibSupportInfoOutputFilename();
59 if (OutputFilename.empty())
Chris Lattner49a2bb22010-03-30 05:01:08 +000060 return new raw_fd_ostream(2, false); // stderr.
Chris Lattnercebf5bc2010-03-30 05:34:02 +000061 if (OutputFilename == "-")
Chris Lattner49a2bb22010-03-30 05:01:08 +000062 return new raw_fd_ostream(1, false); // stdout.
Chris Lattnerf8df3e02010-03-29 21:34:06 +000063
Dan Gohman86026cd2010-05-19 01:21:34 +000064 // Append mode is used because the info output file is opened and closed
65 // each time -stats or -time-passes wants to print output to it. To
66 // compensate for this, the test-suite Makefiles have code to delete the
67 // info output file before running commands which write to it.
Chris Lattnerf8df3e02010-03-29 21:34:06 +000068 std::string Error;
Chris Lattnercebf5bc2010-03-30 05:34:02 +000069 raw_ostream *Result = new raw_fd_ostream(OutputFilename.c_str(),
Chris Lattnerf8df3e02010-03-29 21:34:06 +000070 Error, raw_fd_ostream::F_Append);
71 if (Error.empty())
72 return Result;
73
74 errs() << "Error opening info-output-file '"
Chris Lattnercebf5bc2010-03-30 05:34:02 +000075 << OutputFilename << " for appending!\n";
Chris Lattnerf8df3e02010-03-29 21:34:06 +000076 delete Result;
Chris Lattner49a2bb22010-03-30 05:01:08 +000077 return new raw_fd_ostream(2, false); // stderr.
Chris Lattnerf8df3e02010-03-29 21:34:06 +000078}
79
80
Owen Anderson200aa6d2009-06-23 16:36:10 +000081static TimerGroup *DefaultTimerGroup = 0;
Chris Lattner6c38a792002-10-01 19:36:54 +000082static TimerGroup *getDefaultTimerGroup() {
Chris Lattner9bb110f2010-03-29 20:35:01 +000083 TimerGroup *tmp = DefaultTimerGroup;
Owen Anderson3b8d1352009-06-23 17:33:37 +000084 sys::MemoryFence();
Chris Lattner9bb110f2010-03-29 20:35:01 +000085 if (tmp) return tmp;
86
87 llvm_acquire_global_lock();
88 tmp = DefaultTimerGroup;
Owen Anderson3b8d1352009-06-23 17:33:37 +000089 if (!tmp) {
Chris Lattner9bb110f2010-03-29 20:35:01 +000090 tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
91 sys::MemoryFence();
92 DefaultTimerGroup = tmp;
Owen Anderson3b8d1352009-06-23 17:33:37 +000093 }
Chris Lattner9bb110f2010-03-29 20:35:01 +000094 llvm_release_global_lock();
Mikhail Glushenkovc11e84d2009-11-07 06:33:12 +000095
Owen Anderson3b8d1352009-06-23 17:33:37 +000096 return tmp;
Chris Lattner6c38a792002-10-01 19:36:54 +000097}
98
Chris Lattner9bb110f2010-03-29 20:35:01 +000099//===----------------------------------------------------------------------===//
100// Timer Implementation
101//===----------------------------------------------------------------------===//
102
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000103void Timer::init(StringRef N) {
Chris Lattnera782e752010-03-30 04:03:22 +0000104 assert(TG == 0 && "Timer already initialized");
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000105 Name.assign(N.begin(), N.end());
Chris Lattnera782e752010-03-30 04:03:22 +0000106 Started = false;
107 TG = getDefaultTimerGroup();
Chris Lattnerb9312692010-03-30 04:40:01 +0000108 TG->addTimer(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000109}
110
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000111void Timer::init(StringRef N, TimerGroup &tg) {
Chris Lattnera782e752010-03-30 04:03:22 +0000112 assert(TG == 0 && "Timer already initialized");
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000113 Name.assign(N.begin(), N.end());
Chris Lattnera782e752010-03-30 04:03:22 +0000114 Started = false;
115 TG = &tg;
Chris Lattnerb9312692010-03-30 04:40:01 +0000116 TG->addTimer(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000117}
118
Chris Lattner6c38a792002-10-01 19:36:54 +0000119Timer::~Timer() {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000120 if (!TG) return; // Never initialized, or already cleared.
Chris Lattnerb9312692010-03-30 04:40:01 +0000121 TG->removeTimer(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000122}
123
Jeff Cohene269a1a2005-01-08 20:15:57 +0000124static inline size_t getMemUsage() {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000125 if (!TrackSpace) return 0;
126 return sys::Process::GetMallocUsage();
Reid Spenceraeb47b82004-12-27 08:03:04 +0000127}
128
Chris Lattnera782e752010-03-30 04:03:22 +0000129TimeRecord TimeRecord::getCurrentTime(bool Start) {
Chris Lattnerb4db5f32004-06-07 19:34:51 +0000130 TimeRecord Result;
Chris Lattnerecdbff82010-03-30 05:20:02 +0000131 sys::TimeValue now(0,0), user(0,0), sys(0,0);
132
Reid Spencer7d055632004-12-20 21:44:27 +0000133 if (Start) {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000134 Result.MemUsed = getMemUsage();
Chris Lattner9bb110f2010-03-29 20:35:01 +0000135 sys::Process::GetTimeUsage(now, user, sys);
Reid Spencer7d055632004-12-20 21:44:27 +0000136 } else {
Chris Lattner9bb110f2010-03-29 20:35:01 +0000137 sys::Process::GetTimeUsage(now, user, sys);
Chris Lattnerecdbff82010-03-30 05:20:02 +0000138 Result.MemUsed = getMemUsage();
Reid Spencer7d055632004-12-20 21:44:27 +0000139 }
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000140
Chris Lattnera782e752010-03-30 04:03:22 +0000141 Result.WallTime = now.seconds() + now.microseconds() / 1000000.0;
Chris Lattner9bb110f2010-03-29 20:35:01 +0000142 Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
Chris Lattnera782e752010-03-30 04:03:22 +0000143 Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
Chris Lattner6c38a792002-10-01 19:36:54 +0000144 return Result;
145}
146
Chris Lattner90aa8392006-10-04 21:52:35 +0000147static ManagedStatic<std::vector<Timer*> > ActiveTimers;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000148
Chris Lattner6c38a792002-10-01 19:36:54 +0000149void Timer::startTimer() {
150 Started = true;
Dan Gohman153d28a2008-06-24 22:07:07 +0000151 ActiveTimers->push_back(this);
Chris Lattnera782e752010-03-30 04:03:22 +0000152 Time -= TimeRecord::getCurrentTime(true);
Chris Lattner6c38a792002-10-01 19:36:54 +0000153}
154
155void Timer::stopTimer() {
Chris Lattnera782e752010-03-30 04:03:22 +0000156 Time += TimeRecord::getCurrentTime(false);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000157
Chris Lattner90aa8392006-10-04 21:52:35 +0000158 if (ActiveTimers->back() == this) {
159 ActiveTimers->pop_back();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000160 } else {
161 std::vector<Timer*>::iterator I =
Chris Lattner90aa8392006-10-04 21:52:35 +0000162 std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
163 assert(I != ActiveTimers->end() && "stop but no startTimer?");
164 ActiveTimers->erase(I);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000165 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000166}
167
Chris Lattner9bb110f2010-03-29 20:35:01 +0000168static void printVal(double Val, double Total, raw_ostream &OS) {
Chris Lattner0613edc2010-03-29 20:40:19 +0000169 if (Total < 1e-7) // Avoid dividing by zero.
Chris Lattner9bb110f2010-03-29 20:35:01 +0000170 OS << " ----- ";
171 else {
172 OS << " " << format("%7.4f", Val) << " (";
173 OS << format("%5.1f", Val*100/Total) << "%)";
174 }
175}
176
Chris Lattnera782e752010-03-30 04:03:22 +0000177void TimeRecord::print(const TimeRecord &Total, raw_ostream &OS) const {
178 if (Total.getUserTime())
179 printVal(getUserTime(), Total.getUserTime(), OS);
180 if (Total.getSystemTime())
181 printVal(getSystemTime(), Total.getSystemTime(), OS);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000182 if (Total.getProcessTime())
183 printVal(getProcessTime(), Total.getProcessTime(), OS);
Chris Lattnera782e752010-03-30 04:03:22 +0000184 printVal(getWallTime(), Total.getWallTime(), OS);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000185
186 OS << " ";
187
Chris Lattnera782e752010-03-30 04:03:22 +0000188 if (Total.getMemUsed())
189 OS << format("%9lld", (long long)getMemUsed()) << " ";
Chris Lattner9bb110f2010-03-29 20:35:01 +0000190}
191
192
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000193//===----------------------------------------------------------------------===//
194// NamedRegionTimer Implementation
195//===----------------------------------------------------------------------===//
196
Dan Gohmanb3579832010-04-15 17:08:50 +0000197namespace {
198
Chris Lattnera782e752010-03-30 04:03:22 +0000199typedef StringMap<Timer> Name2TimerMap;
Chris Lattnerecdbff82010-03-30 05:20:02 +0000200
201class Name2PairMap {
202 StringMap<std::pair<TimerGroup*, Name2TimerMap> > Map;
203public:
204 ~Name2PairMap() {
205 for (StringMap<std::pair<TimerGroup*, Name2TimerMap> >::iterator
206 I = Map.begin(), E = Map.end(); I != E; ++I)
207 delete I->second.first;
208 }
209
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000210 Timer &get(StringRef Name, StringRef GroupName) {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000211 sys::SmartScopedLock<true> L(*TimerLock);
212
213 std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
214
215 if (!GroupEntry.first)
216 GroupEntry.first = new TimerGroup(GroupName);
217
218 Timer &T = GroupEntry.second[Name];
219 if (!T.isInitialized())
220 T.init(Name, *GroupEntry.first);
221 return T;
222 }
223};
Dan Gohman5e843682008-07-14 18:19:29 +0000224
Dan Gohmanb3579832010-04-15 17:08:50 +0000225}
226
Chris Lattnera782e752010-03-30 04:03:22 +0000227static ManagedStatic<Name2TimerMap> NamedTimers;
228static ManagedStatic<Name2PairMap> NamedGroupedTimers;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000229
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000230static Timer &getNamedRegionTimer(StringRef Name) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000231 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattnera782e752010-03-30 04:03:22 +0000232
233 Timer &T = (*NamedTimers)[Name];
234 if (!T.isInitialized())
235 T.init(Name);
236 return T;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000237}
238
Dan Gohman03c3dc72010-06-18 15:56:31 +0000239NamedRegionTimer::NamedRegionTimer(StringRef Name,
240 bool Enabled)
241 : TimeRegion(!Enabled ? 0 : &getNamedRegionTimer(Name)) {}
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000242
Dan Gohman03c3dc72010-06-18 15:56:31 +0000243NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef GroupName,
244 bool Enabled)
245 : TimeRegion(!Enabled ? 0 : &NamedGroupedTimers->get(Name, GroupName)) {}
Chris Lattner8f0d8242002-11-18 21:47:09 +0000246
Chris Lattner6c38a792002-10-01 19:36:54 +0000247//===----------------------------------------------------------------------===//
248// TimerGroup Implementation
249//===----------------------------------------------------------------------===//
250
Chris Lattner83fa78e2010-03-30 05:27:58 +0000251/// TimerGroupList - This is the global list of TimerGroups, maintained by the
252/// TimerGroup ctor/dtor and is protected by the TimerLock lock.
253static TimerGroup *TimerGroupList = 0;
254
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000255TimerGroup::TimerGroup(StringRef name)
256 : Name(name.begin(), name.end()), FirstTimer(0) {
Chris Lattner83fa78e2010-03-30 05:27:58 +0000257
258 // Add the group to TimerGroupList.
259 sys::SmartScopedLock<true> L(*TimerLock);
260 if (TimerGroupList)
261 TimerGroupList->Prev = &Next;
262 Next = TimerGroupList;
263 Prev = &TimerGroupList;
264 TimerGroupList = this;
265}
266
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000267TimerGroup::~TimerGroup() {
268 // If the timer group is destroyed before the timers it owns, accumulate and
269 // print the timing data.
270 while (FirstTimer != 0)
271 removeTimer(*FirstTimer);
Chris Lattner83fa78e2010-03-30 05:27:58 +0000272
273 // Remove the group from the TimerGroupList.
274 sys::SmartScopedLock<true> L(*TimerLock);
275 *Prev = Next;
276 if (Next)
277 Next->Prev = Prev;
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000278}
279
280
Chris Lattnerb9312692010-03-30 04:40:01 +0000281void TimerGroup::removeTimer(Timer &T) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000282 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000283
Chris Lattnerb9312692010-03-30 04:40:01 +0000284 // If the timer was started, move its data to TimersToPrint.
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000285 if (T.Started)
Chris Lattnerb9312692010-03-30 04:40:01 +0000286 TimersToPrint.push_back(std::make_pair(T.Time, T.Name));
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000287
288 T.TG = 0;
Chris Lattnerb9312692010-03-30 04:40:01 +0000289
290 // Unlink the timer from our list.
291 *T.Prev = T.Next;
292 if (T.Next)
293 T.Next->Prev = T.Prev;
294
295 // Print the report when all timers in this group are destroyed if some of
296 // them were started.
297 if (FirstTimer != 0 || TimersToPrint.empty())
298 return;
299
Chris Lattner49a2bb22010-03-30 05:01:08 +0000300 raw_ostream *OutStream = CreateInfoOutputFile();
Chris Lattnerb9312692010-03-30 04:40:01 +0000301 PrintQueuedTimers(*OutStream);
Chris Lattner49a2bb22010-03-30 05:01:08 +0000302 delete OutStream; // Close the file.
Chris Lattner6c38a792002-10-01 19:36:54 +0000303}
Brian Gaeked0fde302003-11-11 22:41:34 +0000304
Chris Lattnerb9312692010-03-30 04:40:01 +0000305void TimerGroup::addTimer(Timer &T) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000306 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattnerb9312692010-03-30 04:40:01 +0000307
308 // Add the timer to our list.
309 if (FirstTimer)
310 FirstTimer->Prev = &T.Next;
311 T.Next = FirstTimer;
312 T.Prev = &FirstTimer;
313 FirstTimer = &T;
Owen Anderson46d9a642009-06-23 20:52:29 +0000314}
315
Chris Lattnerb9312692010-03-30 04:40:01 +0000316void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
317 // Sort the timers in descending order by amount of time taken.
Benjamin Kramerfff0f112010-08-07 13:27:41 +0000318 std::sort(TimersToPrint.begin(), TimersToPrint.end());
319
Chris Lattnerb9312692010-03-30 04:40:01 +0000320 TimeRecord Total;
321 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
322 Total += TimersToPrint[i].first;
323
324 // Print out timing header.
325 OS << "===" << std::string(73, '-') << "===\n";
326 // Figure out how many spaces to indent TimerGroup name.
327 unsigned Padding = (80-Name.length())/2;
328 if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
329 OS.indent(Padding) << Name << '\n';
330 OS << "===" << std::string(73, '-') << "===\n";
331
332 // If this is not an collection of ungrouped times, print the total time.
333 // Ungrouped timers don't really make sense to add up. We still print the
334 // TOTAL line to make the percentages make sense.
335 if (this != DefaultTimerGroup) {
336 OS << " Total Execution Time: ";
337 OS << format("%5.4f", Total.getProcessTime()) << " seconds (";
338 OS << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
339 }
340 OS << '\n';
341
342 if (Total.getUserTime())
343 OS << " ---User Time---";
344 if (Total.getSystemTime())
345 OS << " --System Time--";
346 if (Total.getProcessTime())
347 OS << " --User+System--";
348 OS << " ---Wall Time---";
349 if (Total.getMemUsed())
350 OS << " ---Mem---";
351 OS << " --- Name ---\n";
352
353 // Loop through all of the timing data, printing it out.
354 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i) {
355 const std::pair<TimeRecord, std::string> &Entry = TimersToPrint[e-i-1];
356 Entry.first.print(Total, OS);
357 OS << Entry.second << '\n';
358 }
359
360 Total.print(Total, OS);
361 OS << "Total\n\n";
362 OS.flush();
363
364 TimersToPrint.clear();
Owen Anderson46d9a642009-06-23 20:52:29 +0000365}
366
Chris Lattnerecdbff82010-03-30 05:20:02 +0000367/// print - Print any started timers in this group and zero them.
368void TimerGroup::print(raw_ostream &OS) {
369 sys::SmartScopedLock<true> L(*TimerLock);
370
371 // See if any of our timers were started, if so add them to TimersToPrint and
372 // reset them.
373 for (Timer *T = FirstTimer; T; T = T->Next) {
374 if (!T->Started) continue;
375 TimersToPrint.push_back(std::make_pair(T->Time, T->Name));
376
377 // Clear out the time.
378 T->Started = 0;
379 T->Time = TimeRecord();
380 }
381
382 // If any timers were started, print the group.
383 if (!TimersToPrint.empty())
384 PrintQueuedTimers(OS);
385}
Chris Lattner83fa78e2010-03-30 05:27:58 +0000386
387/// printAll - This static method prints all timers and clears them all out.
388void TimerGroup::printAll(raw_ostream &OS) {
389 sys::SmartScopedLock<true> L(*TimerLock);
390
391 for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
392 TG->print(OS);
393}