HP aCC chokes on this, but it's not required anyway: according to
[oota-llvm.git] / lib / Support / Timer.cpp
index 4b273b02ff9184f3333840ff697189dc3783961f..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.
@@ -19,7 +19,6 @@
 #include <functional>
 #include <iostream>
 #include <map>
-
 using namespace llvm;
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on.
@@ -93,7 +92,7 @@ Timer::~Timer() {
   }
 }
 
-static inline long getMemUsage() {
+static inline size_t getMemUsage() {
   if (TrackSpace)
     return sys::Process::GetMallocUsage();
   return 0;
@@ -101,7 +100,7 @@ static inline long getMemUsage() {
 
 struct TimeRecord {
   double Elapsed, UserTime, SystemTime;
-  long MemUsed;
+  ssize_t MemUsed;
 };
 
 static TimeRecord getTimeRecord(bool Start) {
@@ -111,13 +110,13 @@ static TimeRecord getTimeRecord(bool Start) {
   sys::TimeValue user(0,0);
   sys::TimeValue sys(0,0);
 
-  long MemUsed = 0;
+  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;
@@ -171,7 +170,7 @@ void Timer::sum(const Timer &T) {
 /// currently active timers, which will be printed when the timer group prints
 ///
 void Timer::addPeakMemoryMeasurement() {
-  long MemUsed = getMemUsage();
+  size_t MemUsed = getMemUsage();
 
   for (std::vector<Timer*>::iterator I = ActiveTimers.begin(),
          E = ActiveTimers.end(); I != E; ++I)
@@ -239,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) {
@@ -295,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---";
@@ -322,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
     }