-
Couldn't load subscription status.
- Fork 1.5k
Fix #14206 --showtime does not account for addons #7904
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
41b0037
4770995
3ae5770
2fee380
2ba38c4
b7e889a
170782a
7006ea4
d8c18c3
6e587b5
2633020
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -895,7 +895,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str | |
| if (Settings::terminated()) | ||
| return mLogger->exitcode(); | ||
|
|
||
| const Timer fileTotalTimer(mSettings.showtime == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL, file.spath()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the old interface so we don't have to cancel it.. |
||
| Timer WholeFileTimer{file.spath()}; | ||
| if (mSettings.showtime != SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| WholeFileTimer.cancelRealTimeMeasurement(); | ||
|
|
||
| if (!mSettings.quiet) { | ||
| std::string fixedpath = Path::toNativeSeparators(file.spath()); | ||
|
|
@@ -1311,8 +1313,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str | |
| // TODO: clear earlier? | ||
| mLogger->clear(); | ||
|
|
||
| if (mSettings.showtime == SHOWTIME_MODES::SHOWTIME_FILE || mSettings.showtime == SHOWTIME_MODES::SHOWTIME_TOP5_FILE) | ||
| printTimerResults(mSettings.showtime); | ||
| printTimerResults(mSettings.showtime); | ||
|
|
||
| return mLogger->exitcode(); | ||
| } | ||
|
|
@@ -1505,7 +1506,9 @@ void CppCheck::executeAddons(const std::string& dumpFile, const FileWithDetails& | |
| { | ||
| if (!dumpFile.empty()) { | ||
| std::vector<std::string> f{dumpFile}; | ||
| executeAddons(f, file.spath()); | ||
| Timer::run("CppCheck::executeAddons", mSettings.showtime, &s_timerResults, [&]() { | ||
| executeAddons(f, file.spath()); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,9 +83,6 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const | |
| } | ||
| ++ordinal; | ||
| } | ||
|
|
||
| const double secOverall = overallData.seconds(); | ||
| std::cout << "Overall time: " << secOverall << "s" << std::endl; | ||
| } | ||
|
|
||
| void TimerResults::addResults(const std::string& str, std::clock_t clocks) | ||
|
|
@@ -108,11 +105,13 @@ Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* tim | |
| , mStart(std::clock()) | ||
| , mShowTimeMode(showtimeMode) | ||
| , mStopped(showtimeMode == SHOWTIME_MODES::SHOWTIME_NONE || showtimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| , mStartTimePoint(Clock::now()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we need to have both mStart and mStartTimePoint. Why not remove the |
||
| {} | ||
|
|
||
| Timer::Timer(bool fileTotal, std::string filename) | ||
| : mStr(std::move(filename)) | ||
| , mStopped(!fileTotal) | ||
| Timer::Timer(std::string str) | ||
| : mStr(std::move(str)) | ||
| , mShowTimeMode(SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| , mStartTimePoint(Clock::now()) | ||
| {} | ||
|
|
||
| Timer::~Timer() | ||
|
|
@@ -130,15 +129,41 @@ void Timer::stop() | |
| const double sec = static_cast<double>(diff) / CLOCKS_PER_SEC; | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << mStr << ": " << sec << "s" << std::endl; | ||
| } else if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) { | ||
| const double sec = static_cast<double>(diff) / CLOCKS_PER_SEC; | ||
| } else if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL && mStartTimePoint != TimePoint{}) { | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl; | ||
| std::cout << "Check time: " << mStr << ": " << getRealTimePassed() << std::endl; | ||
| } else { | ||
| if (mTimerResults) | ||
| mTimerResults->addResults(mStr, diff); | ||
| else if (mStr.empty() && mStartTimePoint != TimePoint{}) { // Get real time | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << "Overall time: " << getRealTimePassed() << std::endl; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| mStopped = true; | ||
| } | ||
|
|
||
| std::string Timer::getRealTimePassed() | ||
| { | ||
| auto diff = std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - mStartTimePoint); | ||
|
|
||
| // Extract hours | ||
| auto hours = std::chrono::duration_cast<std::chrono::hours>(diff); | ||
| diff -= hours; // Subtract the extracted hours | ||
|
|
||
| // Extract minutes | ||
| auto minutes = std::chrono::duration_cast<std::chrono::minutes>(diff); | ||
| diff -= minutes; // Subtract the extracted minutes | ||
|
|
||
| // Extract seconds | ||
| auto seconds = static_cast<double>(diff.count()) / std::chrono::microseconds::period::den; | ||
|
|
||
| std::string ellapsedTime; | ||
| if (hours.count() > 0) | ||
| ellapsedTime += std::to_string(hours.count()) + "h "; | ||
| if (minutes.count() > 0) | ||
| ellapsedTime += std::to_string(minutes.count()) + "m "; | ||
| return (ellapsedTime + std::to_string(seconds) + "s "); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,6 @@ | |
| #include <algorithm> | ||
| #include <array> | ||
| #include <cassert> | ||
| #include <chrono> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we include it in the timer now |
||
| #include <cstdint> | ||
| #include <cstdlib> | ||
| #include <cstring> | ||
|
|
||
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.
I like that you made it a RAII. If the timer is moved down below the CmdLineParser then we don't need to cancel the timer. That could maybe loose a millisecond.. but this is acceptable imho. I don't care if the total time says 1.978s or 1.979s ..