Skip to content

[llvm][Timer] Don't print timers in TimerGroup when all Timers are removed #131026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions llvm/lib/Support/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ TimerGroup::~TimerGroup() {
while (FirstTimer)
removeTimer(*FirstTimer);

if (!TimersToPrint.empty()) {
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
PrintQueuedTimers(*OutStream);
}

// Remove the group from the TimerGroupList.
sys::SmartScopedLock<true> L(timerLock());
*Prev = Next;
Expand All @@ -305,14 +310,6 @@ void TimerGroup::removeTimer(Timer &T) {
*T.Prev = T.Next;
if (T.Next)
T.Next->Prev = T.Prev;

// Print the report when all timers in this group are destroyed if some of
// them were started.
if (FirstTimer || TimersToPrint.empty())
return;

std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
PrintQueuedTimers(*OutStream);
}

void TimerGroup::addTimer(Timer &T) {
Expand Down
18 changes: 17 additions & 1 deletion llvm/unittests/Support/TimerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,20 @@ TEST(Timer, CheckIfTriggered) {
EXPECT_FALSE(T1.hasTriggered());
}

} // end anon namespace
TEST(Timer, TimerGroupTimerDestructed) {
testing::internal::CaptureStderr();

{
TimerGroup TG("tg", "desc");
{
Timer T1("T1", "T1", TG);
T1.startTimer();
T1.stopTimer();
}
EXPECT_TRUE(testing::internal::GetCapturedStderr().empty());
testing::internal::CaptureStderr();
}
EXPECT_FALSE(testing::internal::GetCapturedStderr().empty());
}

} // namespace
Loading