Skip to content
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
27 changes: 4 additions & 23 deletions clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
std::unique_ptr<llvm::Timer> SyntaxCheckTimer;
std::unique_ptr<llvm::Timer> ExprEngineTimer;
std::unique_ptr<llvm::Timer> BugReporterTimer;
bool ShouldClearTimersToPreventDisplayingThem;

/// The information about analyzed functions shared throughout the
/// translation unit.
Expand All @@ -149,7 +148,10 @@ class AnalysisConsumer : public AnalysisASTConsumer,
if (Opts.AnalyzerDisplayProgress || Opts.PrintStats ||
Opts.ShouldSerializeStats || !Opts.DumpEntryPointStatsToCSV.empty()) {
AnalyzerTimers = std::make_unique<llvm::TimerGroup>(
"analyzer", "Analyzer timers");
"analyzer", "Analyzer timers",
/*PrintOnExit=*/
(Opts.AnalyzerDisplayProgress || Opts.PrintStats ||
Opts.ShouldSerializeStats));
SyntaxCheckTimer = std::make_unique<llvm::Timer>(
"syntaxchecks", "Syntax-based analysis time", *AnalyzerTimers);
ExprEngineTimer = std::make_unique<llvm::Timer>(
Expand All @@ -159,12 +161,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
*AnalyzerTimers);
}

// Avoid displaying the timers created above in case we only want to record
// per-entry-point stats.
ShouldClearTimersToPreventDisplayingThem = !Opts.AnalyzerDisplayProgress &&
!Opts.PrintStats &&
!Opts.ShouldSerializeStats;

if (Opts.PrintStats || Opts.ShouldSerializeStats) {
llvm::EnableStatistics(/* DoPrintOnExit= */ false);
}
Expand Down Expand Up @@ -287,9 +283,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
if (SyntaxCheckTimer)
SyntaxCheckTimer->stopTimer();
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
}
return true;
}
Expand Down Expand Up @@ -583,9 +576,6 @@ void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
if (SyntaxCheckTimer)
SyntaxCheckTimer->stopTimer();
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}

// Run the AST-only checks using the order in which functions are defined.
// If inlining is not turned on, use the simplest function order for path
Expand Down Expand Up @@ -765,9 +755,6 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
FunctionSummaries.findOrInsertSummary(D)->second.SyntaxRunningTime =
std::lround(CheckerDuration.getWallTime() * 1000);
DisplayTime(CheckerDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
}
}

Expand Down Expand Up @@ -830,9 +817,6 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
PathRunningTime.set(static_cast<unsigned>(
std::lround(ExprEngineDuration.getWallTime() * 1000)));
DisplayTime(ExprEngineDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
}

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

flushReports(BugReporterTimer.get(), Eng.getBugReporter());
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
}

//===----------------------------------------------------------------------===//
Expand Down
9 changes: 6 additions & 3 deletions llvm/include/llvm/Support/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class TimerGroup {
std::string Description;
Timer *FirstTimer = nullptr; ///< First timer in the group.
std::vector<PrintRecord> TimersToPrint;
bool PrintOnExit;

TimerGroup **Prev; ///< Pointer to Next field of previous timergroup in list.
TimerGroup *Next; ///< Pointer to next timergroup in list.
Expand All @@ -217,13 +218,15 @@ class TimerGroup {

friend class TimerGlobals;
explicit TimerGroup(StringRef Name, StringRef Description,
sys::SmartMutex<true> &lock);
sys::SmartMutex<true> &lock, bool PrintOnExit);

public:
LLVM_ABI explicit TimerGroup(StringRef Name, StringRef Description);
LLVM_ABI explicit TimerGroup(StringRef Name, StringRef Description,
bool PrintOnExit = true);

LLVM_ABI explicit TimerGroup(StringRef Name, StringRef Description,
const StringMap<TimeRecord> &Records);
const StringMap<TimeRecord> &Records,
bool PrintOnExit = true);

LLVM_ABI ~TimerGroup();

Expand Down
20 changes: 11 additions & 9 deletions llvm/lib/Support/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class Name2PairMap {
getGroupEntry(StringRef GroupName, StringRef GroupDescription) {
std::pair<TimerGroup *, Name2TimerMap> &GroupEntry = Map[GroupName];
if (!GroupEntry.first)
GroupEntry.first = new TimerGroup(GroupName, GroupDescription);
GroupEntry.first =
new TimerGroup(GroupName, GroupDescription, /*PrintOnExit=*/true);

return GroupEntry;
}
Expand Down Expand Up @@ -270,9 +271,10 @@ TimerGroup &NamedRegionTimer::getNamedTimerGroup(StringRef GroupName,
static TimerGroup *TimerGroupList = nullptr;

TimerGroup::TimerGroup(StringRef Name, StringRef Description,
sys::SmartMutex<true> &lock)
sys::SmartMutex<true> &lock, bool PrintOnExit)
: Name(Name.begin(), Name.end()),
Description(Description.begin(), Description.end()) {
Description(Description.begin(), Description.end()),
PrintOnExit(PrintOnExit) {
// Add the group to TimerGroupList.
sys::SmartScopedLock<true> L(lock);
if (TimerGroupList)
Expand All @@ -282,12 +284,12 @@ TimerGroup::TimerGroup(StringRef Name, StringRef Description,
TimerGroupList = this;
}

TimerGroup::TimerGroup(StringRef Name, StringRef Description)
: TimerGroup(Name, Description, timerLock()) {}
TimerGroup::TimerGroup(StringRef Name, StringRef Description, bool PrintOnExit)
: TimerGroup(Name, Description, timerLock(), PrintOnExit) {}

TimerGroup::TimerGroup(StringRef Name, StringRef Description,
const StringMap<TimeRecord> &Records)
: TimerGroup(Name, Description) {
const StringMap<TimeRecord> &Records, bool PrintOnExit)
: TimerGroup(Name, Description, PrintOnExit) {
TimersToPrint.reserve(Records.size());
for (const auto &P : Records)
TimersToPrint.emplace_back(P.getValue(), std::string(P.getKey()),
Expand All @@ -301,7 +303,7 @@ TimerGroup::~TimerGroup() {
while (FirstTimer)
removeTimer(*FirstTimer);

if (!TimersToPrint.empty()) {
if (!TimersToPrint.empty() && PrintOnExit) {
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
PrintQueuedTimers(*OutStream);
}
Expand Down Expand Up @@ -530,7 +532,7 @@ class llvm::TimerGlobals {

sys::SmartMutex<true> TimerLock;
TimerGroup DefaultTimerGroup{"misc", "Miscellaneous Ungrouped Timers",
TimerLock};
TimerLock, /*PrintOnExit=*/true};
SignpostEmitter Signposts;

// Order of these members and initialization below is important. For example
Expand Down
Loading