blob: 69f967c738978f139c058618517903e505efa4b4 [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"
Reid Spencerdf52c9a2004-12-20 00:59:04 +000018#include "llvm/System/Process.h"
Reid Spencer0255abb2004-12-20 03:59:23 +000019#include <algorithm>
Chris Lattnerb4db5f32004-06-07 19:34:51 +000020#include <fstream>
Reid Spencer0255abb2004-12-20 03:59:23 +000021#include <functional>
Chris Lattnerb4db5f32004-06-07 19:34:51 +000022#include <map>
Chris Lattnerb6d465f2003-12-14 21:27:33 +000023using namespace llvm;
Chris Lattnerf205fec2003-05-09 20:05:44 +000024
Chris Lattnerb4db5f32004-06-07 19:34:51 +000025// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
Chris Lattnerb6d465f2003-12-14 21:27:33 +000026namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
Brian Gaeked0fde302003-11-11 22:41:34 +000027
Chris Lattner71336a92003-07-31 19:38:34 +000028// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
29// of constructor/destructor ordering being unspecified by C++. Basically the
Chris Lattnerac0b6ae2006-12-06 17:46:33 +000030// problem is that a Statistic object gets destroyed, which ends up calling
Chris Lattner71336a92003-07-31 19:38:34 +000031// 'GetLibSupportInfoOutputFile()' (below), which calls this function.
32// LibSupportInfoOutputFilename used to be a global variable, but sometimes it
Reid Spencerf6e5a252004-12-14 03:55:21 +000033// would get destroyed before the Statistic, causing havoc to ensue. We "fix"
34// this by creating the string the first time it is needed and never destroying
35// it.
Chris Lattner90aa8392006-10-04 21:52:35 +000036static ManagedStatic<std::string> LibSupportInfoOutputFilename;
Chris Lattner71336a92003-07-31 19:38:34 +000037static std::string &getLibSupportInfoOutputFilename() {
Reid Spencerf6e5a252004-12-14 03:55:21 +000038 return *LibSupportInfoOutputFilename;
Chris Lattner71336a92003-07-31 19:38:34 +000039}
Chris Lattner6c38a792002-10-01 19:36:54 +000040
Chris Lattner3f398492003-01-30 23:08:50 +000041namespace {
Dan Gohman3c02aca2008-04-23 23:15:23 +000042 static cl::opt<bool>
Chris Lattner3f398492003-01-30 23:08:50 +000043 TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
44 "tracking (this may be slow)"),
45 cl::Hidden);
Chris Lattnerf205fec2003-05-09 20:05:44 +000046
Dan Gohman3c02aca2008-04-23 23:15:23 +000047 static cl::opt<std::string, true>
Chris Lattner96a54db2003-08-01 22:15:15 +000048 InfoOutputFilename("info-output-file", cl::value_desc("filename"),
Chris Lattnerf205fec2003-05-09 20:05:44 +000049 cl::desc("File to append -stats and -timer output to"),
Chris Lattner71336a92003-07-31 19:38:34 +000050 cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
Chris Lattner3f398492003-01-30 23:08:50 +000051}
52
Owen Anderson200aa6d2009-06-23 16:36:10 +000053static TimerGroup *DefaultTimerGroup = 0;
Chris Lattner6c38a792002-10-01 19:36:54 +000054static TimerGroup *getDefaultTimerGroup() {
Owen Anderson3b8d1352009-06-23 17:33:37 +000055 TimerGroup* tmp = DefaultTimerGroup;
56 sys::MemoryFence();
57 if (!tmp) {
58 llvm_acquire_global_lock();
59 tmp = DefaultTimerGroup;
60 if (!tmp) {
61 tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
62 sys::MemoryFence();
63 DefaultTimerGroup = tmp;
64 }
65 llvm_release_global_lock();
66 }
67
68 return tmp;
Chris Lattner6c38a792002-10-01 19:36:54 +000069}
70
71Timer::Timer(const std::string &N)
Chris Lattner8f0d8242002-11-18 21:47:09 +000072 : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
Chris Lattner6c38a792002-10-01 19:36:54 +000073 Started(false), TG(getDefaultTimerGroup()) {
74 TG->addTimer();
75}
76
77Timer::Timer(const std::string &N, TimerGroup &tg)
Chris Lattner8f0d8242002-11-18 21:47:09 +000078 : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
Chris Lattner6c38a792002-10-01 19:36:54 +000079 Started(false), TG(&tg) {
80 TG->addTimer();
81}
82
83Timer::Timer(const Timer &T) {
84 TG = T.TG;
85 if (TG) TG->addTimer();
86 operator=(T);
87}
88
89
90// Copy ctor, initialize with no TG member.
91Timer::Timer(bool, const Timer &T) {
92 TG = T.TG; // Avoid assertion in operator=
93 operator=(T); // Copy contents
94 TG = 0;
95}
96
97
98Timer::~Timer() {
99 if (TG) {
100 if (Started) {
101 Started = false;
102 TG->addTimerToPrint(*this);
103 }
104 TG->removeTimer();
105 }
106}
107
Jeff Cohene269a1a2005-01-08 20:15:57 +0000108static inline size_t getMemUsage() {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000109 if (TrackSpace)
Jeff Cohene269a1a2005-01-08 20:15:57 +0000110 return sys::Process::GetMallocUsage();
Reid Spenceraeb47b82004-12-27 08:03:04 +0000111 return 0;
112}
113
Chris Lattner6c38a792002-10-01 19:36:54 +0000114struct TimeRecord {
Owen Anderson14112e52009-06-23 18:21:13 +0000115 int64_t Elapsed, UserTime, SystemTime, MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000116};
117
Chris Lattner8f0d8242002-11-18 21:47:09 +0000118static TimeRecord getTimeRecord(bool Start) {
Chris Lattnerb4db5f32004-06-07 19:34:51 +0000119 TimeRecord Result;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000120
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000121 sys::TimeValue now(0,0);
122 sys::TimeValue user(0,0);
123 sys::TimeValue sys(0,0);
Chris Lattner6c38a792002-10-01 19:36:54 +0000124
Owen Anderson14112e52009-06-23 18:21:13 +0000125 int64_t MemUsed = 0;
Reid Spencer7d055632004-12-20 21:44:27 +0000126 if (Start) {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000127 MemUsed = getMemUsage();
Chris Lattnerfed1b272005-03-22 03:20:38 +0000128 sys::Process::GetTimeUsage(now,user,sys);
Reid Spencer7d055632004-12-20 21:44:27 +0000129 } else {
Reid Spencer7d055632004-12-20 21:44:27 +0000130 sys::Process::GetTimeUsage(now,user,sys);
Chris Lattnerfed1b272005-03-22 03:20:38 +0000131 MemUsed = getMemUsage();
Reid Spencer7d055632004-12-20 21:44:27 +0000132 }
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000133
Owen Andersoncd92c102009-06-23 18:12:30 +0000134 Result.Elapsed = now.seconds() * 1000000 + now.microseconds();
135 Result.UserTime = user.seconds() * 1000000 + user.microseconds();
136 Result.SystemTime = sys.seconds() * 1000000 + sys.microseconds();
Reid Spencer7d055632004-12-20 21:44:27 +0000137 Result.MemUsed = MemUsed;
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000138
Chris Lattner6c38a792002-10-01 19:36:54 +0000139 return Result;
140}
141
Chris Lattner90aa8392006-10-04 21:52:35 +0000142static ManagedStatic<std::vector<Timer*> > ActiveTimers;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000143
Chris Lattner6c38a792002-10-01 19:36:54 +0000144void Timer::startTimer() {
145 Started = true;
Dan Gohman153d28a2008-06-24 22:07:07 +0000146 ActiveTimers->push_back(this);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000147 TimeRecord TR = getTimeRecord(true);
Chris Lattner6c38a792002-10-01 19:36:54 +0000148 Elapsed -= TR.Elapsed;
149 UserTime -= TR.UserTime;
150 SystemTime -= TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000151 MemUsed -= TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000152 PeakMemBase = TR.MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000153}
154
155void Timer::stopTimer() {
Chris Lattner8f0d8242002-11-18 21:47:09 +0000156 TimeRecord TR = getTimeRecord(false);
Chris Lattner6c38a792002-10-01 19:36:54 +0000157 Elapsed += TR.Elapsed;
158 UserTime += TR.UserTime;
159 SystemTime += TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000160 MemUsed += TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000161
Chris Lattner90aa8392006-10-04 21:52:35 +0000162 if (ActiveTimers->back() == this) {
163 ActiveTimers->pop_back();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000164 } else {
165 std::vector<Timer*>::iterator I =
Chris Lattner90aa8392006-10-04 21:52:35 +0000166 std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
167 assert(I != ActiveTimers->end() && "stop but no startTimer?");
168 ActiveTimers->erase(I);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000169 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000170}
171
172void Timer::sum(const Timer &T) {
173 Elapsed += T.Elapsed;
174 UserTime += T.UserTime;
175 SystemTime += T.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000176 MemUsed += T.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000177 PeakMem += T.PeakMem;
Chris Lattner6c38a792002-10-01 19:36:54 +0000178}
179
Chris Lattner8f0d8242002-11-18 21:47:09 +0000180/// addPeakMemoryMeasurement - This method should be called whenever memory
181/// usage needs to be checked. It adds a peak memory measurement to the
182/// currently active timers, which will be printed when the timer group prints
183///
184void Timer::addPeakMemoryMeasurement() {
Jeff Cohene269a1a2005-01-08 20:15:57 +0000185 size_t MemUsed = getMemUsage();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000186
Chris Lattner90aa8392006-10-04 21:52:35 +0000187 for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
188 E = ActiveTimers->end(); I != E; ++I)
Chris Lattner8f0d8242002-11-18 21:47:09 +0000189 (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
190}
191
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000192//===----------------------------------------------------------------------===//
193// NamedRegionTimer Implementation
194//===----------------------------------------------------------------------===//
195
Dan Gohman5e843682008-07-14 18:19:29 +0000196namespace {
197
198typedef std::map<std::string, Timer> Name2Timer;
199typedef std::map<std::string, std::pair<TimerGroup, Name2Timer> > Name2Pair;
200
201}
202
203static ManagedStatic<Name2Timer> NamedTimers;
204
205static ManagedStatic<Name2Pair> NamedGroupedTimers;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000206
Chris Lattner90aa8392006-10-04 21:52:35 +0000207static Timer &getNamedRegionTimer(const std::string &Name) {
Dan Gohman5e843682008-07-14 18:19:29 +0000208 Name2Timer::iterator I = NamedTimers->find(Name);
Dan Gohmanc418bf32008-07-11 20:58:19 +0000209 if (I != NamedTimers->end())
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000210 return I->second;
211
Chris Lattner90aa8392006-10-04 21:52:35 +0000212 return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000213}
214
Dan Gohman5e843682008-07-14 18:19:29 +0000215static Timer &getNamedRegionTimer(const std::string &Name,
216 const std::string &GroupName) {
217
218 Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
219 if (I == NamedGroupedTimers->end()) {
220 TimerGroup TG(GroupName);
221 std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
222 I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
223 }
224
225 Name2Timer::iterator J = I->second.second.find(Name);
226 if (J == I->second.second.end())
227 J = I->second.second.insert(J,
228 std::make_pair(Name,
229 Timer(Name,
230 I->second.first)));
231
232 return J->second;
233}
234
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000235NamedRegionTimer::NamedRegionTimer(const std::string &Name)
236 : TimeRegion(getNamedRegionTimer(Name)) {}
237
Dan Gohman5e843682008-07-14 18:19:29 +0000238NamedRegionTimer::NamedRegionTimer(const std::string &Name,
239 const std::string &GroupName)
240 : TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
Chris Lattner8f0d8242002-11-18 21:47:09 +0000241
Chris Lattner6c38a792002-10-01 19:36:54 +0000242//===----------------------------------------------------------------------===//
243// TimerGroup Implementation
244//===----------------------------------------------------------------------===//
245
Chris Lattnerf205fec2003-05-09 20:05:44 +0000246// printAlignedFP - Simulate the printf "%A.Bf" format, where A is the
247// TotalWidth size, and B is the AfterDec size.
248//
249static void printAlignedFP(double Val, unsigned AfterDec, unsigned TotalWidth,
250 std::ostream &OS) {
251 assert(TotalWidth >= AfterDec+1 && "Bad FP Format!");
252 OS.width(TotalWidth-AfterDec-1);
253 char OldFill = OS.fill();
254 OS.fill(' ');
255 OS << (int)Val; // Integer part;
256 OS << ".";
257 OS.width(AfterDec);
258 OS.fill('0');
259 unsigned ResultFieldSize = 1;
260 while (AfterDec--) ResultFieldSize *= 10;
261 OS << (int)(Val*ResultFieldSize) % ResultFieldSize;
262 OS.fill(OldFill);
Chris Lattner6c38a792002-10-01 19:36:54 +0000263}
264
Chris Lattnerf205fec2003-05-09 20:05:44 +0000265static void printVal(double Val, double Total, std::ostream &OS) {
266 if (Total < 1e-7) // Avoid dividing by zero...
267 OS << " ----- ";
268 else {
269 OS << " ";
270 printAlignedFP(Val, 4, 7, OS);
271 OS << " (";
272 printAlignedFP(Val*100/Total, 1, 5, OS);
273 OS << "%)";
Chris Lattner8f0d8242002-11-18 21:47:09 +0000274 }
Chris Lattnerf205fec2003-05-09 20:05:44 +0000275}
276
277void Timer::print(const Timer &Total, std::ostream &OS) {
278 if (Total.UserTime)
Owen Andersoncd92c102009-06-23 18:12:30 +0000279 printVal(UserTime / 1000000.0, Total.UserTime / 1000000.0, OS);
Chris Lattnerf205fec2003-05-09 20:05:44 +0000280 if (Total.SystemTime)
Owen Andersoncd92c102009-06-23 18:12:30 +0000281 printVal(SystemTime / 1000000.0, Total.SystemTime / 1000000.0, OS);
Chris Lattnerf205fec2003-05-09 20:05:44 +0000282 if (Total.getProcessTime())
Owen Andersoncd92c102009-06-23 18:12:30 +0000283 printVal(getProcessTime() / 1000000.0,
284 Total.getProcessTime() / 1000000.0, OS);
285 printVal(Elapsed / 1000000.0, Total.Elapsed / 1000000.0, OS);
Misha Brukmanf976c852005-04-21 22:55:34 +0000286
Chris Lattnerf205fec2003-05-09 20:05:44 +0000287 OS << " ";
288
289 if (Total.MemUsed) {
290 OS.width(9);
291 OS << MemUsed << " ";
292 }
293 if (Total.PeakMem) {
294 if (PeakMem) {
295 OS.width(9);
296 OS << PeakMem << " ";
297 } else
298 OS << " ";
299 }
300 OS << Name << "\n";
Chris Lattner6c38a792002-10-01 19:36:54 +0000301
302 Started = false; // Once printed, don't print again
303}
304
Chris Lattnerf205fec2003-05-09 20:05:44 +0000305// GetLibSupportInfoOutputFile - Return a file stream to print our output on...
Brian Gaeked0fde302003-11-11 22:41:34 +0000306std::ostream *
Chris Lattnerb6d465f2003-12-14 21:27:33 +0000307llvm::GetLibSupportInfoOutputFile() {
Chris Lattner71336a92003-07-31 19:38:34 +0000308 std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000309 if (LibSupportInfoOutputFilename.empty())
Bill Wendlingbcd24982006-12-07 20:28:15 +0000310 return cerr.stream();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000311 if (LibSupportInfoOutputFilename == "-")
Bill Wendlingbcd24982006-12-07 20:28:15 +0000312 return cout.stream();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000313
314 std::ostream *Result = new std::ofstream(LibSupportInfoOutputFilename.c_str(),
Chris Lattner903c2d12003-06-06 22:13:01 +0000315 std::ios::app);
Chris Lattnerf205fec2003-05-09 20:05:44 +0000316 if (!Result->good()) {
Bill Wendlingbcd24982006-12-07 20:28:15 +0000317 cerr << "Error opening info-output-file '"
318 << LibSupportInfoOutputFilename << " for appending!\n";
Chris Lattnerf205fec2003-05-09 20:05:44 +0000319 delete Result;
Bill Wendlingbcd24982006-12-07 20:28:15 +0000320 return cerr.stream();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000321 }
322 return Result;
323}
324
Chris Lattner6c38a792002-10-01 19:36:54 +0000325
326void TimerGroup::removeTimer() {
327 if (--NumTimers == 0 && !TimersToPrint.empty()) { // Print timing report...
328 // Sort the timers in descending order by amount of time taken...
329 std::sort(TimersToPrint.begin(), TimersToPrint.end(),
330 std::greater<Timer>());
331
332 // Figure out how many spaces to indent TimerGroup name...
333 unsigned Padding = (80-Name.length())/2;
334 if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
335
Chris Lattnerf205fec2003-05-09 20:05:44 +0000336 std::ostream *OutStream = GetLibSupportInfoOutputFile();
337
Chris Lattner6c38a792002-10-01 19:36:54 +0000338 ++NumTimers;
339 { // Scope to contain Total timer... don't allow total timer to drop us to
340 // zero timers...
341 Timer Total("TOTAL");
Misha Brukmanf976c852005-04-21 22:55:34 +0000342
Chris Lattner6c38a792002-10-01 19:36:54 +0000343 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
344 Total.sum(TimersToPrint[i]);
Misha Brukmanf976c852005-04-21 22:55:34 +0000345
Chris Lattner6c38a792002-10-01 19:36:54 +0000346 // Print out timing header...
Chris Lattnerf205fec2003-05-09 20:05:44 +0000347 *OutStream << "===" << std::string(73, '-') << "===\n"
348 << std::string(Padding, ' ') << Name << "\n"
349 << "===" << std::string(73, '-')
Chris Lattner3ac96052005-02-09 18:41:32 +0000350 << "===\n";
Chris Lattner8166b7c2003-02-13 16:25:28 +0000351
Chris Lattner3ac96052005-02-09 18:41:32 +0000352 // If this is not an collection of ungrouped times, print the total time.
353 // Ungrouped timers don't really make sense to add up. We still print the
354 // TOTAL line to make the percentages make sense.
Owen Anderson200aa6d2009-06-23 16:36:10 +0000355 if (this != DefaultTimerGroup) {
Chris Lattner3ac96052005-02-09 18:41:32 +0000356 *OutStream << " Total Execution Time: ";
357
Owen Andersoncd92c102009-06-23 18:12:30 +0000358 printAlignedFP(Total.getProcessTime() / 1000000.0, 4, 5, *OutStream);
Chris Lattner3ac96052005-02-09 18:41:32 +0000359 *OutStream << " seconds (";
Owen Andersoncd92c102009-06-23 18:12:30 +0000360 printAlignedFP(Total.getWallTime() / 1000000.0, 4, 5, *OutStream);
Chris Lattner3ac96052005-02-09 18:41:32 +0000361 *OutStream << " wall clock)\n";
362 }
363 *OutStream << "\n";
Chris Lattner6c38a792002-10-01 19:36:54 +0000364
Owen Andersoncd92c102009-06-23 18:12:30 +0000365 if (Total.UserTime / 1000000.0)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000366 *OutStream << " ---User Time---";
Owen Andersoncd92c102009-06-23 18:12:30 +0000367 if (Total.SystemTime / 1000000.0)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000368 *OutStream << " --System Time--";
Owen Andersoncd92c102009-06-23 18:12:30 +0000369 if (Total.getProcessTime() / 1000000.0)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000370 *OutStream << " --User+System--";
371 *OutStream << " ---Wall Time---";
Owen Andersoncd92c102009-06-23 18:12:30 +0000372 if (Total.getMemUsed() / 1000000.0)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000373 *OutStream << " ---Mem---";
Owen Andersoncd92c102009-06-23 18:12:30 +0000374 if (Total.getPeakMem() / 1000000.0)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000375 *OutStream << " -PeakMem-";
376 *OutStream << " --- Name ---\n";
Misha Brukmanf976c852005-04-21 22:55:34 +0000377
Chris Lattner6c38a792002-10-01 19:36:54 +0000378 // Loop through all of the timing data, printing it out...
379 for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000380 TimersToPrint[i].print(Total, *OutStream);
Misha Brukmanf976c852005-04-21 22:55:34 +0000381
Chris Lattnerf205fec2003-05-09 20:05:44 +0000382 Total.print(Total, *OutStream);
383 *OutStream << std::endl; // Flush output
Chris Lattner6c38a792002-10-01 19:36:54 +0000384 }
385 --NumTimers;
386
387 TimersToPrint.clear();
Chris Lattnerf205fec2003-05-09 20:05:44 +0000388
Bill Wendlingbcd24982006-12-07 20:28:15 +0000389 if (OutStream != cerr.stream() && OutStream != cout.stream())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000390 delete OutStream; // Close the file...
Chris Lattner6c38a792002-10-01 19:36:54 +0000391 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000392}
Brian Gaeked0fde302003-11-11 22:41:34 +0000393