blob: bcb27a4ab4f37bf0e3159a24bfd5a4681f77a157 [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 Anderson6f2c64d2009-06-23 20:17:22 +0000115 double Elapsed, UserTime, SystemTime;
116 ssize_t MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000117};
118
Chris Lattner8f0d8242002-11-18 21:47:09 +0000119static TimeRecord getTimeRecord(bool Start) {
Chris Lattnerb4db5f32004-06-07 19:34:51 +0000120 TimeRecord Result;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000121
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000122 sys::TimeValue now(0,0);
123 sys::TimeValue user(0,0);
124 sys::TimeValue sys(0,0);
Chris Lattner6c38a792002-10-01 19:36:54 +0000125
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000126 ssize_t MemUsed = 0;
Reid Spencer7d055632004-12-20 21:44:27 +0000127 if (Start) {
Reid Spenceraeb47b82004-12-27 08:03:04 +0000128 MemUsed = getMemUsage();
Chris Lattnerfed1b272005-03-22 03:20:38 +0000129 sys::Process::GetTimeUsage(now,user,sys);
Reid Spencer7d055632004-12-20 21:44:27 +0000130 } else {
Reid Spencer7d055632004-12-20 21:44:27 +0000131 sys::Process::GetTimeUsage(now,user,sys);
Chris Lattnerfed1b272005-03-22 03:20:38 +0000132 MemUsed = getMemUsage();
Reid Spencer7d055632004-12-20 21:44:27 +0000133 }
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000134
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000135 Result.Elapsed = now.seconds() + now.microseconds() / 1000000.0;
136 Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
137 Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
Reid Spencer7d055632004-12-20 21:44:27 +0000138 Result.MemUsed = MemUsed;
Reid Spencerdf52c9a2004-12-20 00:59:04 +0000139
Chris Lattner6c38a792002-10-01 19:36:54 +0000140 return Result;
141}
142
Chris Lattner90aa8392006-10-04 21:52:35 +0000143static ManagedStatic<std::vector<Timer*> > ActiveTimers;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000144
Chris Lattner6c38a792002-10-01 19:36:54 +0000145void Timer::startTimer() {
146 Started = true;
Dan Gohman153d28a2008-06-24 22:07:07 +0000147 ActiveTimers->push_back(this);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000148 TimeRecord TR = getTimeRecord(true);
Chris Lattner6c38a792002-10-01 19:36:54 +0000149 Elapsed -= TR.Elapsed;
150 UserTime -= TR.UserTime;
151 SystemTime -= TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000152 MemUsed -= TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000153 PeakMemBase = TR.MemUsed;
Chris Lattner6c38a792002-10-01 19:36:54 +0000154}
155
156void Timer::stopTimer() {
Chris Lattner8f0d8242002-11-18 21:47:09 +0000157 TimeRecord TR = getTimeRecord(false);
Chris Lattner6c38a792002-10-01 19:36:54 +0000158 Elapsed += TR.Elapsed;
159 UserTime += TR.UserTime;
160 SystemTime += TR.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000161 MemUsed += TR.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000162
Chris Lattner90aa8392006-10-04 21:52:35 +0000163 if (ActiveTimers->back() == this) {
164 ActiveTimers->pop_back();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000165 } else {
166 std::vector<Timer*>::iterator I =
Chris Lattner90aa8392006-10-04 21:52:35 +0000167 std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
168 assert(I != ActiveTimers->end() && "stop but no startTimer?");
169 ActiveTimers->erase(I);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000170 }
Chris Lattner6c38a792002-10-01 19:36:54 +0000171}
172
173void Timer::sum(const Timer &T) {
174 Elapsed += T.Elapsed;
175 UserTime += T.UserTime;
176 SystemTime += T.SystemTime;
Chris Lattner18eba912002-11-04 19:19:36 +0000177 MemUsed += T.MemUsed;
Chris Lattner8f0d8242002-11-18 21:47:09 +0000178 PeakMem += T.PeakMem;
Chris Lattner6c38a792002-10-01 19:36:54 +0000179}
180
Chris Lattner8f0d8242002-11-18 21:47:09 +0000181/// addPeakMemoryMeasurement - This method should be called whenever memory
182/// usage needs to be checked. It adds a peak memory measurement to the
183/// currently active timers, which will be printed when the timer group prints
184///
185void Timer::addPeakMemoryMeasurement() {
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000186 size_t MemUsed = getMemUsage();
Chris Lattner8f0d8242002-11-18 21:47:09 +0000187
Chris Lattner90aa8392006-10-04 21:52:35 +0000188 for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
189 E = ActiveTimers->end(); I != E; ++I)
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000190 (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
Chris Lattner8f0d8242002-11-18 21:47:09 +0000191}
192
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000193//===----------------------------------------------------------------------===//
194// NamedRegionTimer Implementation
195//===----------------------------------------------------------------------===//
196
Dan Gohman5e843682008-07-14 18:19:29 +0000197namespace {
198
199typedef std::map<std::string, Timer> Name2Timer;
200typedef std::map<std::string, std::pair<TimerGroup, Name2Timer> > Name2Pair;
201
202}
203
204static ManagedStatic<Name2Timer> NamedTimers;
205
206static ManagedStatic<Name2Pair> NamedGroupedTimers;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000207
Chris Lattner90aa8392006-10-04 21:52:35 +0000208static Timer &getNamedRegionTimer(const std::string &Name) {
Dan Gohman5e843682008-07-14 18:19:29 +0000209 Name2Timer::iterator I = NamedTimers->find(Name);
Dan Gohmanc418bf32008-07-11 20:58:19 +0000210 if (I != NamedTimers->end())
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000211 return I->second;
212
Chris Lattner90aa8392006-10-04 21:52:35 +0000213 return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000214}
215
Dan Gohman5e843682008-07-14 18:19:29 +0000216static Timer &getNamedRegionTimer(const std::string &Name,
217 const std::string &GroupName) {
218
219 Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
220 if (I == NamedGroupedTimers->end()) {
221 TimerGroup TG(GroupName);
222 std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
223 I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
224 }
225
226 Name2Timer::iterator J = I->second.second.find(Name);
227 if (J == I->second.second.end())
228 J = I->second.second.insert(J,
229 std::make_pair(Name,
230 Timer(Name,
231 I->second.first)));
232
233 return J->second;
234}
235
Chris Lattnerd5a310e2003-10-06 15:02:31 +0000236NamedRegionTimer::NamedRegionTimer(const std::string &Name)
237 : TimeRegion(getNamedRegionTimer(Name)) {}
238
Dan Gohman5e843682008-07-14 18:19:29 +0000239NamedRegionTimer::NamedRegionTimer(const std::string &Name,
240 const std::string &GroupName)
241 : TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
Chris Lattner8f0d8242002-11-18 21:47:09 +0000242
Chris Lattner6c38a792002-10-01 19:36:54 +0000243//===----------------------------------------------------------------------===//
244// TimerGroup Implementation
245//===----------------------------------------------------------------------===//
246
Chris Lattnerf205fec2003-05-09 20:05:44 +0000247// printAlignedFP - Simulate the printf "%A.Bf" format, where A is the
248// TotalWidth size, and B is the AfterDec size.
249//
250static void printAlignedFP(double Val, unsigned AfterDec, unsigned TotalWidth,
251 std::ostream &OS) {
252 assert(TotalWidth >= AfterDec+1 && "Bad FP Format!");
253 OS.width(TotalWidth-AfterDec-1);
254 char OldFill = OS.fill();
255 OS.fill(' ');
256 OS << (int)Val; // Integer part;
257 OS << ".";
258 OS.width(AfterDec);
259 OS.fill('0');
260 unsigned ResultFieldSize = 1;
261 while (AfterDec--) ResultFieldSize *= 10;
262 OS << (int)(Val*ResultFieldSize) % ResultFieldSize;
263 OS.fill(OldFill);
Chris Lattner6c38a792002-10-01 19:36:54 +0000264}
265
Chris Lattnerf205fec2003-05-09 20:05:44 +0000266static void printVal(double Val, double Total, std::ostream &OS) {
267 if (Total < 1e-7) // Avoid dividing by zero...
268 OS << " ----- ";
269 else {
270 OS << " ";
271 printAlignedFP(Val, 4, 7, OS);
272 OS << " (";
273 printAlignedFP(Val*100/Total, 1, 5, OS);
274 OS << "%)";
Chris Lattner8f0d8242002-11-18 21:47:09 +0000275 }
Chris Lattnerf205fec2003-05-09 20:05:44 +0000276}
277
278void Timer::print(const Timer &Total, std::ostream &OS) {
279 if (Total.UserTime)
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000280 printVal(UserTime, Total.UserTime, OS);
Chris Lattnerf205fec2003-05-09 20:05:44 +0000281 if (Total.SystemTime)
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000282 printVal(SystemTime, Total.SystemTime, OS);
Chris Lattnerf205fec2003-05-09 20:05:44 +0000283 if (Total.getProcessTime())
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000284 printVal(getProcessTime(), Total.getProcessTime(), OS);
285 printVal(Elapsed, Total.Elapsed, 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 Anderson6f2c64d2009-06-23 20:17:22 +0000358 printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
Chris Lattner3ac96052005-02-09 18:41:32 +0000359 *OutStream << " seconds (";
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000360 printAlignedFP(Total.getWallTime(), 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 Anderson6f2c64d2009-06-23 20:17:22 +0000365 if (Total.UserTime)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000366 *OutStream << " ---User Time---";
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000367 if (Total.SystemTime)
Chris Lattnerf205fec2003-05-09 20:05:44 +0000368 *OutStream << " --System Time--";
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000369 if (Total.getProcessTime())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000370 *OutStream << " --User+System--";
371 *OutStream << " ---Wall Time---";
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000372 if (Total.getMemUsed())
Chris Lattnerf205fec2003-05-09 20:05:44 +0000373 *OutStream << " ---Mem---";
Owen Anderson6f2c64d2009-06-23 20:17:22 +0000374 if (Total.getPeakMem())
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