aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Timer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-03-30 05:27:58 +0000
committerChris Lattner <sabre@nondot.org>2010-03-30 05:27:58 +0000
commit90fe73dc92cf994c45fea46a826816a1a95d1f7e (patch)
treed02ae822461571932089d8485139af8fe8f17198 /llvm/lib/Support/Timer.cpp
parent4cd6571fef9e0cbb26ef5f61a2943d4380c7dfa4 (diff)
downloadllvm-90fe73dc92cf994c45fea46a826816a1a95d1f7e.zip
llvm-90fe73dc92cf994c45fea46a826816a1a95d1f7e.tar.gz
llvm-90fe73dc92cf994c45fea46a826816a1a95d1f7e.tar.bz2
finally, maintain a global list of timer groups, allowing us to
implement TimerGroup::printAll, which prints and resets all active timers. llvm-svn: 99876
Diffstat (limited to 'llvm/lib/Support/Timer.cpp')
-rw-r--r--llvm/lib/Support/Timer.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp
index ace9158..5b17a26 100644
--- a/llvm/lib/Support/Timer.cpp
+++ b/llvm/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<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 @@ 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<true> L(*TimerLock);
+
+ for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
+ TG->print(OS);
+}