Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp =================================================================== --- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -128,7 +128,8 @@ Plugins(plugins), Injector(injector), CTU(CI), MacroExpansions(CI.getLangOpts()) { DigestAnalyzerOptions(); - if (Opts->PrintStats || Opts->ShouldSerializeStats) { + if (Opts->AnalyzerDisplayProgress || Opts->PrintStats || + Opts->ShouldSerializeStats) { AnalyzerTimers = std::make_unique( "analyzer", "Analyzer timers"); SyntaxCheckTimer = std::make_unique( @@ -138,6 +139,9 @@ BugReporterTimer = std::make_unique( "bugreporter", "Path-sensitive report post-processing time", *AnalyzerTimers); + } + + if (Opts->PrintStats || Opts->ShouldSerializeStats) { llvm::EnableStatistics(/* PrintOnExit= */ false); } @@ -183,6 +187,14 @@ } } + void DisplayTime(llvm::TimeRecord &Time) { + if (!Opts->AnalyzerDisplayProgress) { + return; + } + llvm::errs() << " : " << llvm::format("%1.1f", Time.getWallTime() * 1000) + << " ms\n"; + } + void DisplayFunction(const Decl *D, AnalysisMode Mode, ExprEngine::InliningModes IMode) { if (!Opts->AnalyzerDisplayProgress) @@ -209,8 +221,7 @@ } else assert(Mode == (AM_Syntax | AM_Path) && "Unexpected mode!"); - llvm::errs() << ": " << Loc.getFilename() << ' ' << getFunctionName(D) - << '\n'; + llvm::errs() << ": " << Loc.getFilename() << ' ' << getFunctionName(D); } } @@ -661,19 +672,26 @@ if (Mgr->getAnalysisDeclContext(D)->isBodyAutosynthesized()) return; - DisplayFunction(D, Mode, IMode); CFG *DeclCFG = Mgr->getCFG(D); if (DeclCFG) MaxCFGSize.updateMax(DeclCFG->size()); + DisplayFunction(D, Mode, IMode); BugReporter BR(*Mgr); if (Mode & AM_Syntax) { - if (SyntaxCheckTimer) + llvm::TimeRecord CheckerStartTime; + if (SyntaxCheckTimer) { + CheckerStartTime = SyntaxCheckTimer->getTotalTime(); SyntaxCheckTimer->startTimer(); + } checkerMgr->runCheckersOnASTBody(D, *Mgr, BR); - if (SyntaxCheckTimer) + if (SyntaxCheckTimer) { SyntaxCheckTimer->stopTimer(); + llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime(); + CheckerEndTime -= CheckerStartTime; + DisplayTime(CheckerEndTime); + } } BR.FlushReports(); @@ -704,12 +722,19 @@ ExprEngine Eng(CTU, *Mgr, VisitedCallees, &FunctionSummaries, IMode); // Execute the worklist algorithm. - if (ExprEngineTimer) + llvm::TimeRecord ExprEngineStartTime; + if (ExprEngineTimer) { + ExprEngineStartTime = ExprEngineTimer->getTotalTime(); ExprEngineTimer->startTimer(); + } Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D), Mgr->options.MaxNodesPerTopLevelFunction); - if (ExprEngineTimer) + if (ExprEngineTimer) { ExprEngineTimer->stopTimer(); + llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime(); + ExprEngineEndTime -= ExprEngineStartTime; + DisplayTime(ExprEngineEndTime); + } if (!Mgr->options.DumpExplodedGraphTo.empty()) Eng.DumpGraph(Mgr->options.TrimGraph, Mgr->options.DumpExplodedGraphTo); Index: clang/test/Analysis/analyzer-display-progress.cpp =================================================================== --- clang/test/Analysis/analyzer-display-progress.cpp +++ clang/test/Analysis/analyzer-display-progress.cpp @@ -20,11 +20,11 @@ }; } -// CHECK: analyzer-display-progress.cpp f() -// CHECK: analyzer-display-progress.cpp g() -// CHECK: analyzer-display-progress.cpp h() -// CHECK: analyzer-display-progress.cpp SomeStruct::f() -// CHECK: analyzer-display-progress.cpp SomeOtherStruct::f() -// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(int) -// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, ::SomeStruct) -// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, struct ns::SomeStruct) +// CHECK: analyzer-display-progress.cpp f() : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp g() : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp h() : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp SomeStruct::f() : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp SomeOtherStruct::f() : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(int) : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, ::SomeStruct) : {{[0-9]+}} +// CHECK: analyzer-display-progress.cpp ns::SomeStruct::f(float, struct ns::SomeStruct) : {{[0-9]+}}