Fixed #11715 (Add --showtime=file-total option to show checking time of each file) (#5049)

This commit is contained in:
Daniel Marjamäki 2023-05-11 14:04:22 +02:00 committed by GitHub
parent d5951fa2b9
commit e1d5d9988d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 9 deletions

View File

@ -830,6 +830,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
const std::string showtimeMode = argv[i] + 11;
if (showtimeMode == "file")
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_FILE;
else if (showtimeMode == "file-total")
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL;
else if (showtimeMode == "summary")
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY;
else if (showtimeMode == "top5")
@ -837,7 +839,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
else if (showtimeMode.empty())
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
else {
printError("unrecognized showtime mode: \"" + showtimeMode + "\". Supported modes: file, summary, top5.");
printError("unrecognized showtime mode: \"" + showtimeMode + "\". Supported modes: file, file-total, summary, top5.");
return false;
}
}

View File

@ -638,6 +638,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
if (Settings::terminated())
return mExitCode;
const Timer fileTotalTimer(mSettings.showtime == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL, filename);
if (!mSettings.quiet) {
std::string fixedpath = Path::simplifyPath(filename);
fixedpath = Path::toNativeSeparators(fixedpath);

View File

@ -40,7 +40,7 @@ namespace {
void TimerResults::showResults(SHOWTIME_MODES mode) const
{
if (mode == SHOWTIME_MODES::SHOWTIME_NONE)
if (mode == SHOWTIME_MODES::SHOWTIME_NONE || mode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)
return;
std::cout << std::endl;
@ -90,13 +90,18 @@ void TimerResults::addResults(const std::string& str, std::clock_t clocks)
Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults)
: mStr(std::move(str))
, mTimerResults(timerResults)
, mStart(0)
, mStart(std::clock())
, mShowTimeMode(showtimeMode)
, mStopped(false)
{
if (showtimeMode != SHOWTIME_MODES::SHOWTIME_NONE)
mStart = std::clock();
}
, mStopped(showtimeMode == SHOWTIME_MODES::SHOWTIME_NONE || showtimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)
{}
Timer::Timer(bool fileTotal, std::string filename)
: mStr(std::move(filename))
, mTimerResults(nullptr)
, mStart(std::clock())
, mShowTimeMode(SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)
, mStopped(!fileTotal)
{}
Timer::~Timer()
{
@ -112,6 +117,9 @@ void Timer::stop()
if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) {
const double sec = (double)diff / CLOCKS_PER_SEC;
std::cout << mStr << ": " << sec << "s" << std::endl;
} else if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) {
const double sec = (double)diff / CLOCKS_PER_SEC;
std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl;
} else {
if (mTimerResults)
mTimerResults->addResults(mStr, diff);

View File

@ -28,8 +28,9 @@
#include <string>
enum class SHOWTIME_MODES {
SHOWTIME_NONE = 0,
SHOWTIME_NONE,
SHOWTIME_FILE,
SHOWTIME_FILE_TOTAL,
SHOWTIME_SUMMARY,
SHOWTIME_TOP5
};
@ -70,6 +71,7 @@ private:
class CPPCHECKLIB Timer {
public:
Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults = nullptr);
Timer(bool fileTotal, std::string filename);
~Timer();
Timer(const Timer&) = delete;