blob: 4dbb34c8a9432bf86d728305d75b7d339a775b1b [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
David Greeneda80ff62010-01-05 01:28:58 +000014#include "llvm/Support/Debug.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000015#include "llvm/Support/Timer.h"
16#include "llvm/Support/CommandLine.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"
Reid Spencerdf52c9a2004-12-20 00:59:04 +000020#include "llvm/System/Process.h"
Reid Spencer0255abb2004-12-20 03:59:23 +000021#include <algorithm>
Reid Spencer0255abb2004-12-20 03:59:23 +000022#include <functional>
Chris Lattnerb4db5f32004-06-07 19:34:51 +000023#include <map>
Chris Lattnerb6d465f2003-12-14 21:27:33 +000024using namespace llvm;
Chris Lattnerf205fec2003-05-09 20:05:44 +000025
Chris Lattnerb4db5f32004-06-07 19:34:51 +000026// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
Chris Lattnerd9ea85a2009-08-23 08:43:55 +000027namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
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
Owen Anderson200aa6d2009-06-23 16:36:10 +000056static TimerGroup *DefaultTimerGroup = 0;
Chris Lattner6c38a792002-10-01 19:36:54 +000057static TimerGroup *getDefaultTimerGroup() {
Chris Lattner9bb110f2010-03-29 20:35:01 +000058 TimerGroup *tmp = DefaultTimerGroup;
Owen Anderson3b8d1352009-06-23 17:33:37 +000059 sys::MemoryFence();
Chris Lattner9bb110f2010-03-29 20:35:01 +000060 if (tmp) return tmp;
61
62 llvm_acquire_global_lock();
63 tmp = DefaultTimerGroup;
Owen Anderson3b8d1352009-06-23 17:33:37 +000064 if (!tmp) {
Chris Lattner9bb110f2010-03-29 20:35:01 +000065 tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
66 sys::MemoryFence();
67 DefaultTimerGroup = tmp;
Owen Anderson3b8d1352009-06-23 17:33:37 +000068 }
Chris Lattner9bb110f2010-03-29 20:35:01 +000069 llvm_release_global_lock();
Mikhail Glushenkovc11e84d2009-11-07 06:33:12 +000070
Owen Anderson3b8d1352009-06-23 17:33:37 +000071 return tmp;
Chris Lattner6c38a792002-10-01 19:36:54 +000072}
73
Chris Lattner9bb110f2010-03-29 20:35:01 +000074//===----------------------------------------------------------------------===//
75// Timer Implementation
76//===----------------------------------------------------------------------===//
77
Chris Lattner6c38a792002-10-01 19:36:54 +000078Timer::Timer(const std::string &N)
Chris Lattner8f0d8242002-11-18 21:47:09 +000079 : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
Chris Lattner6c38a792002-10-01 19:36:54 +000080 Started(false), TG(getDefaultTimerGroup()) {
81 TG->addTimer();
82}
83
84Timer::Timer(const std::string &N, TimerGroup &tg)
Chris Lattner8f0d8242002-11-18 21:47:09 +000085 : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
Chris Lattner6c38a792002-10-01 19:36:54 +000086 Started(false), TG(&tg) {
87 TG->addTimer();
88}
89
90Timer::Timer(const Timer &T) {
91 TG = T.TG;
92 if (TG) TG->addTimer();
93 operator=(T);
94}
95
Chris Lattner6c38a792002-10-01 19:36:54 +000096// Copy ctor, initialize with no TG member.
97Timer::Timer(bool, const Timer &T) {
98 TG = T.TG; // Avoid assertion in operator=
99 operator=(T); // Copy contents
100 TG = 0;
101}
102
Chris Lattner6c38a792002-10-01 19:36:54 +0000103Timer::~Timer() {
Chris Lattner9bb110f2010-03-29 20:35:01 +0000104 if (!TG) return;
105
106 if (Started) {
107 Started = false;
108 TG->addTimerToPrint(*this);
Chris Lattner6c38a792002-10-01 19:36:54 +0000109 }
Chris Lattner9bb110f2010-03-29 20:35:01 +0000110 TG->removeTimer();
Chris Lattner6c38a792002-10-01 19:36:54 +0000111}
112
Jeff Cohene269a1a2005-01-08 20:15:57 +0000113static inline size_t getMemUsage() {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000114 if (TrackSpace)
Jeff Cohene269a1a2005-01-08 20:15:57 +0000115 return sys::Process::GetMallocUsage();
Reid Spenceraeb47b82004-12-27 08:03:04 +0000116 return 0;
117}
118
Chris Lattner6c38a792002-10-01 19:36:54 +0000119struct TimeRecord {
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000120 double Elapsed, UserTime, SystemTime;
121 ssize_t MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000122};
123
Chris Lattner8f0d8242002-11-18 21:47:09 +0000124static TimeRecord getTimeRecord(bool Start) {
Chris Lattnerb4db5f32004-06-07 19:34:51 +0000125 TimeRecord Result;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000126
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000127 sys::TimeValue now(0,0);
128 sys::TimeValue user(0,0);
129 sys::TimeValue sys(0,0);
Chris Lattner6c38a792002-10-01 19:36:54 +0000130
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000131 ssize_t MemUsed = 0;
Reid Spencer7d055632004-12-20 21:44:27 +0000132 if (Start) {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000133 MemUsed = getMemUsage();
Chris Lattner9bb110f2010-03-29 20:35:01 +0000134 sys::Process::GetTimeUsage(now, user, sys);
Reid Spencer7d055632004-12-20 21:44:27 +0000135 } else {
Chris Lattner9bb110f2010-03-29 20:35:01 +0000136 sys::Process::GetTimeUsage(now, user, sys);
Chris Lattnerfed1b272005-03-22 03:20:38 +0000137 MemUsed = getMemUsage();
Reid Spencer7d055632004-12-20 21:44:27 +0000138 }
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000139
Chris Lattner9bb110f2010-03-29 20:35:01 +0000140 Result.Elapsed = now.seconds() + now.microseconds() / 1000000.0;
141 Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
142 Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
143 Result.MemUsed = MemUsed;
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() {
Owen Anderson252e5742009-11-17 07:06:10 +0000150 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +0000151 Started = true;
Dan Gohman153d28a2008-06-24 22:07:07 +0000152 ActiveTimers->push_back(this);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000153 TimeRecord TR = getTimeRecord(true);
Chris Lattner6c38a792002-10-01 19:36:54 +0000154 Elapsed -= TR.Elapsed;
155 UserTime -= TR.UserTime;
156 SystemTime -= TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000157 MemUsed -= TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000158 PeakMemBase = TR.MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000159}
160
161void Timer::stopTimer() {
Owen Anderson252e5742009-11-17 07:06:10 +0000162 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000163 TimeRecord TR = getTimeRecord(false);
Chris Lattner6c38a792002-10-01 19:36:54 +0000164 Elapsed += TR.Elapsed;
165 UserTime += TR.UserTime;
166 SystemTime += TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000167 MemUsed += TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000168
Chris Lattner90aa8392006-10-04 21:52:35 +0000169 if (ActiveTimers->back() == this) {
170 ActiveTimers->pop_back();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000171 } else {
172 std::vector<Timer*>::iterator I =
Chris Lattner90aa8392006-10-04 21:52:35 +0000173 std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
174 assert(I != ActiveTimers->end() && "stop but no startTimer?");
175 ActiveTimers->erase(I);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000176 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000177}
178
179void Timer::sum(const Timer &T) {
180 Elapsed += T.Elapsed;
181 UserTime += T.UserTime;
182 SystemTime += T.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000183 MemUsed += T.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000184 PeakMem += T.PeakMem;
Chris Lattner6c38a792002-10-01 19:36:54 +0000185}
186
Chris Lattner8f0d8242002-11-18 21:47:09 +0000187/// addPeakMemoryMeasurement - This method should be called whenever memory
188/// usage needs to be checked. It adds a peak memory measurement to the
189/// currently active timers, which will be printed when the timer group prints
190///
191void Timer::addPeakMemoryMeasurement() {
Owen Anderson252e5742009-11-17 07:06:10 +0000192 sys::SmartScopedLock<true> L(*TimerLock);
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000193 size_t MemUsed = getMemUsage();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000194
Chris Lattner90aa8392006-10-04 21:52:35 +0000195 for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
Owen Anderson252e5742009-11-17 07:06:10 +0000196 E = ActiveTimers->end(); I != E; ++I)
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000197 (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000198}
199
Chris Lattner9bb110f2010-03-29 20:35:01 +0000200
201static void printVal(double Val, double Total, raw_ostream &OS) {
Chris Lattner0613edc2010-03-29 20:40:19 +0000202 if (Total < 1e-7) // Avoid dividing by zero.
Chris Lattner9bb110f2010-03-29 20:35:01 +0000203 OS << " ----- ";
204 else {
205 OS << " " << format("%7.4f", Val) << " (";
206 OS << format("%5.1f", Val*100/Total) << "%)";
207 }
208}
209
210void Timer::print(const Timer &Total, raw_ostream &OS) {
211 sys::SmartScopedLock<true> L(*TimerLock);
212 if (Total.UserTime)
213 printVal(UserTime, Total.UserTime, OS);
214 if (Total.SystemTime)
215 printVal(SystemTime, Total.SystemTime, OS);
216 if (Total.getProcessTime())
217 printVal(getProcessTime(), Total.getProcessTime(), OS);
218 printVal(Elapsed, Total.Elapsed, OS);
219
220 OS << " ";
221
222 if (Total.MemUsed) {
223 OS << format("%9lld", (long long)MemUsed) << " ";
224 }
225 if (Total.PeakMem) {
226 if (PeakMem) {
227 OS << format("%9lld", (long long)PeakMem) << " ";
228 } else
229 OS << " ";
230 }
231 OS << Name << "\n";
232
233 Started = false; // Once printed, don't print again
234}
235
236
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000237//===----------------------------------------------------------------------===//
238// NamedRegionTimer Implementation
239//===----------------------------------------------------------------------===//
240
Dan Gohman5e843682008-07-14 18:19:29 +0000241typedef std::map<std::string, Timer> Name2Timer;
242typedef std::map<std::string, std::pair<TimerGroup, Name2Timer> > Name2Pair;
243
Dan Gohman5e843682008-07-14 18:19:29 +0000244static ManagedStatic<Name2Timer> NamedTimers;
Dan Gohman5e843682008-07-14 18:19:29 +0000245static ManagedStatic<Name2Pair> NamedGroupedTimers;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000246
Chris Lattner90aa8392006-10-04 21:52:35 +0000247static Timer &getNamedRegionTimer(const std::string &Name) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000248 sys::SmartScopedLock<true> L(*TimerLock);
Dan Gohman5e843682008-07-14 18:19:29 +0000249 Name2Timer::iterator I = NamedTimers->find(Name);
Dan Gohmanc418bf32008-07-11 20:58:19 +0000250 if (I != NamedTimers->end())
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000251 return I->second;
252
Chris Lattner90aa8392006-10-04 21:52:35 +0000253 return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000254}
255
Dan Gohman5e843682008-07-14 18:19:29 +0000256static Timer &getNamedRegionTimer(const std::string &Name,
257 const std::string &GroupName) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000258 sys::SmartScopedLock<true> L(*TimerLock);
Dan Gohman5e843682008-07-14 18:19:29 +0000259
260 Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
261 if (I == NamedGroupedTimers->end()) {
262 TimerGroup TG(GroupName);
263 std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
264 I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
265 }
266
267 Name2Timer::iterator J = I->second.second.find(Name);
268 if (J == I->second.second.end())
269 J = I->second.second.insert(J,
270 std::make_pair(Name,
271 Timer(Name,
272 I->second.first)));
273
274 return J->second;
275}
276
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000277NamedRegionTimer::NamedRegionTimer(const std::string &Name)
278 : TimeRegion(getNamedRegionTimer(Name)) {}
279
Dan Gohman5e843682008-07-14 18:19:29 +0000280NamedRegionTimer::NamedRegionTimer(const std::string &Name,
281 const std::string &GroupName)
282 : TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
Chris Lattner8f0d8242002-11-18 21:47:09 +0000283
Chris Lattner6c38a792002-10-01 19:36:54 +0000284//===----------------------------------------------------------------------===//
285// TimerGroup Implementation
286//===----------------------------------------------------------------------===//
287
Chris Lattner0613edc2010-03-29 20:40:19 +0000288// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
Chris Lattnerd9ea85a2009-08-23 08:43:55 +0000289raw_ostream *
Chris Lattnerb6d465f2003-12-14 21:27:33 +0000290llvm::GetLibSupportInfoOutputFile() {
Chris Lattner71336a92003-07-31 19:38:34 +0000291 std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000292 if (LibSupportInfoOutputFilename.empty())
Chris Lattnerd9ea85a2009-08-23 08:43:55 +0000293 return &errs();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000294 if (LibSupportInfoOutputFilename == "-")
Chris Lattnerd9ea85a2009-08-23 08:43:55 +0000295 return &outs();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000296
Mikhail Glushenkovc11e84d2009-11-07 06:33:12 +0000297
Chris Lattnerd9ea85a2009-08-23 08:43:55 +0000298 std::string Error;
299 raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
300 Error, raw_fd_ostream::F_Append);
301 if (Error.empty())
302 return Result;
Mikhail Glushenkovc11e84d2009-11-07 06:33:12 +0000303
Chris Lattnerd9ea85a2009-08-23 08:43:55 +0000304 errs() << "Error opening info-output-file '"
Bill Wendlingbcd24982006-12-07 20:28:15 +0000305 << LibSupportInfoOutputFilename << " for appending!\n";
Chris Lattnerd9ea85a2009-08-23 08:43:55 +0000306 delete Result;
307 return &errs();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000308}
309
Chris Lattner6c38a792002-10-01 19:36:54 +0000310
311void TimerGroup::removeTimer() {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000312 sys::SmartScopedLock<true> L(*TimerLock);
Chris Lattner9bb110f2010-03-29 20:35:01 +0000313 if (--NumTimers != 0 || TimersToPrint.empty())
314 return; // Don't print timing report.
315
316 // Sort the timers in descending order by amount of time taken.
317 std::sort(TimersToPrint.begin(), TimersToPrint.end(),
318 std::greater<Timer>());
Chris Lattner6c38a792002-10-01 19:36:54 +0000319
Chris Lattner9bb110f2010-03-29 20:35:01 +0000320 // Figure out how many spaces to indent TimerGroup name.
321 unsigned Padding = (80-Name.length())/2;
322 if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
Chris Lattner6c38a792002-10-01 19:36:54 +0000323
Chris Lattner9bb110f2010-03-29 20:35:01 +0000324 raw_ostream *OutStream = GetLibSupportInfoOutputFile();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000325
Chris Lattner9bb110f2010-03-29 20:35:01 +0000326 ++NumTimers;
Chris Lattner0613edc2010-03-29 20:40:19 +0000327 { // Scope to contain Total timer: don't allow total timer to drop us to
328 // zero timers.
Chris Lattner9bb110f2010-03-29 20:35:01 +0000329 Timer Total("TOTAL");
Misha Brukmanf976c852005-04-21 22:55:34 +0000330
Chris Lattner9bb110f2010-03-29 20:35:01 +0000331 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
332 Total.sum(TimersToPrint[i]);
Misha Brukmanf976c852005-04-21 22:55:34 +0000333
Chris Lattner0613edc2010-03-29 20:40:19 +0000334 // Print out timing header.
Chris Lattner9bb110f2010-03-29 20:35:01 +0000335 *OutStream << "===" << std::string(73, '-') << "===\n"
336 << std::string(Padding, ' ') << Name << "\n"
337 << "===" << std::string(73, '-')
338 << "===\n";
Chris Lattner8166b7c2003-02-13 16:25:28 +0000339
Chris Lattner9bb110f2010-03-29 20:35:01 +0000340 // If this is not an collection of ungrouped times, print the total time.
341 // Ungrouped timers don't really make sense to add up. We still print the
342 // TOTAL line to make the percentages make sense.
343 if (this != DefaultTimerGroup) {
344 *OutStream << " Total Execution Time: ";
Chris Lattner3ac96052005-02-09 18:41:32 +0000345
Chris Lattner9bb110f2010-03-29 20:35:01 +0000346 *OutStream << format("%5.4f", Total.getProcessTime()) << " seconds (";
347 *OutStream << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
Chris Lattner6c38a792002-10-01 19:36:54 +0000348 }
Chris Lattner9bb110f2010-03-29 20:35:01 +0000349 *OutStream << "\n";
Chris Lattner6c38a792002-10-01 19:36:54 +0000350
Chris Lattner9bb110f2010-03-29 20:35:01 +0000351 if (Total.UserTime)
352 *OutStream << " ---User Time---";
353 if (Total.SystemTime)
354 *OutStream << " --System Time--";
355 if (Total.getProcessTime())
356 *OutStream << " --User+System--";
357 *OutStream << " ---Wall Time---";
358 if (Total.getMemUsed())
359 *OutStream << " ---Mem---";
360 if (Total.getPeakMem())
361 *OutStream << " -PeakMem-";
362 *OutStream << " --- Name ---\n";
Chris Lattnerf205fec2003-05-09 20:05:44 +0000363
Chris Lattner0613edc2010-03-29 20:40:19 +0000364 // Loop through all of the timing data, printing it out.
Chris Lattner9bb110f2010-03-29 20:35:01 +0000365 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
366 TimersToPrint[i].print(Total, *OutStream);
367
368 Total.print(Total, *OutStream);
369 *OutStream << '\n';
370 OutStream->flush();
Chris Lattner6c38a792002-10-01 19:36:54 +0000371 }
Chris Lattner9bb110f2010-03-29 20:35:01 +0000372 --NumTimers;
373
374 TimersToPrint.clear();
375
376 if (OutStream != &errs() && OutStream != &outs() && OutStream != &dbgs())
Chris Lattner0613edc2010-03-29 20:40:19 +0000377 delete OutStream; // Close the file.
Chris Lattner6c38a792002-10-01 19:36:54 +0000378}
Brian Gaeked0fde302003-11-11 22:41:34 +0000379
Owen Anderson46d9a642009-06-23 20:52:29 +0000380void TimerGroup::addTimer() {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000381 sys::SmartScopedLock<true> L(*TimerLock);
Owen Anderson46d9a642009-06-23 20:52:29 +0000382 ++NumTimers;
383}
384
385void TimerGroup::addTimerToPrint(const Timer &T) {
Owen Andersona9d1f2c2009-07-07 18:33:04 +0000386 sys::SmartScopedLock<true> L(*TimerLock);
Owen Anderson46d9a642009-06-23 20:52:29 +0000387 TimersToPrint.push_back(Timer(true, T));
388}
389