Uh oh!
There was an error while loading. Please reload this page.
- 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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
791815ef50a83bb3f83a6a9b382661d6c2ef4704c8ae8c19d657a8480244d2ec15117eb3ab3755a3abb3ff2a51a8dbeda2ef67e97dc02479fcf6c89b2c5a56176e6793a3e5d95a89705d695765c2af3152e8b8b9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| - 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? | ||
CollaboratorAuthor 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) | ||
Uh oh!
There was an error while loading. Please reload this page.
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