Add external definitions for commonly-used template specializations and add
[oota-llvm.git] / lib / Support / Timer.cpp
index 3713f7f69ca57237f0c2dada883a09c97f4644b5..b0012ceb51819a0285aedf02c592864ea729470d 100644 (file)
@@ -1,10 +1,10 @@
 //===-- Timer.cpp - Interval Timing Support -------------------------------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // Interval Timing implementation.
@@ -112,11 +112,11 @@ static TimeRecord getTimeRecord(bool Start) {
 
   ssize_t MemUsed = 0;
   if (Start) {
-    sys::Process::GetTimeUsage(now,user,sys);
     MemUsed = getMemUsage();
+    sys::Process::GetTimeUsage(now,user,sys);
   } else {
-    MemUsed = getMemUsage();
     sys::Process::GetTimeUsage(now,user,sys);
+    MemUsed = getMemUsage();
   }
 
   Result.Elapsed  = now.seconds()  + now.microseconds()  / 1000000.0;
@@ -238,7 +238,7 @@ void Timer::print(const Timer &Total, std::ostream &OS) {
   if (Total.getProcessTime())
     printVal(getProcessTime(), Total.getProcessTime(), OS);
   printVal(Elapsed, Total.Elapsed, OS);
-  
+
   OS << "  ";
 
   if (Total.MemUsed) {
@@ -294,20 +294,28 @@ void TimerGroup::removeTimer() {
     {  // Scope to contain Total timer... don't allow total timer to drop us to
        // zero timers...
       Timer Total("TOTAL");
-  
+
       for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
         Total.sum(TimersToPrint[i]);
-      
+
       // Print out timing header...
       *OutStream << "===" << std::string(73, '-') << "===\n"
                  << std::string(Padding, ' ') << Name << "\n"
                  << "===" << std::string(73, '-')
-                 << "===\n  Total Execution Time: ";
+                 << "===\n";
 
-      printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
-      *OutStream << " seconds (";
-      printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
-      *OutStream << " wall clock)\n\n";
+      // If this is not an collection of ungrouped times, print the total time.
+      // Ungrouped timers don't really make sense to add up.  We still print the
+      // TOTAL line to make the percentages make sense.
+      if (this != DefaultTimerGroup) {
+        *OutStream << "  Total Execution Time: ";
+
+        printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
+        *OutStream << " seconds (";
+        printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
+        *OutStream << " wall clock)\n";
+      }
+      *OutStream << "\n";
 
       if (Total.UserTime)
         *OutStream << "   ---User Time---";
@@ -321,11 +329,11 @@ void TimerGroup::removeTimer() {
       if (Total.getPeakMem())
         *OutStream << "  -PeakMem-";
       *OutStream << "  --- Name ---\n";
-      
+
       // Loop through all of the timing data, printing it out...
       for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
         TimersToPrint[i].print(Total, *OutStream);
-    
+
       Total.print(Total, *OutStream);
       *OutStream << std::endl;  // Flush output
     }