[llvm-commits] [llvm] r73974 - in /llvm/trunk: include/llvm/Support/Timer.h lib/Support/Timer.cpp

Owen Anderson resistor at mac.com
Tue Jun 23 11:12:42 PDT 2009


Author: resistor
Date: Tue Jun 23 13:12:30 2009
New Revision: 73974

URL: http://llvm.org/viewvc/llvm-project?rev=73974&view=rev
Log:
Use 64-bit integer counters for tracking time, rather than doubles.  This will be more atomic op friendly.

Modified:
    llvm/trunk/include/llvm/Support/Timer.h
    llvm/trunk/lib/Support/Timer.cpp

Modified: llvm/trunk/include/llvm/Support/Timer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Timer.h?rev=73974&r1=73973&r2=73974&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/Timer.h (original)
+++ llvm/trunk/include/llvm/Support/Timer.h Tue Jun 23 13:12:30 2009
@@ -34,12 +34,12 @@
 /// if they are never started.
 ///
 class Timer {
-  double Elapsed;        // Wall clock time elapsed in seconds
-  double UserTime;       // User time elapsed
-  double SystemTime;     // System time elapsed
-  ssize_t MemUsed;       // Memory allocated (in bytes)
-  size_t PeakMem;        // Peak memory used
-  size_t PeakMemBase;    // Temporary for peak calculation...
+  uint64_t Elapsed;        // Wall clock time elapsed in seconds
+  uint64_t UserTime;       // User time elapsed
+  uint64_t SystemTime;     // System time elapsed
+  uint64_t MemUsed;       // Memory allocated (in bytes)
+  uint64_t PeakMem;        // Peak memory used
+  uint64_t PeakMemBase;    // Temporary for peak calculation...
   std::string Name;      // The name of this time variable
   bool Started;          // Has this time variable ever been started?
   TimerGroup *TG;        // The TimerGroup this Timer is in.
@@ -49,10 +49,10 @@
   Timer(const Timer &T);
   ~Timer();
 
-  double getProcessTime() const { return UserTime+SystemTime; }
-  double getWallTime() const { return Elapsed; }
-  ssize_t getMemUsed() const { return MemUsed; }
-  size_t getPeakMem() const { return PeakMem; }
+  uint64_t getProcessTime() const { return UserTime+SystemTime; }
+  uint64_t getWallTime() const { return Elapsed; }
+  uint64_t getMemUsed() const { return MemUsed; }
+  uint64_t getPeakMem() const { return PeakMem; }
   std::string getName() const { return Name; }
 
   const Timer &operator=(const Timer &T) {

Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=73974&r1=73973&r2=73974&view=diff

==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Tue Jun 23 13:12:30 2009
@@ -112,8 +112,7 @@
 }
 
 struct TimeRecord {
-  double Elapsed, UserTime, SystemTime;
-  ssize_t MemUsed;
+  uint64_t Elapsed, UserTime, SystemTime, MemUsed;
 };
 
 static TimeRecord getTimeRecord(bool Start) {
@@ -123,7 +122,7 @@
   sys::TimeValue user(0,0);
   sys::TimeValue sys(0,0);
 
-  ssize_t MemUsed = 0;
+  uint64_t MemUsed = 0;
   if (Start) {
     MemUsed = getMemUsage();
     sys::Process::GetTimeUsage(now,user,sys);
@@ -132,9 +131,9 @@
     MemUsed = getMemUsage();
   }
 
-  Result.Elapsed  = now.seconds()  + now.microseconds()  / 1000000.0;
-  Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
-  Result.SystemTime  = sys.seconds()  + sys.microseconds()  / 1000000.0;
+  Result.Elapsed  = now.seconds() * 1000000 + now.microseconds();
+  Result.UserTime = user.seconds() * 1000000 + user.microseconds();
+  Result.SystemTime  = sys.seconds() * 1000000 + sys.microseconds();
   Result.MemUsed  = MemUsed;
 
   return Result;
@@ -277,12 +276,13 @@
 
 void Timer::print(const Timer &Total, std::ostream &OS) {
   if (Total.UserTime)
-    printVal(UserTime, Total.UserTime, OS);
+    printVal(UserTime / 1000000.0, Total.UserTime / 1000000.0, OS);
   if (Total.SystemTime)
-    printVal(SystemTime, Total.SystemTime, OS);
+    printVal(SystemTime / 1000000.0, Total.SystemTime / 1000000.0, OS);
   if (Total.getProcessTime())
-    printVal(getProcessTime(), Total.getProcessTime(), OS);
-  printVal(Elapsed, Total.Elapsed, OS);
+    printVal(getProcessTime() / 1000000.0,
+             Total.getProcessTime() / 1000000.0, OS);
+  printVal(Elapsed / 1000000.0, Total.Elapsed / 1000000.0, OS);
 
   OS << "  ";
 
@@ -355,23 +355,23 @@
       if (this != DefaultTimerGroup) {
         *OutStream << "  Total Execution Time: ";
 
-        printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
+        printAlignedFP(Total.getProcessTime() / 1000000.0, 4, 5, *OutStream);
         *OutStream << " seconds (";
-        printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
+        printAlignedFP(Total.getWallTime() / 1000000.0, 4, 5, *OutStream);
         *OutStream << " wall clock)\n";
       }
       *OutStream << "\n";
 
-      if (Total.UserTime)
+      if (Total.UserTime / 1000000.0)
         *OutStream << "   ---User Time---";
-      if (Total.SystemTime)
+      if (Total.SystemTime / 1000000.0)
         *OutStream << "   --System Time--";
-      if (Total.getProcessTime())
+      if (Total.getProcessTime() / 1000000.0)
         *OutStream << "   --User+System--";
       *OutStream << "   ---Wall Time---";
-      if (Total.getMemUsed())
+      if (Total.getMemUsed() / 1000000.0)
         *OutStream << "  ---Mem---";
-      if (Total.getPeakMem())
+      if (Total.getPeakMem() / 1000000.0)
         *OutStream << "  -PeakMem-";
       *OutStream << "  --- Name ---\n";
 





More information about the llvm-commits mailing list