[llvm-dev] printing statistics timers
George Karpenkov via llvm-dev
llvm-dev at lists.llvm.org
Tue Feb 6 19:19:32 PST 2018
The diff which I’ve ended up using to do what I need is:
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 0c85faecca8..7fe8d776cfb 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -336,10 +336,16 @@ void TimerGroup::prepareToPrintList() {
// reset them.
for (Timer *T = FirstTimer; T; T = T->Next) {
if (!T->hasTriggered()) continue;
+
+ bool WasRunning = T->isRunning();
+ if (WasRunning)
+ T->stopTimer();
+
TimersToPrint.emplace_back(T->Time, T->Name, T->Description);
- // Clear out the time.
- T->clear();
+ if (WasRunning)
+ T->startTimer();
}
}
…but the code could race, so further hints are welcome.
> On Feb 6, 2018, at 6:42 PM, George Karpenkov <ekarpenkov at apple.com> wrote:
>
> Hi,
>
> The code in Support/Timer.cpp has strangely inconsistent behavior for printAll vs printJSONValues.
> The former can work multiple times, while the latter calls prepareToPrintList(), which stops all timers,
> hence making all further attempts to print timers crash.
>
> Would it be possible not to call prepareToPrintList on printJSONValues, or at least make it optional?
> I am trying to serialize displayed statistic using PrintStatisticJSON, and it actually crashes if the statistic is printed again
> due to stopped timers.
>
> George
More information about the llvm-dev
mailing list