Skip to content

Commit 1cfca53

Browse files
authored
[llvm][Timer] Don't print timers in TimerGroup when all Timers are removed (#131026)
Only print them on TimerGroup destruction (or eagerly when TimerGroup::printAll() is called). We should be able to destroy all Timers in a TimerGroup while delaying printing the stored TimeRecords.
1 parent c14e459 commit 1cfca53

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

llvm/lib/Support/Timer.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ TimerGroup::~TimerGroup() {
284284
while (FirstTimer)
285285
removeTimer(*FirstTimer);
286286

287+
if (!TimersToPrint.empty()) {
288+
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
289+
PrintQueuedTimers(*OutStream);
290+
}
291+
287292
// Remove the group from the TimerGroupList.
288293
sys::SmartScopedLock<true> L(timerLock());
289294
*Prev = Next;
@@ -305,14 +310,6 @@ void TimerGroup::removeTimer(Timer &T) {
305310
*T.Prev = T.Next;
306311
if (T.Next)
307312
T.Next->Prev = T.Prev;
308-
309-
// Print the report when all timers in this group are destroyed if some of
310-
// them were started.
311-
if (FirstTimer || TimersToPrint.empty())
312-
return;
313-
314-
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
315-
PrintQueuedTimers(*OutStream);
316313
}
317314

318315
void TimerGroup::addTimer(Timer &T) {

llvm/unittests/Support/TimerTest.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,20 @@ TEST(Timer, CheckIfTriggered) {
6666
EXPECT_FALSE(T1.hasTriggered());
6767
}
6868

69-
} // end anon namespace
69+
TEST(Timer, TimerGroupTimerDestructed) {
70+
testing::internal::CaptureStderr();
71+
72+
{
73+
TimerGroup TG("tg", "desc");
74+
{
75+
Timer T1("T1", "T1", TG);
76+
T1.startTimer();
77+
T1.stopTimer();
78+
}
79+
EXPECT_TRUE(testing::internal::GetCapturedStderr().empty());
80+
testing::internal::CaptureStderr();
81+
}
82+
EXPECT_FALSE(testing::internal::GetCapturedStderr().empty());
83+
}
84+
85+
} // namespace

0 commit comments

Comments
 (0)