-
Notifications
You must be signed in to change notification settings - Fork 1.6k
refs #4452 / refs #11705 - improved --showtime= behavior and testing
#4876
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 all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
791815e
reset timer results before each test
firewave f50a83b
TestThreadExecutor: run tests with quiet flag
firewave b3f83a6
TimerResults: avoid multiple threads writing their results over each …
firewave a9b3826
TestThreadExecutor: added some `showtime` tests
firewave 61d6c2e
actually only print the summary with `--showtime=summary`
firewave f4704c8
cmdlineparser.cpp: added TODO
firewave ae8c19d
testthreadexecutor.cpp: added TODO
firewave 657a848
Timer: removed TODOs
firewave 0244d2e
moved `find_all_of()` into `cppcheck` namespace and into `helpers.h`
firewave c15117e
TestThreadExecutor: inverted default quiet flag
firewave b3ab375
TestProcessExecutor: applied `TestThreadExecutor` changes / use TODO …
firewave 5a3abb3
timer.cpp: added TODO
firewave ff2a51a
cppcheck.cpp: suppress `unusedFunction` selfcheck warning
firewave 8dbeda2
deprecated `--showtime=top5` and introduced the modes `top5_file` and…
firewave ef67e97
renamed `find_all_of()` to `count_all_of()`
firewave dc02479
TestSingleExecutor: applied changes from other executor tests / marke…
firewave fcf6c89
fixed TSAN errors in `Timer::stop()` with `--showtime=file` and multi…
firewave b2c5a56
Timer: use a lock for all `std::cout` uses
firewave 176e679
print timing information in the proper places for `SingleExecutor`
firewave 3a3e5d9
ProcessExecutor: added (partial) missing printing of timing informati…
firewave 5a89705
testprocessexecutor.cpp: fixed `bugprone-implicit-widening-of-multipl…
firewave d695765
converted `test_showtimetop5.sh` into a Python test
firewave c2af315
added test coverage and documentation for `--showtime=file-total`
firewave 2e8b8b9
Timer: added missing lock for `SHOWTIME_FILE_TOTAL` printing
firewave 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
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 |
|---|---|---|
|
|
@@ -24,38 +24,41 @@ | |
| #include <iostream> | ||
| #include <utility> | ||
| #include <vector> | ||
| /* | ||
| TODO: | ||
| - rename "file" to "single" | ||
firewave marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - add unit tests | ||
| - for --showtime (needs input file) | ||
| - for Timer* classes | ||
| */ | ||
|
|
||
| namespace { | ||
| using dataElementType = std::pair<std::string, struct TimerResultsData>; | ||
| bool more_second_sec(const dataElementType& lhs, const dataElementType& rhs) | ||
| { | ||
| return lhs.second.seconds() > rhs.second.seconds(); | ||
| } | ||
|
|
||
| // TODO: remove and print through (synchronized) ErrorLogger instead | ||
| std::mutex stdCoutLock; | ||
| } | ||
|
|
||
| // TODO: this does not include any file context when SHOWTIME_FILE thus rendering it useless - should we include the logging with the progress logging? | ||
|
Collaborator
Author
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. This would also be without context when using |
||
| // that could also get rid of the broader locking | ||
| void TimerResults::showResults(SHOWTIME_MODES mode) const | ||
| { | ||
| if (mode == SHOWTIME_MODES::SHOWTIME_NONE || mode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| return; | ||
|
|
||
| std::cout << std::endl; | ||
| TimerResultsData overallData; | ||
|
|
||
| std::vector<dataElementType> data; | ||
|
|
||
| { | ||
| std::lock_guard<std::mutex> l(mResultsSync); | ||
|
|
||
| data.reserve(mResults.size()); | ||
| data.insert(data.begin(), mResults.cbegin(), mResults.cend()); | ||
| } | ||
| std::sort(data.begin(), data.end(), more_second_sec); | ||
|
|
||
| // lock the whole logging operation to avoid multiple threads printing their results at the same time | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
|
|
||
| std::cout << std::endl; | ||
|
|
||
| size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later! | ||
| for (std::vector<dataElementType>::const_iterator iter=data.cbegin(); iter!=data.cend(); ++iter) { | ||
| const double sec = iter->second.seconds(); | ||
|
|
@@ -75,7 +78,7 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const | |
| } | ||
| if (!hasParent) | ||
| overallData.mClocks += iter->second.mClocks; | ||
| if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5) || (ordinal<=5)) { | ||
| if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5_FILE && mode != SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY) || (ordinal<=5)) { | ||
| std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl; | ||
| } | ||
| ++ordinal; | ||
|
|
@@ -93,6 +96,12 @@ void TimerResults::addResults(const std::string& str, std::clock_t clocks) | |
| mResults[str].mNumberOfResults++; | ||
| } | ||
|
|
||
| void TimerResults::reset() | ||
| { | ||
| std::lock_guard<std::mutex> l(mResultsSync); | ||
| mResults.clear(); | ||
| } | ||
|
|
||
| Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults) | ||
| : mStr(std::move(str)) | ||
| , mTimerResults(timerResults) | ||
|
|
@@ -119,9 +128,11 @@ void Timer::stop() | |
|
|
||
| if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) { | ||
| const double sec = (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 = (double)diff / CLOCKS_PER_SEC; | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl; | ||
| } else { | ||
| if (mTimerResults) | ||
|
|
||
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
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.
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.
spelling: wee => we