Skip to content

Commit 7d0c163

Browse files
committed
[NFC][clang] Add PrintOnExit parameter to a timer group
1 parent a042f69 commit 7d0c163

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
128128
std::unique_ptr<llvm::Timer> SyntaxCheckTimer;
129129
std::unique_ptr<llvm::Timer> ExprEngineTimer;
130130
std::unique_ptr<llvm::Timer> BugReporterTimer;
131-
bool ShouldClearTimersToPreventDisplayingThem;
132131

133132
/// The information about analyzed functions shared throughout the
134133
/// translation unit.
@@ -149,7 +148,10 @@ class AnalysisConsumer : public AnalysisASTConsumer,
149148
if (Opts.AnalyzerDisplayProgress || Opts.PrintStats ||
150149
Opts.ShouldSerializeStats || !Opts.DumpEntryPointStatsToCSV.empty()) {
151150
AnalyzerTimers = std::make_unique<llvm::TimerGroup>(
152-
"analyzer", "Analyzer timers");
151+
"analyzer", "Analyzer timers",
152+
/*PrintOnExit=*/
153+
(Opts.AnalyzerDisplayProgress || Opts.PrintStats ||
154+
Opts.ShouldSerializeStats));
153155
SyntaxCheckTimer = std::make_unique<llvm::Timer>(
154156
"syntaxchecks", "Syntax-based analysis time", *AnalyzerTimers);
155157
ExprEngineTimer = std::make_unique<llvm::Timer>(
@@ -159,12 +161,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
159161
*AnalyzerTimers);
160162
}
161163

162-
// Avoid displaying the timers created above in case we only want to record
163-
// per-entry-point stats.
164-
ShouldClearTimersToPreventDisplayingThem = !Opts.AnalyzerDisplayProgress &&
165-
!Opts.PrintStats &&
166-
!Opts.ShouldSerializeStats;
167-
168164
if (Opts.PrintStats || Opts.ShouldSerializeStats) {
169165
llvm::EnableStatistics(/* DoPrintOnExit= */ false);
170166
}
@@ -287,9 +283,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
287283
checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
288284
if (SyntaxCheckTimer)
289285
SyntaxCheckTimer->stopTimer();
290-
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
291-
AnalyzerTimers->clear();
292-
}
293286
}
294287
return true;
295288
}
@@ -583,9 +576,6 @@ void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
583576
checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
584577
if (SyntaxCheckTimer)
585578
SyntaxCheckTimer->stopTimer();
586-
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
587-
AnalyzerTimers->clear();
588-
}
589579

590580
// Run the AST-only checks using the order in which functions are defined.
591581
// If inlining is not turned on, use the simplest function order for path
@@ -765,9 +755,6 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
765755
FunctionSummaries.findOrInsertSummary(D)->second.SyntaxRunningTime =
766756
std::lround(CheckerEndTime.getWallTime() * 1000);
767757
DisplayTime(CheckerEndTime);
768-
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
769-
AnalyzerTimers->clear();
770-
}
771758
}
772759
}
773760

@@ -830,9 +817,6 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
830817
PathRunningTime.set(static_cast<unsigned>(
831818
std::lround(ExprEngineEndTime.getWallTime() * 1000)));
832819
DisplayTime(ExprEngineEndTime);
833-
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
834-
AnalyzerTimers->clear();
835-
}
836820
}
837821

838822
if (!Mgr->options.DumpExplodedGraphTo.empty())
@@ -843,9 +827,6 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
843827
Eng.ViewGraph(Mgr->options.TrimGraph);
844828

845829
flushReports(BugReporterTimer.get(), Eng.getBugReporter());
846-
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
847-
AnalyzerTimers->clear();
848-
}
849830
}
850831

851832
//===----------------------------------------------------------------------===//

