Skip to content

Commit c48be7f

Browse files
committed
[analyzer] Add more timers for performance profiling.
The -analyzer-stats flag now allows you to find out how much time was spent on AST-based analysis and on path-sensitive analysis and, separately, on bug visitors, as they're occasionally a performance problem on their own. The total timer wasn't useful because there's anyway a total time printed out. Remove it. Differential Revision: https://reviews.llvm.org/D63227 llvm-svn: 364266
1 parent 7939ba0 commit c48be7f

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ExprEngine : public SubEngine {
161161
SetOfConstDecls *VisitedCalleesIn,
162162
FunctionSummariesTy *FS, InliningModes HowToInlineIn);
163163

164-
~ExprEngine() override;
164+
~ExprEngine() override = default;
165165

166166
/// Returns true if there is still simulation state on the worklist.
167167
bool ExecuteWorkList(const LocationContext *L, unsigned Steps = 150000) {

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ ExprEngine::ExprEngine(cross_tu::CrossTranslationUnitContext &CTU,
225225
}
226226
}
227227

228-
ExprEngine::~ExprEngine() {
229-
BR.FlushReports();
230-
}
231-
232228
//===----------------------------------------------------------------------===//
233229
// Utility methods.
234230
//===----------------------------------------------------------------------===//

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

+34-9
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ class AnalysisConsumer : public AnalysisASTConsumer,
196196

197197
/// Time the analyzes time of each translation unit.
198198
std::unique_ptr<llvm::TimerGroup> AnalyzerTimers;
199-
std::unique_ptr<llvm::Timer> TUTotalTimer;
199+
std::unique_ptr<llvm::Timer> SyntaxCheckTimer;
200+
std::unique_ptr<llvm::Timer> ExprEngineTimer;
201+
std::unique_ptr<llvm::Timer> BugReporterTimer;
200202

201203
/// The information about analyzed functions shared throughout the
202204
/// translation unit.
@@ -212,8 +214,13 @@ class AnalysisConsumer : public AnalysisASTConsumer,
212214
if (Opts->PrintStats || Opts->ShouldSerializeStats) {
213215
AnalyzerTimers = llvm::make_unique<llvm::TimerGroup>(
214216
"analyzer", "Analyzer timers");
215-
TUTotalTimer = llvm::make_unique<llvm::Timer>(
216-
"time", "Analyzer total time", *AnalyzerTimers);
217+
SyntaxCheckTimer = llvm::make_unique<llvm::Timer>(
218+
"syntaxchecks", "Syntax-based analysis time", *AnalyzerTimers);
219+
ExprEngineTimer = llvm::make_unique<llvm::Timer>(
220+
"exprengine", "Path exploration time", *AnalyzerTimers);
221+
BugReporterTimer = llvm::make_unique<llvm::Timer>(
222+
"bugreporter", "Path-sensitive report post-processing time",
223+
*AnalyzerTimers);
217224
llvm::EnableStatistics(/* PrintOnExit= */ false);
218225
}
219226
}
@@ -346,8 +353,13 @@ class AnalysisConsumer : public AnalysisASTConsumer,
346353
/// Handle callbacks for arbitrary Decls.
347354
bool VisitDecl(Decl *D) {
348355
AnalysisMode Mode = getModeForDecl(D, RecVisitorMode);
349-
if (Mode & AM_Syntax)
356+
if (Mode & AM_Syntax) {
357+
if (SyntaxCheckTimer)
358+
SyntaxCheckTimer->startTimer();
350359
checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
360+
if (SyntaxCheckTimer)
361+
SyntaxCheckTimer->stopTimer();
362+
}
351363
return true;
352364
}
353365

@@ -566,7 +578,11 @@ static bool isBisonFile(ASTContext &C) {
566578
void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
567579
BugReporter BR(*Mgr);
568580
TranslationUnitDecl *TU = C.getTranslationUnitDecl();
581+
if (SyntaxCheckTimer)
582+
SyntaxCheckTimer->startTimer();
569583
checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
584+
if (SyntaxCheckTimer)
585+
SyntaxCheckTimer->stopTimer();
570586

571587
// Run the AST-only checks using the order in which functions are defined.
572588
// If inlining is not turned on, use the simplest function order for path
@@ -608,8 +624,6 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
608624
if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
609625
return;
610626

611-
if (TUTotalTimer) TUTotalTimer->startTimer();
612-
613627
if (isBisonFile(C)) {
614628
reportAnalyzerProgress("Skipping bison-generated file\n");
615629
} else if (Opts->DisableAllChecks) {
@@ -622,8 +636,6 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
622636
runAnalysisOnTranslationUnit(C);
623637
}
624638

625-
if (TUTotalTimer) TUTotalTimer->stopTimer();
626-
627639
// Count how many basic blocks we have not covered.
628640
NumBlocksInAnalyzedFunctions = FunctionSummaries.getTotalNumBasicBlocks();
629641
NumVisitedBlocksInAnalyzedFunctions =
@@ -747,8 +759,13 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
747759

748760
BugReporter BR(*Mgr);
749761

750-
if (Mode & AM_Syntax)
762+
if (Mode & AM_Syntax) {
763+
if (SyntaxCheckTimer)
764+
SyntaxCheckTimer->startTimer();
751765
checkerMgr->runCheckersOnASTBody(D, *Mgr, BR);
766+
if (SyntaxCheckTimer)
767+
SyntaxCheckTimer->stopTimer();
768+
}
752769
if ((Mode & AM_Path) && checkerMgr->hasPathSensitiveCheckers()) {
753770
RunPathSensitiveChecks(D, IMode, VisitedCallees);
754771
if (IMode != ExprEngine::Inline_Minimal)
@@ -775,8 +792,12 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
775792
ExprEngine Eng(CTU, *Mgr, VisitedCallees, &FunctionSummaries, IMode);
776793

777794
// Execute the worklist algorithm.
795+
if (ExprEngineTimer)
796+
ExprEngineTimer->startTimer();
778797
Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D),
779798
Mgr->options.MaxNodesPerTopLevelFunction);
799+
if (ExprEngineTimer)
800+
ExprEngineTimer->stopTimer();
780801

781802
if (!Mgr->options.DumpExplodedGraphTo.empty())
782803
Eng.DumpGraph(Mgr->options.TrimGraph, Mgr->options.DumpExplodedGraphTo);
@@ -786,7 +807,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
786807
Eng.ViewGraph(Mgr->options.TrimGraph);
787808

788809
// Display warnings.
810+
if (BugReporterTimer)
811+
BugReporterTimer->startTimer();
789812
Eng.getBugReporter().FlushReports();
813+
if (BugReporterTimer)
814+
BugReporterTimer->stopTimer();
790815
}
791816

792817
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)