-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
41b0037
Fix #14206 --showtime does not account for addons
olabetskyi 4770995
Add global timer
olabetskyi 3ae5770
Rework + test fix
olabetskyi 2fee380
Merge branch 'main' into fix_14206
olabetskyi 2ba38c4
Nits
olabetskyi b7e889a
Some test nits
olabetskyi 170782a
Test fix
olabetskyi 7006ea4
include
olabetskyi d8c18c3
Small nit
olabetskyi 6e587b5
Nits
olabetskyi 2633020
Nits 2
olabetskyi aa049f8
Some more work
olabetskyi 270ba35
Some test revert
olabetskyi 98f362d
Small nits
olabetskyi bbb5199
Small nits
olabetskyi a576a54
Nits
olabetskyi 45e3b2d
Nits
olabetskyi e344a79
Global var
olabetskyi d4a936d
Nit
olabetskyi 6271c02
Small nits
olabetskyi ed23668
Anoher small nit
olabetskyi d83f797
SOme more changes
olabetskyi ea16e4b
Test fix
olabetskyi 67a71be
Small workaround
olabetskyi 6c036ca
Nits
olabetskyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,13 @@ | |
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| constexpr char Timer::OVERALL[]; | ||
|
|
||
| namespace { | ||
| using dataElementType = std::pair<std::string, TimerResultsData>; | ||
| bool more_second_sec(const dataElementType& lhs, const dataElementType& rhs) | ||
| { | ||
| return lhs.second.seconds() > rhs.second.seconds(); | ||
| return lhs.second.getSeconds() > rhs.second.getSeconds(); | ||
| } | ||
|
|
||
| // TODO: remove and print through (synchronized) ErrorLogger instead | ||
|
|
@@ -38,12 +40,10 @@ namespace { | |
|
|
||
| // TODO: this does not include any file context when SHOWTIME_FILE thus rendering it useless - should we include the logging with the progress logging? | ||
| // that could also get rid of the broader locking | ||
| void TimerResults::showResults(SHOWTIME_MODES mode) const | ||
| void TimerResults::showResults(ShowTime mode) const | ||
| { | ||
| if (mode == SHOWTIME_MODES::SHOWTIME_NONE || mode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| if (mode == ShowTime::NONE || mode == ShowTime::FILE_TOTAL) | ||
| return; | ||
|
|
||
| TimerResultsData overallData; | ||
| std::vector<dataElementType> data; | ||
|
|
||
| { | ||
|
|
@@ -61,38 +61,20 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const | |
|
|
||
| size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later! | ||
| for (auto iter=data.cbegin(); iter!=data.cend(); ++iter) { | ||
| const double sec = iter->second.seconds(); | ||
| const double sec = iter->second.getSeconds().count(); | ||
| const double secAverage = sec / static_cast<double>(iter->second.mNumberOfResults); | ||
| bool hasParent = false; | ||
| { | ||
| // Do not use valueFlow.. in "Overall time" because those are included in Tokenizer already | ||
| if (startsWith(iter->first,"valueFlow")) | ||
| hasParent = true; | ||
|
|
||
| // Do not use inner timers in "Overall time" | ||
| const std::string::size_type pos = iter->first.rfind("::"); | ||
| if (pos != std::string::npos) | ||
| hasParent = std::any_of(data.cbegin(), data.cend(), [iter,pos](const dataElementType& d) { | ||
| return d.first.size() == pos && iter->first.compare(0, d.first.size(), d.first) == 0; | ||
| }); | ||
| } | ||
| if (!hasParent) | ||
| overallData.mClocks += iter->second.mClocks; | ||
| if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5_FILE && mode != SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY) || (ordinal<=5)) { | ||
| if ((mode != ShowTime::TOP5_FILE && mode != ShowTime::TOP5_SUMMARY) || (ordinal<=5)) { | ||
| std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl; | ||
| } | ||
| ++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) | ||
| void TimerResults::addResults(const std::string& str, std::chrono::milliseconds duration) | ||
| { | ||
| std::lock_guard<std::mutex> l(mResultsSync); | ||
|
|
||
| mResults[str].mClocks += clocks; | ||
| mResults[str].mDuration += duration; | ||
| mResults[str].mNumberOfResults++; | ||
| } | ||
|
|
||
|
|
@@ -102,17 +84,11 @@ void TimerResults::reset() | |
| mResults.clear(); | ||
| } | ||
|
|
||
| Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults) | ||
| Timer::Timer(std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults) | ||
| : mStr(std::move(str)) | ||
| , mTimerResults(timerResults) | ||
| , mStart(std::clock()) | ||
| , mShowTimeMode(showtimeMode) | ||
| , mStopped(showtimeMode == SHOWTIME_MODES::SHOWTIME_NONE || showtimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| {} | ||
|
|
||
| Timer::Timer(bool fileTotal, std::string filename) | ||
| : mStr(std::move(filename)) | ||
| , mStopped(!fileTotal) | ||
| , mStartTimePoint(Clock::now()) | ||
| {} | ||
|
|
||
| Timer::~Timer() | ||
|
|
@@ -122,23 +98,42 @@ Timer::~Timer() | |
|
|
||
| void Timer::stop() | ||
| { | ||
| if ((mShowTimeMode != SHOWTIME_MODES::SHOWTIME_NONE) && !mStopped) { | ||
| const std::clock_t end = std::clock(); | ||
| const std::clock_t diff = end - mStart; | ||
|
|
||
| if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) { | ||
| 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; | ||
| if ((mShowTimeMode != ShowTime::NONE) && mStartTimePoint != TimePoint{}) { | ||
| auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - mStartTimePoint); | ||
| if (!mTimerResults) { | ||
| if (mStr == OVERALL | ||
| && (mShowTimeMode != ShowTime::TOP5_SUMMARY && mShowTimeMode != ShowTime::TOP5_FILE && mShowTimeMode != ShowTime::SUMMARY)) | ||
| return; | ||
| if (mStr != OVERALL | ||
| && (mShowTimeMode != ShowTime::FILE && mShowTimeMode != ShowTime::FILE_TOTAL)) | ||
| return; | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl; | ||
| std::cout << (mStr == OVERALL ? "Overall time: " : "Check time: " + mStr + ": ")<< TimerResultsData::durationToString(diff) << std::endl; | ||
| } else { | ||
| if (mTimerResults) | ||
| mTimerResults->addResults(mStr, diff); | ||
| mTimerResults->addResults(mStr, diff); | ||
| } | ||
| } | ||
| mShowTimeMode = ShowTime::NONE; // prevent multiple stops | ||
| } | ||
|
|
||
| mStopped = true; | ||
| std::string TimerResultsData::durationToString(std::chrono::milliseconds duration) | ||
| { | ||
| // Extract hours | ||
| auto hours = std::chrono::duration_cast<std::chrono::hours>(duration); | ||
| duration -= hours; // Subtract the extracted hours | ||
|
|
||
| // Extract minutes | ||
| auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration); | ||
| duration -= minutes; // Subtract the extracted minutes | ||
|
|
||
| // Extract seconds | ||
| std::chrono::duration<double> seconds = std::chrono::duration_cast<std::chrono::duration<double>>(duration); | ||
|
|
||
| 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 "; | ||
| std::string secondsStr{std::to_string(seconds.count())}; | ||
| return (ellapsedTime + secondsStr.substr(0, secondsStr.length() - 3) + "s"); | ||
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.