-
Notifications
You must be signed in to change notification settings - Fork 15k
[NFC][support] Add operator- to TimeRecord #163361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
@llvm/pr-subscribers-clang-static-analyzer-1 Author: Arseniy Zaostrovnykh (necto) ChangesA 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 Full diff: https://github.com/llvm/llvm-project/pull/163361.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 4efde59aab763..5ecaeea5ddf96 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -757,9 +757,9 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
++NumFunctionsAnalyzedSyntaxOnly;
if (SyntaxCheckTimer) {
SyntaxCheckTimer->stopTimer();
- llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
- CheckerEndTime -= CheckerStartTime;
- DisplayTime(CheckerEndTime);
+ llvm::TimeRecord CheckerDuration =
+ SyntaxCheckTimer->getTotalTime() - CheckerStartTime;
+ DisplayTime(CheckerDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
@@ -804,11 +804,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
Mgr->options.MaxNodesPerTopLevelFunction);
if (ExprEngineTimer) {
ExprEngineTimer->stopTimer();
- llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime();
- ExprEngineEndTime -= ExprEngineStartTime;
+ llvm::TimeRecord ExprEngineDuration =
+ ExprEngineTimer->getTotalTime() - ExprEngineStartTime;
PathRunningTime.set(static_cast<unsigned>(
- std::lround(ExprEngineEndTime.getWallTime() * 1000)));
- DisplayTime(ExprEngineEndTime);
+ std::lround(ExprEngineDuration.getWallTime() * 1000)));
+ DisplayTime(ExprEngineDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h
index 40709d49db011..8412200e4c981 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -66,6 +66,11 @@ class TimeRecord {
MemUsed -= RHS.MemUsed;
InstructionsExecuted -= RHS.InstructionsExecuted;
}
+ TimeRecord operator-(const TimeRecord &RHS) const {
+ TimeRecord R = *this;
+ R -= RHS;
+ return R;
+ }
/// Print the current time record to \p OS, with a breakdown showing
/// contributions to the \p Total time record.
|
|
@llvm/pr-subscribers-llvm-support Author: Arseniy Zaostrovnykh (necto) ChangesA 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 Full diff: https://github.com/llvm/llvm-project/pull/163361.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 4efde59aab763..5ecaeea5ddf96 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -757,9 +757,9 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
++NumFunctionsAnalyzedSyntaxOnly;
if (SyntaxCheckTimer) {
SyntaxCheckTimer->stopTimer();
- llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
- CheckerEndTime -= CheckerStartTime;
- DisplayTime(CheckerEndTime);
+ llvm::TimeRecord CheckerDuration =
+ SyntaxCheckTimer->getTotalTime() - CheckerStartTime;
+ DisplayTime(CheckerDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
@@ -804,11 +804,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
Mgr->options.MaxNodesPerTopLevelFunction);
if (ExprEngineTimer) {
ExprEngineTimer->stopTimer();
- llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime();
- ExprEngineEndTime -= ExprEngineStartTime;
+ llvm::TimeRecord ExprEngineDuration =
+ ExprEngineTimer->getTotalTime() - ExprEngineStartTime;
PathRunningTime.set(static_cast<unsigned>(
- std::lround(ExprEngineEndTime.getWallTime() * 1000)));
- DisplayTime(ExprEngineEndTime);
+ std::lround(ExprEngineDuration.getWallTime() * 1000)));
+ DisplayTime(ExprEngineDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h
index 40709d49db011..8412200e4c981 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -66,6 +66,11 @@ class TimeRecord {
MemUsed -= RHS.MemUsed;
InstructionsExecuted -= RHS.InstructionsExecuted;
}
+ TimeRecord operator-(const TimeRecord &RHS) const {
+ TimeRecord R = *this;
+ R -= RHS;
+ return R;
+ }
/// Print the current time record to \p OS, with a breakdown showing
/// contributions to the \p Total time record.
|
|
@llvm/pr-subscribers-clang Author: Arseniy Zaostrovnykh (necto) ChangesA 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 Full diff: https://github.com/llvm/llvm-project/pull/163361.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 4efde59aab763..5ecaeea5ddf96 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -757,9 +757,9 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
++NumFunctionsAnalyzedSyntaxOnly;
if (SyntaxCheckTimer) {
SyntaxCheckTimer->stopTimer();
- llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
- CheckerEndTime -= CheckerStartTime;
- DisplayTime(CheckerEndTime);
+ llvm::TimeRecord CheckerDuration =
+ SyntaxCheckTimer->getTotalTime() - CheckerStartTime;
+ DisplayTime(CheckerDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
@@ -804,11 +804,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
Mgr->options.MaxNodesPerTopLevelFunction);
if (ExprEngineTimer) {
ExprEngineTimer->stopTimer();
- llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime();
- ExprEngineEndTime -= ExprEngineStartTime;
+ llvm::TimeRecord ExprEngineDuration =
+ ExprEngineTimer->getTotalTime() - ExprEngineStartTime;
PathRunningTime.set(static_cast<unsigned>(
- std::lround(ExprEngineEndTime.getWallTime() * 1000)));
- DisplayTime(ExprEngineEndTime);
+ std::lround(ExprEngineDuration.getWallTime() * 1000)));
+ DisplayTime(ExprEngineDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h
index 40709d49db011..8412200e4c981 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -66,6 +66,11 @@ class TimeRecord {
MemUsed -= RHS.MemUsed;
InstructionsExecuted -= RHS.InstructionsExecuted;
}
+ TimeRecord operator-(const TimeRecord &RHS) const {
+ TimeRecord R = *this;
+ R -= RHS;
+ return R;
+ }
/// Print the current time record to \p OS, with a breakdown showing
/// contributions to the \p Total time record.
|
|
This NFC fixes a quirk observed in #162839 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for creating this patch!
|
@kazutakahirata Do you know who should review this PR? |
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
SyntaxCheckTimerandExprEngineTimerone can compute duration directly.