llvm/include/llvm/Support/Timer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class TimerGroup {
203203
std::string Description;
204204
Timer *FirstTimer = nullptr; ///< First timer in the group.
205205
std::vector<PrintRecord> TimersToPrint;
206+
bool PrintOnExit;
206207

207208
TimerGroup **Prev; ///< Pointer to Next field of previous timergroup in list.
208209
TimerGroup *Next; ///< Pointer to next timergroup in list.
@@ -211,10 +212,11 @@ class TimerGroup {
211212

212213
friend class TimerGlobals;
213214
explicit TimerGroup(StringRef Name, StringRef Description,
214-
sys::SmartMutex<true> &lock);
215+
sys::SmartMutex<true> &lock, bool PrintOnExit);
215216

216217
public:
217-
LLVM_ABI explicit TimerGroup(StringRef Name, StringRef Description);
218+
LLVM_ABI explicit TimerGroup(StringRef Name, StringRef Description,
219+
bool PrintOnExit = true);
218220

219221
LLVM_ABI explicit TimerGroup(StringRef Name, StringRef Description,
220222
const StringMap<TimeRecord> &Records);

llvm/lib/Support/Timer.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class Name2PairMap {
240240
getGroupEntry(StringRef GroupName, StringRef GroupDescription) {
241241
std::pair<TimerGroup *, Name2TimerMap> &GroupEntry = Map[GroupName];
242242
if (!GroupEntry.first)
243-
GroupEntry.first = new TimerGroup(GroupName, GroupDescription);
243+
GroupEntry.first = new TimerGroup(GroupName, GroupDescription, /*PrintOnExit=*/true);
244244

245245
return GroupEntry;
246246
}
@@ -270,9 +270,10 @@ TimerGroup &NamedRegionTimer::getNamedTimerGroup(StringRef GroupName,
270270
static TimerGroup *TimerGroupList = nullptr;
271271

272272
TimerGroup::TimerGroup(StringRef Name, StringRef Description,
273-
sys::SmartMutex<true> &lock)
273+
sys::SmartMutex<true> &lock, bool PrintOnExit)
274274
: Name(Name.begin(), Name.end()),
275-
Description(Description.begin(), Description.end()) {
275+
Description(Description.begin(), Description.end()),
276+
PrintOnExit(PrintOnExit) {
276277
// Add the group to TimerGroupList.
277278
sys::SmartScopedLock<true> L(lock);
278279
if (TimerGroupList)
@@ -282,12 +283,12 @@ TimerGroup::TimerGroup(StringRef Name, StringRef Description,
282283
TimerGroupList = this;
283284
}
284285

285-
TimerGroup::TimerGroup(StringRef Name, StringRef Description)
286-
: TimerGroup(Name, Description, timerLock()) {}
286+
TimerGroup::TimerGroup(StringRef Name, StringRef Description, bool PrintOnExit)
287+
: TimerGroup(Name, Description, timerLock(), PrintOnExit) {}
287288

288289
TimerGroup::TimerGroup(StringRef Name, StringRef Description,
289290
const StringMap<TimeRecord> &Records)
290-
: TimerGroup(Name, Description) {
291+
: TimerGroup(Name, Description, /*PrintOnExit=*/false) {
291292
TimersToPrint.reserve(Records.size());
292293
for (const auto &P : Records)
293294
TimersToPrint.emplace_back(P.getValue(), std::string(P.getKey()),
@@ -301,7 +302,7 @@ TimerGroup::~TimerGroup() {
301302
while (FirstTimer)
302303
removeTimer(*FirstTimer);
303304

304-
if (!TimersToPrint.empty()) {
305+
if (!TimersToPrint.empty() && PrintOnExit) {
305306
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
306307
PrintQueuedTimers(*OutStream);
307308
}
@@ -530,7 +531,7 @@ class llvm::TimerGlobals {
530531

531532
sys::SmartMutex<true> TimerLock;
532533
TimerGroup DefaultTimerGroup{"misc", "Miscellaneous Ungrouped Timers",
533-
TimerLock};
534+
TimerLock, /*PrintOnExit=*/true};
534535
SignpostEmitter Signposts;
535536

536537
// Order of these members and initialization below is important. For example

0 commit comments

Comments
 (0)