diff options
| author | Graydon Hoare <ghoare@apple.com> | 2018-08-17 04:13:19 +0000 |
|---|---|---|
| committer | Graydon Hoare <ghoare@apple.com> | 2018-08-17 04:13:19 +0000 |
| commit | eac6e8711864197d5da3eef71d056cffa4acbfb6 (patch) | |
| tree | 7ec4a4764828ba773516c60163f5b5a0b94191f5 | |
| parent | d6a76f761f57fb73cd8d65b317644d2aa061bb0c (diff) | |
| download | bcm5719-llvm-eac6e8711864197d5da3eef71d056cffa4acbfb6.tar.gz bcm5719-llvm-eac6e8711864197d5da3eef71d056cffa4acbfb6.zip | |
[Support] Add a public API to allow clearing all (static) timer groups.
Summary:
Formerly, all timer groups were automatically cleared when printed out. In
https://reviews.llvm.org/rL324788 this behaviour was changed to not-clearing
timers on printout, to allow printing timers more than once, but as a result
clients (specifically Swift) that relied on the clear-on-print behaviour to
inhibit duplicate timer printing on shutdown were broken.
Rather than revert that change, this change adds a new API that enables
clients that _want_ to clear all timers to do so explicitly.
Reviewers: george.karpenkov, thegameg
Reviewed By: george.karpenkov
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D50874
llvm-svn: 339980
| -rw-r--r-- | llvm/include/llvm/Support/Timer.h | 14 | ||||
| -rw-r--r-- | llvm/lib/Support/Timer.cpp | 15 |
2 files changed, 24 insertions, 5 deletions
diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h index bfffbc3157b..a11c3ce3ff2 100644 --- a/llvm/include/llvm/Support/Timer.h +++ b/llvm/include/llvm/Support/Timer.h @@ -206,15 +206,23 @@ public: Description.assign(NewDescription.begin(), NewDescription.end()); } - /// Print any started timers in this group and zero them. + /// Print any started timers in this group. void print(raw_ostream &OS); - /// This static method prints all timers and clears them all out. + /// Clear all timers in this group. + void clear(); + + /// This static method prints all timers. static void printAll(raw_ostream &OS); + /// Clear out all timers. This is mostly used to disable automatic + /// printing on shutdown, when timers have already been printed explicitly + /// using \c printAll or \c printJSONValues. + static void clearAll(); + const char *printJSONValues(raw_ostream &OS, const char *delim); - /// Prints all timers as JSON key/value pairs, and clears them all out. + /// Prints all timers as JSON key/value pairs. static const char *printAllJSONValues(raw_ostream &OS, const char *delim); /// Ensure global timer group lists are initialized. This function is mostly diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 61d3b6c6e31..3821f487a8f 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -343,8 +343,7 @@ void TimerGroup::PrintQueuedTimers(raw_ostream &OS) { } void TimerGroup::prepareToPrintList() { - // See if any of our timers were started, if so add them to TimersToPrint and - // reset them. + // See if any of our timers were started, if so add them to TimersToPrint. for (Timer *T = FirstTimer; T; T = T->Next) { if (!T->hasTriggered()) continue; bool WasRunning = T->isRunning(); @@ -368,6 +367,12 @@ void TimerGroup::print(raw_ostream &OS) { PrintQueuedTimers(OS); } +void TimerGroup::clear() { + sys::SmartScopedLock<true> L(*TimerLock); + for (Timer *T = FirstTimer; T; T = T->Next) + T->clear(); +} + void TimerGroup::printAll(raw_ostream &OS) { sys::SmartScopedLock<true> L(*TimerLock); @@ -375,6 +380,12 @@ void TimerGroup::printAll(raw_ostream &OS) { TG->print(OS); } +void TimerGroup::clearAll() { + sys::SmartScopedLock<true> L(*TimerLock); + for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next) + TG->clear(); +} + void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R, const char *suffix, double Value) { assert(yaml::needsQuotes(Name) == yaml::QuotingType::None && |

