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

Chris Lattner sabre at nondot.org
Mon Mar 29 22:27:59 PDT 2010


Author: lattner
Date: Tue Mar 30 00:27:58 2010
New Revision: 99876

URL: http://llvm.org/viewvc/llvm-project?rev=99876&view=rev
Log:
finally, maintain a global list of timer groups, allowing us to 
implement TimerGroup::printAll, which prints and resets all active
timers.

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=99876&r1=99875&r2=99876&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Timer.h (original)
+++ llvm/trunk/include/llvm/Support/Timer.h Tue Mar 30 00:27:58 2010
@@ -164,12 +164,12 @@
   std::string Name;
   Timer *FirstTimer;   // First timer in the group.
   std::vector<std::pair<TimeRecord, std::string> > TimersToPrint;
+  
+  TimerGroup **Prev, *Next; // Doubly linked list of TimerGroup's.
   TimerGroup(const TimerGroup &TG);      // DO NOT IMPLEMENT
   void operator=(const TimerGroup &TG);  // DO NOT IMPLEMENT
 public:
-  explicit TimerGroup(const std::string &name = "")
-    : Name(name), FirstTimer(0) {}
-
+  explicit TimerGroup(const std::string &name);
   ~TimerGroup();
 
   void setName(const std::string &name) { Name = name; }
@@ -177,6 +177,9 @@
   /// print - Print any started timers in this group and zero them.
   void print(raw_ostream &OS);
   
+  /// printAll - This static method prints all timers and clears them all out.
+  static void printAll(raw_ostream &OS);
+  
 private:
   friend class Timer;
   void addTimer(Timer &T);

Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=99876&r1=99875&r2=99876&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Tue Mar 30 00:27:58 2010
@@ -239,11 +239,33 @@
 //   TimerGroup Implementation
 //===----------------------------------------------------------------------===//
 
+/// TimerGroupList - This is the global list of TimerGroups, maintained by the
+/// TimerGroup ctor/dtor and is protected by the TimerLock lock.
+static TimerGroup *TimerGroupList = 0;
+
+TimerGroup::TimerGroup(const std::string &name)
+  : Name(name), FirstTimer(0) {
+    
+  // Add the group to TimerGroupList.
+  sys::SmartScopedLock<true> L(*TimerLock);
+  if (TimerGroupList)
+    TimerGroupList->Prev = &Next;
+  Next = TimerGroupList;
+  Prev = &TimerGroupList;
+  TimerGroupList = this;
+}
+
 TimerGroup::~TimerGroup() {
   // If the timer group is destroyed before the timers it owns, accumulate and
   // print the timing data.
   while (FirstTimer != 0)
     removeTimer(*FirstTimer);
+  
+  // Remove the group from the TimerGroupList.
+  sys::SmartScopedLock<true> L(*TimerLock);
+  *Prev = Next;
+  if (Next)
+    Next->Prev = Prev;
 }
 
 
@@ -352,3 +374,11 @@
   if (!TimersToPrint.empty())
     PrintQueuedTimers(OS);
 }
+
+/// printAll - This static method prints all timers and clears them all out.
+void TimerGroup::printAll(raw_ostream &OS) {
+  sys::SmartScopedLock<true> L(*TimerLock);
+
+  for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
+    TG->print(OS);
+}





More information about the llvm-commits mailing list