if a timergroup is destroyed before its timers, print times.
authorChris Lattner <sabre@nondot.org>
Tue, 30 Mar 2010 04:58:26 +0000 (04:58 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 30 Mar 2010 04:58:26 +0000 (04:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99873 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Timer.h
lib/Support/Statistic.cpp
lib/Support/Timer.cpp

index aba31506fcf9e6c486a19f09c37874259c1649d6..2997a8744cc05945abe162eb9bd3b28a02140c36 100644 (file)
@@ -171,6 +171,7 @@ public:
   explicit TimerGroup(const TimerGroup &TG) : FirstTimer(0) {
     operator=(TG);
   }
+  ~TimerGroup();
 
   void operator=(const TimerGroup &TG) {
     assert(TG.FirstTimer == 0 && FirstTimer == 0 &&
@@ -181,11 +182,6 @@ public:
   
   void setName(const std::string &name) { Name = name; }
   
-  ~TimerGroup() {
-    assert(FirstTimer == 0 &&
-           "TimerGroup destroyed before all contained timers!");
-  }
-
   void PrintQueuedTimers(raw_ostream &OS);
   
 private:
index e7876704599821bce5cf08088022c6b96b9368cf..f88094af74b685549bc3864a8050bc23f8eff8ed 100644 (file)
@@ -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.
 }
index cc903805e8fa9f4a0ac63d978b646d7d57732a8a..daafd63dd2dca69ecace70a7f092bc860b795346 100644 (file)
@@ -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<true> 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.
 }