From 83fa78efb19d288d172a5db87bafcb9a34a4f035 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 30 Mar 2010 05:27:58 +0000 Subject: finally, maintain a global list of timer groups, allowing us to implement TimerGroup::printAll, which prints and resets all active timers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99876 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Timer.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/Support/Timer.cpp') diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index ace9158f6c..5b17a26b83 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -239,11 +239,33 @@ NamedRegionTimer::NamedRegionTimer(const std::string &Name, // 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 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 L(*TimerLock); + *Prev = Next; + if (Next) + Next->Prev = Prev; } @@ -352,3 +374,11 @@ void TimerGroup::print(raw_ostream &OS) { 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 L(*TimerLock); + + for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next) + TG->print(OS); +} -- cgit v1.2.3