[llvm-commits] Add helper RAII-style SwitchTimeRegion class (issue1735041)
reid.kleckner at gmail.com
reid.kleckner at gmail.com
Fri Jun 18 17:13:21 PDT 2010
Reviewers: ,
Message:
Please take a look.
Description:
This class pauses one timer while another runs, which is useful when you
are trying to separate time spent in two different sections of code that
call back and forth between each other.
Used like this:
NextToken {
SwitchTimeRegion Region(ParsingTimer, LexingTimer);
... lex lex lex
}
This change supports some profiling in clang:
http://codereview.appspot.com/1683046/show
Please review this at http://codereview.appspot.com/1735041/show
Affected files:
M include/llvm/Support/Timer.h
Index: include/llvm/Support/Timer.h
===================================================================
--- include/llvm/Support/Timer.h (revision 106102)
+++ include/llvm/Support/Timer.h (working copy)
@@ -144,6 +144,27 @@
};
+// The SwitchTimeRegion is similar to the TimeRegion helper class, except
that
+// it takes a second timer which is stopped for the duration of the first
+// timer, and restarted after region is exited. This helps allow nested
+// timers, where you do not want to record the time to perform the nested
+// action.
+class SwitchTimeRegion {
+ Timer *Running;
+ Timer *Paused;
+ SwitchTimeRegion(const SwitchTimeRegion &); // DO NOT IMPLEMENT
+public:
+ explicit SwitchTimeRegion(Timer *R, Timer *P) : Running(R), Paused(P) {
+ if (Paused) Paused->stopTimer();
+ if (Running) Running->startTimer();
+ }
+ ~SwitchTimeRegion() {
+ if (Running) Running->stopTimer();
+ if (Paused) Paused->startTimer();
+ }
+};
+
+
/// NamedRegionTimer - This class is basically a combination of TimeRegion
and
/// Timer. It allows you to declare a new timer, AND specify the region to
/// time, all in one statement. All timers with the same name are
merged. This
More information about the llvm-commits
mailing list