Skip to content

Commit 955c9ee

Browse files
nectoaokblast
authored andcommitted
[NFC][support]Add operator- to TimeRecord (llvm#163361)
A common use case for the Timer is to measure time duration between two points. Lack of operator- forced an non-intuitive two-step duration computation: get the end time, then decrement it by the start time. Now, as demonstrated on the example of `SyntaxCheckTimer` and `ExprEngineTimer` one can compute duration directly.
1 parent 92437bf commit 955c9ee

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,11 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
760760
++NumFunctionsAnalyzedSyntaxOnly;
761761
if (SyntaxCheckTimer) {
762762
SyntaxCheckTimer->stopTimer();
763-
llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
764-
CheckerEndTime -= CheckerStartTime;
763+
llvm::TimeRecord CheckerDuration =
764+
SyntaxCheckTimer->getTotalTime() - CheckerStartTime;
765765
FunctionSummaries.findOrInsertSummary(D)->second.SyntaxRunningTime =
766-
std::lround(CheckerEndTime.getWallTime() * 1000);
767-
DisplayTime(CheckerEndTime);
766+
std::lround(CheckerDuration.getWallTime() * 1000);
767+
DisplayTime(CheckerDuration);
768768
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
769769
AnalyzerTimers->clear();
770770
}
@@ -825,11 +825,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
825825
Mgr->options.MaxNodesPerTopLevelFunction);
826826
if (ExprEngineTimer) {
827827
ExprEngineTimer->stopTimer();
828-
llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime();
829-
ExprEngineEndTime -= ExprEngineStartTime;
828+
llvm::TimeRecord ExprEngineDuration =
829+
ExprEngineTimer->getTotalTime() - ExprEngineStartTime;
830830
PathRunningTime.set(static_cast<unsigned>(
831-
std::lround(ExprEngineEndTime.getWallTime() * 1000)));
832-
DisplayTime(ExprEngineEndTime);
831+
std::lround(ExprEngineDuration.getWallTime() * 1000)));
832+
DisplayTime(ExprEngineDuration);
833833
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
834834
AnalyzerTimers->clear();
835835
}

llvm/include/llvm/Support/Timer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class TimeRecord {
6666
MemUsed -= RHS.MemUsed;
6767
InstructionsExecuted -= RHS.InstructionsExecuted;
6868
}
69+
TimeRecord operator-(const TimeRecord &RHS) const {
70+
TimeRecord R = *this;
71+
R -= RHS;
72+
return R;
73+
}
74+
// Feel free to add operator+ if you need it
6975

7076
/// Print the current time record to \p OS, with a breakdown showing
7177
/// contributions to the \p Total time record.

0 commit comments

Comments
 (0)