blob: c4920f0ba573ad4bee57d2119272f3d5f15c079f [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 Lattner90aa8392006-10-04 21:52:35 +000016#include "llvm/Support/ManagedStatic.h"
Bill Wendlingbcd24982006-12-07 20:28:15 +000017#include "llvm/Support/Streams.h"
Owen Andersonaf2e2b52009-06-22 23:37:06 +000018#include "llvm/System/Mutex.h"
Reid Spencerdf52c9a2004-12-20 00:59:04 +000019#include "llvm/System/Process.h"
Reid Spencer0255abb2004-12-20 03:59:23 +000020#include <algorithm>
Chris Lattnerb4db5f32004-06-07 19:34:51 +000021#include <fstream>
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 Lattnerb6d465f2003-12-14 21:27:33 +000027namespace llvm { extern std::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
Chris Lattner3f398492003-01-30 23:08:50 +000042namespace {
Dan Gohman3c02aca2008-04-23 23:15:23 +000043 static cl::opt<bool>
Chris Lattner3f398492003-01-30 23:08:50 +000044 TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
45 "tracking (this may be slow)"),
46 cl::Hidden);
Chris Lattnerf205fec2003-05-09 20:05:44 +000047
Dan Gohman3c02aca2008-04-23 23:15:23 +000048 static cl::opt<std::string, true>
Chris Lattner96a54db2003-08-01 22:15:15 +000049 InfoOutputFilename("info-output-file", cl::value_desc("filename"),
Chris Lattnerf205fec2003-05-09 20:05:44 +000050 cl::desc("File to append -stats and -timer output to"),
Chris Lattner71336a92003-07-31 19:38:34 +000051 cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
Chris Lattner3f398492003-01-30 23:08:50 +000052}
53
Owen Andersonaf2e2b52009-06-22 23:37:06 +000054static ManagedStatic<sys::SmartMutex<true> > TimerLock;
55static ManagedStatic<TimerGroup> DefaultTimerGroup;
Chris Lattner6c38a792002-10-01 19:36:54 +000056static TimerGroup *getDefaultTimerGroup() {
Owen Andersonaf2e2b52009-06-22 23:37:06 +000057 return &*DefaultTimerGroup;
Chris Lattner6c38a792002-10-01 19:36:54 +000058}
59
60Timer::Timer(const std::string &N)
Chris Lattner8f0d8242002-11-18 21:47:09 +000061 : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
Chris Lattner6c38a792002-10-01 19:36:54 +000062 Started(false), TG(getDefaultTimerGroup()) {
Owen Andersonaf2e2b52009-06-22 23:37:06 +000063 sys::SmartScopedLock<true> Lock(&*TimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +000064 TG->addTimer();
65}
66
67Timer::Timer(const std::string &N, TimerGroup &tg)
Chris Lattner8f0d8242002-11-18 21:47:09 +000068 : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
Chris Lattner6c38a792002-10-01 19:36:54 +000069 Started(false), TG(&tg) {
Owen Andersonaf2e2b52009-06-22 23:37:06 +000070 sys::SmartScopedLock<true> Lock(&*TimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +000071 TG->addTimer();
72}
73
74Timer::Timer(const Timer &T) {
Owen Andersonaf2e2b52009-06-22 23:37:06 +000075 sys::SmartScopedLock<true> Lock(&*TimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +000076 TG = T.TG;
77 if (TG) TG->addTimer();
78 operator=(T);
79}
80
81
82// Copy ctor, initialize with no TG member.
83Timer::Timer(bool, const Timer &T) {
Owen Andersonaf2e2b52009-06-22 23:37:06 +000084 sys::SmartScopedLock<true> Lock(&*TimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +000085 TG = T.TG; // Avoid assertion in operator=
86 operator=(T); // Copy contents
87 TG = 0;
88}
89
90
91Timer::~Timer() {
Owen Andersonaf2e2b52009-06-22 23:37:06 +000092 sys::SmartScopedLock<true> Lock(&*TimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +000093 if (TG) {
94 if (Started) {
95 Started = false;
96 TG->addTimerToPrint(*this);
97 }
98 TG->removeTimer();
99 }
100}
101
Jeff Cohene269a1a2005-01-08 20:15:57 +0000102static inline size_t getMemUsage() {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000103 if (TrackSpace)
Jeff Cohene269a1a2005-01-08 20:15:57 +0000104 return sys::Process::GetMallocUsage();
Reid Spenceraeb47b82004-12-27 08:03:04 +0000105 return 0;
106}
107
Chris Lattner6c38a792002-10-01 19:36:54 +0000108struct TimeRecord {
109 double Elapsed, UserTime, SystemTime;
Chris Lattner6cfbd622005-01-29 05:21:16 +0000110 ssize_t MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000111};
112
Chris Lattner8f0d8242002-11-18 21:47:09 +0000113static TimeRecord getTimeRecord(bool Start) {
Chris Lattnerb4db5f32004-06-07 19:34:51 +0000114 TimeRecord Result;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000115
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000116 sys::TimeValue now(0,0);
117 sys::TimeValue user(0,0);
118 sys::TimeValue sys(0,0);
Chris Lattner6c38a792002-10-01 19:36:54 +0000119
Chris Lattner6cfbd622005-01-29 05:21:16 +0000120 ssize_t MemUsed = 0;
Reid Spencer7d055632004-12-20 21:44:27 +0000121 if (Start) {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000122 MemUsed = getMemUsage();
Chris Lattnerfed1b272005-03-22 03:20:38 +0000123 sys::Process::GetTimeUsage(now,user,sys);
Reid Spencer7d055632004-12-20 21:44:27 +0000124 } else {
Reid Spencer7d055632004-12-20 21:44:27 +0000125 sys::Process::GetTimeUsage(now,user,sys);
Chris Lattnerfed1b272005-03-22 03:20:38 +0000126 MemUsed = getMemUsage();
Reid Spencer7d055632004-12-20 21:44:27 +0000127 }
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000128
Reid Spencer7d055632004-12-20 21:44:27 +0000129 Result.Elapsed = now.seconds() + now.microseconds() / 1000000.0;
130 Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
131 Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
132 Result.MemUsed = MemUsed;
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000133
Chris Lattner6c38a792002-10-01 19:36:54 +0000134 return Result;
135}
136
Chris Lattner90aa8392006-10-04 21:52:35 +0000137static ManagedStatic<std::vector<Timer*> > ActiveTimers;
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000138static ManagedStatic<sys::SmartMutex<true> > ActiveTimerLock;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000139
Chris Lattner6c38a792002-10-01 19:36:54 +0000140void Timer::startTimer() {
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000141 sys::SmartScopedLock<true> Lock(&*ActiveTimerLock);
Chris Lattner6c38a792002-10-01 19:36:54 +0000142 Started = true;
Dan Gohman153d28a2008-06-24 22:07:07 +0000143 ActiveTimers->push_back(this);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000144 TimeRecord TR = getTimeRecord(true);
Chris Lattner6c38a792002-10-01 19:36:54 +0000145 Elapsed -= TR.Elapsed;
146 UserTime -= TR.UserTime;
147 SystemTime -= TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000148 MemUsed -= TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000149 PeakMemBase = TR.MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000150}
151
152void Timer::stopTimer() {
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000153 sys::SmartScopedLock<true> Lock(&*ActiveTimerLock);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000154 TimeRecord TR = getTimeRecord(false);
Chris Lattner6c38a792002-10-01 19:36:54 +0000155 Elapsed += TR.Elapsed;
156 UserTime += TR.UserTime;
157 SystemTime += TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000158 MemUsed += TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000159
Chris Lattner90aa8392006-10-04 21:52:35 +0000160 if (ActiveTimers->back() == this) {
161 ActiveTimers->pop_back();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000162 } else {
163 std::vector<Timer*>::iterator I =
Chris Lattner90aa8392006-10-04 21:52:35 +0000164 std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
165 assert(I != ActiveTimers->end() && "stop but no startTimer?");
166 ActiveTimers->erase(I);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000167 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000168}
169
170void Timer::sum(const Timer &T) {
171 Elapsed += T.Elapsed;
172 UserTime += T.UserTime;
173 SystemTime += T.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000174 MemUsed += T.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000175 PeakMem += T.PeakMem;
Chris Lattner6c38a792002-10-01 19:36:54 +0000176}
177
Chris Lattner8f0d8242002-11-18 21:47:09 +0000178/// addPeakMemoryMeasurement - This method should be called whenever memory
179/// usage needs to be checked. It adds a peak memory measurement to the
180/// currently active timers, which will be printed when the timer group prints
181///
182void Timer::addPeakMemoryMeasurement() {
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000183 sys::SmartScopedLock<true> Lock(&*ActiveTimerLock);
Jeff Cohene269a1a2005-01-08 20:15:57 +0000184 size_t MemUsed = getMemUsage();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000185
Chris Lattner90aa8392006-10-04 21:52:35 +0000186 for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
187 E = ActiveTimers->end(); I != E; ++I)
Chris Lattner8f0d8242002-11-18 21:47:09 +0000188 (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
189}
190
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000191//===----------------------------------------------------------------------===//
192// NamedRegionTimer Implementation
193//===----------------------------------------------------------------------===//
194
Dan Gohman5e843682008-07-14 18:19:29 +0000195namespace {
196
197typedef std::map<std::string, Timer> Name2Timer;
198typedef std::map<std::string, std::pair<TimerGroup, Name2Timer> > Name2Pair;
199
200}
201
202static ManagedStatic<Name2Timer> NamedTimers;
203
204static ManagedStatic<Name2Pair> NamedGroupedTimers;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000205
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000206static ManagedStatic<sys::SmartMutex<true> > NamedTimerLock;
207
Chris Lattner90aa8392006-10-04 21:52:35 +0000208static Timer &getNamedRegionTimer(const std::string &Name) {
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000209 sys::SmartScopedLock<true> Lock(&*NamedTimerLock);
Dan Gohman5e843682008-07-14 18:19:29 +0000210 Name2Timer::iterator I = NamedTimers->find(Name);
Dan Gohmanc418bf32008-07-11 20:58:19 +0000211 if (I != NamedTimers->end())
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000212 return I->second;
213
Chris Lattner90aa8392006-10-04 21:52:35 +0000214 return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000215}
216
Dan Gohman5e843682008-07-14 18:19:29 +0000217static Timer &getNamedRegionTimer(const std::string &Name,
218 const std::string &GroupName) {
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000219 sys::SmartScopedLock<true> Lock(&*NamedTimerLock);
Dan Gohman5e843682008-07-14 18:19:29 +0000220
221 Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
222 if (I == NamedGroupedTimers->end()) {
223 TimerGroup TG(GroupName);
224 std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
225 I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
226 }
227
228 Name2Timer::iterator J = I->second.second.find(Name);
229 if (J == I->second.second.end())
230 J = I->second.second.insert(J,
231 std::make_pair(Name,
232 Timer(Name,
233 I->second.first)));
234
235 return J->second;
236}
237
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000238NamedRegionTimer::NamedRegionTimer(const std::string &Name)
239 : TimeRegion(getNamedRegionTimer(Name)) {}
240
Dan Gohman5e843682008-07-14 18:19:29 +0000241NamedRegionTimer::NamedRegionTimer(const std::string &Name,
242 const std::string &GroupName)
243 : TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
Chris Lattner8f0d8242002-11-18 21:47:09 +0000244
Chris Lattner6c38a792002-10-01 19:36:54 +0000245//===----------------------------------------------------------------------===//
246// TimerGroup Implementation
247//===----------------------------------------------------------------------===//
248
Chris Lattnerf205fec2003-05-09 20:05:44 +0000249// printAlignedFP - Simulate the printf "%A.Bf" format, where A is the
250// TotalWidth size, and B is the AfterDec size.
251//
252static void printAlignedFP(double Val, unsigned AfterDec, unsigned TotalWidth,
253 std::ostream &OS) {
254 assert(TotalWidth >= AfterDec+1 && "Bad FP Format!");
255 OS.width(TotalWidth-AfterDec-1);
256 char OldFill = OS.fill();
257 OS.fill(' ');
258 OS << (int)Val; // Integer part;
259 OS << ".";
260 OS.width(AfterDec);
261 OS.fill('0');
262 unsigned ResultFieldSize = 1;
263 while (AfterDec--) ResultFieldSize *= 10;
264 OS << (int)(Val*ResultFieldSize) % ResultFieldSize;
265 OS.fill(OldFill);
Chris Lattner6c38a792002-10-01 19:36:54 +0000266}
267
Chris Lattnerf205fec2003-05-09 20:05:44 +0000268static void printVal(double Val, double Total, std::ostream &OS) {
269 if (Total < 1e-7) // Avoid dividing by zero...
270 OS << " ----- ";
271 else {
272 OS << " ";
273 printAlignedFP(Val, 4, 7, OS);
274 OS << " (";
275 printAlignedFP(Val*100/Total, 1, 5, OS);
276 OS << "%)";
Chris Lattner8f0d8242002-11-18 21:47:09 +0000277 }
Chris Lattnerf205fec2003-05-09 20:05:44 +0000278}
279
280void Timer::print(const Timer &Total, std::ostream &OS) {
281 if (Total.UserTime)
282 printVal(UserTime, Total.UserTime, OS);
283 if (Total.SystemTime)
284 printVal(SystemTime, Total.SystemTime, OS);
285 if (Total.getProcessTime())
286 printVal(getProcessTime(), Total.getProcessTime(), OS);
287 printVal(Elapsed, Total.Elapsed, OS);
Misha Brukmanf976c852005-04-21 22:55:34 +0000288
Chris Lattnerf205fec2003-05-09 20:05:44 +0000289 OS << " ";
290
291 if (Total.MemUsed) {
292 OS.width(9);
293 OS << MemUsed << " ";
294 }
295 if (Total.PeakMem) {
296 if (PeakMem) {
297 OS.width(9);
298 OS << PeakMem << " ";
299 } else
300 OS << " ";
301 }
302 OS << Name << "\n";
Chris Lattner6c38a792002-10-01 19:36:54 +0000303
304 Started = false; // Once printed, don't print again
305}
306
Chris Lattnerf205fec2003-05-09 20:05:44 +0000307// GetLibSupportInfoOutputFile - Return a file stream to print our output on...
Brian Gaeked0fde302003-11-11 22:41:34 +0000308std::ostream *
Chris Lattnerb6d465f2003-12-14 21:27:33 +0000309llvm::GetLibSupportInfoOutputFile() {
Chris Lattner71336a92003-07-31 19:38:34 +0000310 std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000311 if (LibSupportInfoOutputFilename.empty())
Bill Wendlingbcd24982006-12-07 20:28:15 +0000312 return cerr.stream();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000313 if (LibSupportInfoOutputFilename == "-")
Bill Wendlingbcd24982006-12-07 20:28:15 +0000314 return cout.stream();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000315
316 std::ostream *Result = new std::ofstream(LibSupportInfoOutputFilename.c_str(),
Chris Lattner903c2d12003-06-06 22:13:01 +0000317 std::ios::app);
Chris Lattnerf205fec2003-05-09 20:05:44 +0000318 if (!Result->good()) {
Bill Wendlingbcd24982006-12-07 20:28:15 +0000319 cerr << "Error opening info-output-file '"
320 << LibSupportInfoOutputFilename << " for appending!\n";
Chris Lattnerf205fec2003-05-09 20:05:44 +0000321 delete Result;
Bill Wendlingbcd24982006-12-07 20:28:15 +0000322 return cerr.stream();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000323 }
324 return Result;
325}
326
Chris Lattner6c38a792002-10-01 19:36:54 +0000327
328void TimerGroup::removeTimer() {
329 if (--NumTimers == 0 && !TimersToPrint.empty()) { // Print timing report...
330 // Sort the timers in descending order by amount of time taken...
331 std::sort(TimersToPrint.begin(), TimersToPrint.end(),
332 std::greater<Timer>());
333
334 // Figure out how many spaces to indent TimerGroup name...
335 unsigned Padding = (80-Name.length())/2;
336 if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
337
Chris Lattnerf205fec2003-05-09 20:05:44 +0000338 std::ostream *OutStream = GetLibSupportInfoOutputFile();
339
Chris Lattner6c38a792002-10-01 19:36:54 +0000340 ++NumTimers;
341 { // Scope to contain Total timer... don't allow total timer to drop us to
342 // zero timers...
343 Timer Total("TOTAL");
Misha Brukmanf976c852005-04-21 22:55:34 +0000344
Chris Lattner6c38a792002-10-01 19:36:54 +0000345 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
346 Total.sum(TimersToPrint[i]);
Misha Brukmanf976c852005-04-21 22:55:34 +0000347
Chris Lattner6c38a792002-10-01 19:36:54 +0000348 // Print out timing header...
Chris Lattnerf205fec2003-05-09 20:05:44 +0000349 *OutStream << "===" << std::string(73, '-') << "===\n"
350 << std::string(Padding, ' ') << Name << "\n"
351 << "===" << std::string(73, '-')
Chris Lattner3ac96052005-02-09 18:41:32 +0000352 << "===\n";
Chris Lattner8166b7c2003-02-13 16:25:28 +0000353
Chris Lattner3ac96052005-02-09 18:41:32 +0000354 // If this is not an collection of ungrouped times, print the total time.
355 // Ungrouped timers don't really make sense to add up. We still print the
356 // TOTAL line to make the percentages make sense.
Owen Andersonaf2e2b52009-06-22 23:37:06 +0000357 if (this != &*DefaultTimerGroup) {
Chris Lattner3ac96052005-02-09 18:41:32 +0000358 *OutStream << " Total Execution Time: ";
359
360 printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
361 *OutStream << " seconds (";
362 printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
363 *OutStream << " wall clock)\n";
364 }
365 *OutStream << "\n";
Chris Lattner6c38a792002-10-01 19:36:54 +0000366
367 if (Total.UserTime)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000368 *OutStream << " ---User Time---";
Chris Lattner6c38a792002-10-01 19:36:54 +0000369 if (Total.SystemTime)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000370 *OutStream << " --System Time--";
Chris Lattner6c38a792002-10-01 19:36:54 +0000371 if (Total.getProcessTime())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000372 *OutStream << " --User+System--";
373 *OutStream << " ---Wall Time---";
Chris Lattner18eba912002-11-04 19:19:36 +0000374 if (Total.getMemUsed())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000375 *OutStream << " ---Mem---";
Chris Lattner8f0d8242002-11-18 21:47:09 +0000376 if (Total.getPeakMem())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000377 *OutStream << " -PeakMem-";
378 *OutStream << " --- Name ---\n";
Misha Brukmanf976c852005-04-21 22:55:34 +0000379
Chris Lattner6c38a792002-10-01 19:36:54 +0000380 // Loop through all of the timing data, printing it out...
381 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000382 TimersToPrint[i].print(Total, *OutStream);
Misha Brukmanf976c852005-04-21 22:55:34 +0000383
Chris Lattnerf205fec2003-05-09 20:05:44 +0000384 Total.print(Total, *OutStream);
385 *OutStream << std::endl; // Flush output
Chris Lattner6c38a792002-10-01 19:36:54 +0000386 }
387 --NumTimers;
388
389 TimersToPrint.clear();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000390
Bill Wendlingbcd24982006-12-07 20:28:15 +0000391 if (OutStream != cerr.stream() && OutStream != cout.stream())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000392 delete OutStream; // Close the file...
Chris Lattner6c38a792002-10-01 19:36:54 +0000393 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000394}
Brian Gaeked0fde302003-11-11 22:41:34 +0000395