From dcd68b7a658dc95d3e14104ae16c2b36424b78b6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 30 Mar 2010 04:58:26 +0000 Subject: if a timergroup is destroyed before its timers, print times. llvm-svn: 99873 --- llvm/lib/Support/Statistic.cpp | 2 +- llvm/lib/Support/Timer.cpp | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Support') diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp index e7876704599..f88094af74b 100644 --- a/llvm/lib/Support/Statistic.cpp +++ b/llvm/lib/Support/Statistic.cpp @@ -128,6 +128,6 @@ StatisticInfo::~StatisticInfo() { OutStream << '\n'; // Flush the output stream... OutStream.flush(); - if (&OutStream != &outs() && &OutStream != &errs() && &OutStream != &dbgs()) + if (&OutStream != &outs() && &OutStream != &errs()) delete &OutStream; // Close the file. } diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index cc903805e8f..daafd63dd2d 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -237,14 +237,22 @@ NamedRegionTimer::NamedRegionTimer(const std::string &Name, // TimerGroup Implementation //===----------------------------------------------------------------------===// +TimerGroup::~TimerGroup() { + // If the timer group is destroyed before the timers it owns, accumulate and + // print the timing data. + while (FirstTimer != 0) + removeTimer(*FirstTimer); +} + + void TimerGroup::removeTimer(Timer &T) { sys::SmartScopedLock L(*TimerLock); // If the timer was started, move its data to TimersToPrint. - if (T.Started) { - T.Started = false; + if (T.Started) TimersToPrint.push_back(std::make_pair(T.Time, T.Name)); - } + + T.TG = 0; // Unlink the timer from our list. *T.Prev = T.Next; @@ -257,9 +265,9 @@ void TimerGroup::removeTimer(Timer &T) { return; raw_ostream *OutStream = GetLibSupportInfoOutputFile(); - + PrintQueuedTimers(*OutStream); - + if (OutStream != &errs() && OutStream != &outs()) delete OutStream; // Close the file. } -- cgit v1.2.3