blob: bf4595484981e9dcaa92337fd5ac5ca31218e35f [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"
Benjamin Kramer933b16e2010-08-07 12:37:00 +000023#include "llvm/ADT/STLExtras.h"
Chris Lattnera782e752010-03-30 04:03:22 +000024#include "llvm/ADT/StringMap.h"
Chris Lattnerb6d465f2003-12-14 21:27:33 +000025using namespace llvm;
Chris Lattnerf205fec2003-05-09 20:05:44 +000026
Chris Lattner49a2bb22010-03-30 05:01:08 +000027// CreateInfoOutputFile - Return a file stream to print our output on.
28namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
Brian Gaeked0fde302003-11-11 22:41:34 +000029
Chris Lattner71336a92003-07-31 19:38:34 +000030// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
31// of constructor/destructor ordering being unspecified by C++. Basically the
Chris Lattnerac0b6ae2006-12-06 17:46:33 +000032// problem is that a Statistic object gets destroyed, which ends up calling
Chris Lattner71336a92003-07-31 19:38:34 +000033// 'GetLibSupportInfoOutputFile()' (below), which calls this function.
34// LibSupportInfoOutputFilename used to be a global variable, but sometimes it
Reid Spencerf6e5a252004-12-14 03:55:21 +000035// would get destroyed before the Statistic, causing havoc to ensue. We "fix"
36// this by creating the string the first time it is needed and never destroying
37// it.
Chris Lattner90aa8392006-10-04 21:52:35 +000038static ManagedStatic<std::string> LibSupportInfoOutputFilename;
Chris Lattner71336a92003-07-31 19:38:34 +000039static std::string &getLibSupportInfoOutputFilename() {
Reid Spencerf6e5a252004-12-14 03:55:21 +000040 return *LibSupportInfoOutputFilename;
Chris Lattner71336a92003-07-31 19:38:34 +000041}
Chris Lattner6c38a792002-10-01 19:36:54 +000042
Owen Anderson46d9a642009-06-23 20:52:29 +000043static ManagedStatic<sys::SmartMutex<true> > TimerLock;
44
Chris Lattner3f398492003-01-30 23:08:50 +000045namespace {
Dan Gohman3c02aca2008-04-23 23:15:23 +000046 static cl::opt<bool>
Chris Lattner3f398492003-01-30 23:08:50 +000047 TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
48 "tracking (this may be slow)"),
49 cl::Hidden);
Chris Lattnerf205fec2003-05-09 20:05:44 +000050
Dan Gohman3c02aca2008-04-23 23:15:23 +000051 static cl::opt<std::string, true>
Chris Lattner96a54db2003-08-01 22:15:15 +000052 InfoOutputFilename("info-output-file", cl::value_desc("filename"),
Chris Lattnerf205fec2003-05-09 20:05:44 +000053 cl::desc("File to append -stats and -timer output to"),
Chris Lattner71336a92003-07-31 19:38:34 +000054 cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
Chris Lattner3f398492003-01-30 23:08:50 +000055}
56
Chris Lattner49a2bb22010-03-30 05:01:08 +000057// CreateInfoOutputFile - Return a file stream to print our output on.
58raw_ostream *llvm::CreateInfoOutputFile() {
Chris Lattnercebf5bc2010-03-30 05:34:02 +000059 const std::string &OutputFilename = getLibSupportInfoOutputFilename();
60 if (OutputFilename.empty())
Chris Lattner49a2bb22010-03-30 05:01:08 +000061 return new raw_fd_ostream(2, false); // stderr.
Chris Lattnercebf5bc2010-03-30 05:34:02 +000062 if (OutputFilename == "-")
Chris Lattner49a2bb22010-03-30 05:01:08 +000063 return new raw_fd_ostream(1, false); // stdout.
Chris Lattnerf8df3e02010-03-29 21:34:06 +000064
Dan Gohman86026cd2010-05-19 01:21:34 +000065 // Append mode is used because the info output file is opened and closed
66 // each time -stats or -time-passes wants to print output to it. To
67 // compensate for this, the test-suite Makefiles have code to delete the
68 // info output file before running commands which write to it.
Chris Lattnerf8df3e02010-03-29 21:34:06 +000069 std::string Error;
Chris Lattnercebf5bc2010-03-30 05:34:02 +000070 raw_ostream *Result = new raw_fd_ostream(OutputFilename.c_str(),
Chris Lattnerf8df3e02010-03-29 21:34:06 +000071 Error, raw_fd_ostream::F_Append);
72 if (Error.empty())
73 return Result;
74
75 errs() << "Error opening info-output-file '"
Chris Lattnercebf5bc2010-03-30 05:34:02 +000076 << OutputFilename << " for appending!\n";
Chris Lattnerf8df3e02010-03-29 21:34:06 +000077 delete Result;
Chris Lattner49a2bb22010-03-30 05:01:08 +000078 return new raw_fd_ostream(2, false); // stderr.
Chris Lattnerf8df3e02010-03-29 21:34:06 +000079}
80
81
Owen Anderson200aa6d2009-06-23 16:36:10 +000082static TimerGroup *DefaultTimerGroup = 0;
Chris Lattner6c38a792002-10-01 19:36:54 +000083static TimerGroup *getDefaultTimerGroup() {
Chris Lattner9bb110f2010-03-29 20:35:01 +000084 TimerGroup *tmp = DefaultTimerGroup;
Owen Anderson3b8d1352009-06-23 17:33:37 +000085 sys::MemoryFence();
Chris Lattner9bb110f2010-03-29 20:35:01 +000086 if (tmp) return tmp;
87
88 llvm_acquire_global_lock();
89 tmp = DefaultTimerGroup;
Owen Anderson3b8d1352009-06-23 17:33:37 +000090 if (!tmp) {
Chris Lattner9bb110f2010-03-29 20:35:01 +000091 tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
92 sys::MemoryFence();
93 DefaultTimerGroup = tmp;
Owen Anderson3b8d1352009-06-23 17:33:37 +000094 }
Chris Lattner9bb110f2010-03-29 20:35:01 +000095 llvm_release_global_lock();
Mikhail Glushenkovc11e84d2009-11-07 06:33:12 +000096
Owen Anderson3b8d1352009-06-23 17:33:37 +000097 return tmp;
Chris Lattner6c38a792002-10-01 19:36:54 +000098}
99
Chris Lattner9bb110f2010-03-29 20:35:01 +0000100//===----------------------------------------------------------------------===//
101// Timer Implementation
102//===----------------------------------------------------------------------===//
103
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000104void Timer::init(StringRef N) {
Chris Lattnera782e752010-03-30 04:03:22 +0000105 assert(TG == 0 && "Timer already initialized");
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000106 Name.assign(N.begin(), N.end());
Chris Lattnera782e752010-03-30 04:03:22 +0000107 Started = false;
108 TG = getDefaultTimerGroup();
Chris Lattnerb9312692010-03-30 04:40:01 +0000109 TG->addTimer(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000110}
111
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000112void Timer::init(StringRef N, TimerGroup &tg) {
Chris Lattnera782e752010-03-30 04:03:22 +0000113 assert(TG == 0 && "Timer already initialized");
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000114 Name.assign(N.begin(), N.end());
Chris Lattnera782e752010-03-30 04:03:22 +0000115 Started = false;
116 TG = &tg;
Chris Lattnerb9312692010-03-30 04:40:01 +0000117 TG->addTimer(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000118}
119
Chris Lattner6c38a792002-10-01 19:36:54 +0000120Timer::~Timer() {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000121 if (!TG) return; // Never initialized, or already cleared.
Chris Lattnerb9312692010-03-30 04:40:01 +0000122 TG->removeTimer(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000123}
124
Jeff Cohene269a1a2005-01-08 20:15:57 +0000125static inline size_t getMemUsage() {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000126 if (!TrackSpace) return 0;
127 return sys::Process::GetMallocUsage();
Reid Spenceraeb47b82004-12-27 08:03:04 +0000128}
129
Chris Lattnera782e752010-03-30 04:03:22 +0000130TimeRecord TimeRecord::getCurrentTime(bool Start) {
Chris Lattnerb4db5f32004-06-07 19:34:51 +0000131 TimeRecord Result;
Chris Lattnerecdbff82010-03-30 05:20:02 +0000132 sys::TimeValue now(0,0), user(0,0), sys(0,0);
133
Reid Spencer7d055632004-12-20 21:44:27 +0000134 if (Start) {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000135 Result.MemUsed = getMemUsage();
Chris Lattner9bb110f2010-03-29 20:35:01 +0000136 sys::Process::GetTimeUsage(now, user, sys);
Reid Spencer7d055632004-12-20 21:44:27 +0000137 } else {
Chris Lattner9bb110f2010-03-29 20:35:01 +0000138 sys::Process::GetTimeUsage(now, user, sys);
Chris Lattnerecdbff82010-03-30 05:20:02 +0000139 Result.MemUsed = getMemUsage();
Reid Spencer7d055632004-12-20 21:44:27 +0000140 }
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000141
Chris Lattnera782e752010-03-30 04:03:22 +0000142 Result.WallTime = now.seconds() + now.microseconds() / 1000000.0;
Chris Lattner9bb110f2010-03-29 20:35:01 +0000143 Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
Chris Lattnera782e752010-03-30 04:03:22 +0000144 Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
Chris Lattner6c38a792002-10-01 19:36:54 +0000145 return Result;
146}
147
Chris Lattner90aa8392006-10-04 21:52:35 +0000148static ManagedStatic<std::vector<Timer*> > ActiveTimers;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000149
Chris Lattner6c38a792002-10-01 19:36:54 +0000150void Timer::startTimer() {
151 Started = true;
Dan Gohman153d28a2008-06-24 22:07:07 +0000152 ActiveTimers->push_back(this);
Chris Lattnera782e752010-03-30 04:03:22 +0000153 Time -= TimeRecord::getCurrentTime(true);
Chris Lattner6c38a792002-10-01 19:36:54 +0000154}
155
156void Timer::stopTimer() {
Chris Lattnera782e752010-03-30 04:03:22 +0000157 Time += TimeRecord::getCurrentTime(false);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000158
Chris Lattner90aa8392006-10-04 21:52:35 +0000159 if (ActiveTimers->back() == this) {
160 ActiveTimers->pop_back();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000161 } else {
162 std::vector<Timer*>::iterator I =
Chris Lattner90aa8392006-10-04 21:52:35 +0000163 std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
164 assert(I != ActiveTimers->end() && "stop but no startTimer?");
165 ActiveTimers->erase(I);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000166 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000167}
168
Chris Lattner9bb110f2010-03-29 20:35:01 +0000169static void printVal(double Val, double Total, raw_ostream &OS) {
Chris Lattner0613edc2010-03-29 20:40:19 +0000170 if (Total < 1e-7) // Avoid dividing by zero.
Chris Lattner9bb110f2010-03-29 20:35:01 +0000171 OS << " ----- ";
172 else {
173 OS << " " << format("%7.4f", Val) << " (";
174 OS << format("%5.1f", Val*100/Total) << "%)";
175 }
176}
177
Chris Lattnera782e752010-03-30 04:03:22 +0000178void TimeRecord::print(const TimeRecord &Total, raw_ostream &OS) const {
179 if (Total.getUserTime())
180 printVal(getUserTime(), Total.getUserTime(), OS);
181 if (Total.getSystemTime())
182 printVal(getSystemTime(), Total.getSystemTime(), OS);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000183 if (Total.getProcessTime())
184 printVal(getProcessTime(), Total.getProcessTime(), OS);
Chris Lattnera782e752010-03-30 04:03:22 +0000185 printVal(getWallTime(), Total.getWallTime(), OS);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000186
187 OS << " ";
188
Chris Lattnera782e752010-03-30 04:03:22 +0000189 if (Total.getMemUsed())
190 OS << format("%9lld", (long long)getMemUsed()) << " ";
Chris Lattner9bb110f2010-03-29 20:35:01 +0000191}
192
193
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000194//===----------------------------------------------------------------------===//
195// NamedRegionTimer Implementation
196//===----------------------------------------------------------------------===//
197
Dan Gohmanb3579832010-04-15 17:08:50 +0000198namespace {
199
Chris Lattnera782e752010-03-30 04:03:22 +0000200typedef StringMap<Timer> Name2TimerMap;
Chris Lattnerecdbff82010-03-30 05:20:02 +0000201
202class Name2PairMap {
203 StringMap<std::pair<TimerGroup*, Name2TimerMap> > Map;
204public:
205 ~Name2PairMap() {
206 for (StringMap<std::pair<TimerGroup*, Name2TimerMap> >::iterator
207 I = Map.begin(), E = Map.end(); I != E; ++I)
208 delete I->second.first;
209 }
210
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000211 Timer &get(StringRef Name, StringRef GroupName) {
Chris Lattnerecdbff82010-03-30 05:20:02 +0000212 sys::SmartScopedLock<true> L(*TimerLock);
213
214 std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
215
216 if (!GroupEntry.first)
217 GroupEntry.first = new TimerGroup(GroupName);
218
219 Timer &T = GroupEntry.second[Name];
220 if (!T.isInitialized())
221 T.init(Name, *GroupEntry.first);
222 return T;
223 }
224};
Dan Gohman5e843682008-07-14 18:19:29 +0000225
Dan Gohmanb3579832010-04-15 17:08:50 +0000226}
227
Chris Lattnera782e752010-03-30 04:03:22 +0000228static ManagedStatic<Name2TimerMap> NamedTimers;
229static ManagedStatic<Name2PairMap> NamedGroupedTimers;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000230
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000231static Timer &getNamedRegionTimer(StringRef Name) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000232 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattnera782e752010-03-30 04:03:22 +0000233
234 Timer &T = (*NamedTimers)[Name];
235 if (!T.isInitialized())
236 T.init(Name);
237 return T;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000238}
239
Dan Gohman03c3dc72010-06-18 15:56:31 +0000240NamedRegionTimer::NamedRegionTimer(StringRef Name,
241 bool Enabled)
242 : TimeRegion(!Enabled ? 0 : &getNamedRegionTimer(Name)) {}
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000243
Dan Gohman03c3dc72010-06-18 15:56:31 +0000244NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef GroupName,
245 bool Enabled)
246 : TimeRegion(!Enabled ? 0 : &NamedGroupedTimers->get(Name, GroupName)) {}
Chris Lattner8f0d8242002-11-18 21:47:09 +0000247
Chris Lattner6c38a792002-10-01 19:36:54 +0000248//===----------------------------------------------------------------------===//
249// TimerGroup Implementation
250//===----------------------------------------------------------------------===//
251
Chris Lattner83fa78e2010-03-30 05:27:58 +0000252/// TimerGroupList - This is the global list of TimerGroups, maintained by the
253/// TimerGroup ctor/dtor and is protected by the TimerLock lock.
254static TimerGroup *TimerGroupList = 0;
255
Chris Lattnercebf5bc2010-03-30 05:34:02 +0000256TimerGroup::TimerGroup(StringRef name)
257 : Name(name.begin(), name.end()), FirstTimer(0) {
Chris Lattner83fa78e2010-03-30 05:27:58 +0000258
259 // Add the group to TimerGroupList.
260 sys::SmartScopedLock<true> L(*TimerLock);
261 if (TimerGroupList)
262 TimerGroupList->Prev = &Next;
263 Next = TimerGroupList;
264 Prev = &TimerGroupList;
265 TimerGroupList = this;
266}
267
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000268TimerGroup::~TimerGroup() {
269 // If the timer group is destroyed before the timers it owns, accumulate and
270 // print the timing data.
271 while (FirstTimer != 0)
272 removeTimer(*FirstTimer);
Chris Lattner83fa78e2010-03-30 05:27:58 +0000273
274 // Remove the group from the TimerGroupList.
275 sys::SmartScopedLock<true> L(*TimerLock);
276 *Prev = Next;
277 if (Next)
278 Next->Prev = Prev;
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000279}
280
281
Chris Lattnerb9312692010-03-30 04:40:01 +0000282void TimerGroup::removeTimer(Timer &T) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000283 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000284
Chris Lattnerb9312692010-03-30 04:40:01 +0000285 // If the timer was started, move its data to TimersToPrint.
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000286 if (T.Started)
Chris Lattnerb9312692010-03-30 04:40:01 +0000287 TimersToPrint.push_back(std::make_pair(T.Time, T.Name));
Chris Lattner9f9f6d12010-03-30 04:58:26 +0000288
289 T.TG = 0;
Chris Lattnerb9312692010-03-30 04:40:01 +0000290
291 // Unlink the timer from our list.
292 *T.Prev = T.Next;
293 if (T.Next)
294 T.Next->Prev = T.Prev;
295
296 // Print the report when all timers in this group are destroyed if some of
297 // them were started.
298 if (FirstTimer != 0 || TimersToPrint.empty())
299 return;
300
Chris Lattner49a2bb22010-03-30 05:01:08 +0000301 raw_ostream *OutStream = CreateInfoOutputFile();
Chris Lattnerb9312692010-03-30 04:40:01 +0000302 PrintQueuedTimers(*OutStream);
Chris Lattner49a2bb22010-03-30 05:01:08 +0000303 delete OutStream; // Close the file.
Chris Lattner6c38a792002-10-01 19:36:54 +0000304}
Brian Gaeked0fde302003-11-11 22:41:34 +0000305
Chris Lattnerb9312692010-03-30 04:40:01 +0000306void TimerGroup::addTimer(Timer &T) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000307 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattnerb9312692010-03-30 04:40:01 +0000308
309 // Add the timer to our list.
310 if (FirstTimer)
311 FirstTimer->Prev = &T.Next;
312 T.Next = FirstTimer;
313 T.Prev = &FirstTimer;
314 FirstTimer = &T;
Owen Anderson46d9a642009-06-23 20:52:29 +0000315}
316
Chris Lattnerb9312692010-03-30 04:40:01 +0000317void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
318 // Sort the timers in descending order by amount of time taken.
Benjamin Kramer933b16e2010-08-07 12:37:00 +0000319 array_pod_sort(TimersToPrint.begin(), TimersToPrint.end());
320
Chris Lattnerb9312692010-03-30 04:40:01 +0000321 TimeRecord Total;
322 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
323 Total += TimersToPrint[i].first;
324
325 // Print out timing header.
326 OS << "===" << std::string(73, '-') << "===\n";
327 // Figure out how many spaces to indent TimerGroup name.
328 unsigned Padding = (80-Name.length())/2;
329 if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
330 OS.indent(Padding) << Name << '\n';
331 OS << "===" << std::string(73, '-') << "===\n";
332
333 // If this is not an collection of ungrouped times, print the total time.
334 // Ungrouped timers don't really make sense to add up. We still print the
335 // TOTAL line to make the percentages make sense.
336 if (this != DefaultTimerGroup) {
337 OS << " Total Execution Time: ";
338 OS << format("%5.4f", Total.getProcessTime()) << " seconds (";
339 OS << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
340 }
341 OS << '\n';
342
343 if (Total.getUserTime())
344 OS << " ---User Time---";
345 if (Total.getSystemTime())
346 OS << " --System Time--";
347 if (Total.getProcessTime())
348 OS << " --User+System--";
349 OS << " ---Wall Time---";
350 if (Total.getMemUsed())
351 OS << " ---Mem---";
352 OS << " --- Name ---\n";
353
354 // Loop through all of the timing data, printing it out.
355 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i) {
356 const std::pair<TimeRecord, std::string> &Entry = TimersToPrint[e-i-1];
357 Entry.first.print(Total, OS);
358 OS << Entry.second << '\n';
359 }
360
361 Total.print(Total, OS);
362 OS << "Total\n\n";
363 OS.flush();
364
365 TimersToPrint.clear();
Owen Anderson46d9a642009-06-23 20:52:29 +0000366}
367
Chris Lattnerecdbff82010-03-30 05:20:02 +0000368/// print - Print any started timers in this group and zero them.
369void TimerGroup::print(raw_ostream &OS) {
370 sys::SmartScopedLock<true> L(*TimerLock);
371
372 // See if any of our timers were started, if so add them to TimersToPrint and
373 // reset them.
374 for (Timer *T = FirstTimer; T; T = T->Next) {
375 if (!T->Started) continue;
376 TimersToPrint.push_back(std::make_pair(T->Time, T->Name));
377
378 // Clear out the time.
379 T->Started = 0;
380 T->Time = TimeRecord();
381 }
382
383 // If any timers were started, print the group.
384 if (!TimersToPrint.empty())
385 PrintQueuedTimers(OS);
386}
Chris Lattner83fa78e2010-03-30 05:27:58 +0000387
388/// printAll - This static method prints all timers and clears them all out.
389void TimerGroup::printAll(raw_ostream &OS) {
390 sys::SmartScopedLock<true> L(*TimerLock);
391
392 for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
393 TG->print(OS);
394}