Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ frontend/frontend.o: frontend/frontend.cpp frontend/frontend.h lib/addoninfo.h l
cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/filelister.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h lib/xml.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cmdlineparser.cpp

cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.h cli/sehwrapper.h cli/signalhandler.h cli/singleexecutor.h cli/threadexecutor.h externals/picojson/picojson.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/checkers.h lib/checkersreport.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/sarifreport.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.h cli/sehwrapper.h cli/signalhandler.h cli/singleexecutor.h cli/threadexecutor.h externals/picojson/picojson.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/checkers.h lib/checkersreport.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/sarifreport.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutor.cpp

cli/executor.o: cli/executor.cpp cli/executor.h lib/addoninfo.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
Expand Down
5 changes: 5 additions & 0 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "settings.h"
#include "singleexecutor.h"
#include "suppressions.h"
#include "timer.h"
#include "utils.h"

#if defined(HAS_THREADING_MODEL_THREAD)
Expand Down Expand Up @@ -259,6 +260,7 @@ namespace {

int CppCheckExecutor::check(int argc, const char* const argv[])
{
auto startTime{Timer::now()};
Settings settings;
CmdLineLoggerStd logger;
Suppressions supprs;
Expand All @@ -277,6 +279,9 @@ int CppCheckExecutor::check(int argc, const char* const argv[])

const int ret = check_wrapper(settings, supprs);

if (settings.showtime != SHOWTIME_MODES::SHOWTIME_NONE)
Timer::calculateAndOutputTimeDiff(startTime, Timer::now());

return ret;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,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());
});
}
}

Expand Down
29 changes: 26 additions & 3 deletions lib/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -142,3 +139,29 @@ void Timer::stop()

mStopped = true;
}

void Timer::calculateAndOutputTimeDiff(const tp& start, const tp& end)
{
auto diff = std::chrono::duration_cast<std::chrono::microseconds>(end - start);

// 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 ";
ellapsedTime += std::to_string(seconds) + "s ";

std::lock_guard<std::mutex> l(stdCoutLock);
std::cout << "Overall time: " << ellapsedTime << std::endl;
}
10 changes: 10 additions & 0 deletions lib/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "config.h"

#include <chrono>
#include <cstdint>
#include <ctime>
#include <functional>
Expand Down Expand Up @@ -79,6 +80,14 @@ class CPPCHECKLIB Timer {
Timer(const Timer&) = delete;
Timer& operator=(const Timer&) = delete;

using tp = std::chrono::time_point<std::chrono::high_resolution_clock>;

static tp now() {
return std::chrono::high_resolution_clock::now();
}

static void calculateAndOutputTimeDiff(const tp& start, const tp& end);

void stop();

static void run(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults, const std::function<void()>& f) {
Expand All @@ -93,5 +102,6 @@ class CPPCHECKLIB Timer {
const SHOWTIME_MODES mShowTimeMode = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL;
bool mStopped{};
};

//---------------------------------------------------------------------------
#endif // timerH
1 change: 0 additions & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion test/testprocessexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class TestProcessExecutorBase : public TestFixture {
$.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY));
const std::string output_s = GET_REDIRECT_OUTPUT;
// once: top5 results + overall + empty line
TODO_ASSERT_EQUALS(5 + 1 + 1, 2, cppcheck::count_all_of(output_s, '\n'));
TODO_ASSERT_EQUALS(5 + 1 + 1, 1, cppcheck::count_all_of(output_s, '\n'));
// should only report the top5 once
ASSERT(output_s.find("1 result(s)") == std::string::npos);
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
Expand Down
10 changes: 5 additions & 5 deletions test/testsingleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ class TestSingleExecutorBase : public TestFixture {
dinit(CheckOptions,
$.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_FILE));
const std::string output_s = GET_REDIRECT_OUTPUT;
// for each file: top5 results + overall + empty line
ASSERT_EQUALS((5 + 1 + 1) * 2LL, cppcheck::count_all_of(output_s, '\n'));
// for each file: top5 results + overall
ASSERT_EQUALS((5 + 1) * 2LL, cppcheck::count_all_of(output_s, '\n'));
}

void showtime_top5_summary() {
Expand All @@ -253,8 +253,8 @@ class TestSingleExecutorBase : public TestFixture {
dinit(CheckOptions,
$.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY));
const std::string output_s = GET_REDIRECT_OUTPUT;
// once: top5 results + overall + empty line
ASSERT_EQUALS(5 + 1 + 1, cppcheck::count_all_of(output_s, '\n'));
// once: top5 results + overall
ASSERT_EQUALS(5 + 1, cppcheck::count_all_of(output_s, '\n'));
// should only report the top5 once
ASSERT(output_s.find("1 result(s)") == std::string::npos);
ASSERT(output_s.find("2 result(s)") != std::string::npos);
Expand All @@ -267,7 +267,7 @@ class TestSingleExecutorBase : public TestFixture {
dinit(CheckOptions,
$.showtime = SHOWTIME_MODES::SHOWTIME_FILE));
const std::string output_s = GET_REDIRECT_OUTPUT;
ASSERT_EQUALS(2, cppcheck::count_all_of(output_s, "Overall time:"));
ASSERT_EQUALS(0, cppcheck::count_all_of(output_s, "Overall time:"));
}

void showtime_summary() {
Expand Down
11 changes: 5 additions & 6 deletions test/testthreadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,9 @@ class TestThreadExecutorBase : public TestFixture {
"int main() {}",
dinit(CheckOptions,
$.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_FILE));
// for each file: top5 results + overall + empty line
const std::string output_s = GET_REDIRECT_OUTPUT;
// for each file: top5 results + overall + empty line
ASSERT_EQUALS((5 + 1 + 1) * 2LL, cppcheck::count_all_of(output_s, '\n'));
// for each file: top5 results + overall
ASSERT_EQUALS((5 + 1) * 2LL, cppcheck::count_all_of(output_s, '\n'));
}

void showtime_top5_summary() {
Expand All @@ -246,8 +245,8 @@ class TestThreadExecutorBase : public TestFixture {
dinit(CheckOptions,
$.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY));
const std::string output_s = GET_REDIRECT_OUTPUT;
// once: top5 results + overall + empty line
ASSERT_EQUALS(5 + 1 + 1, cppcheck::count_all_of(output_s, '\n'));
// once: top5 results + overall
ASSERT_EQUALS(5 + 1, cppcheck::count_all_of(output_s, '\n'));
// should only report the top5 once
ASSERT(output_s.find("1 result(s)") == std::string::npos);
ASSERT(output_s.find("2 result(s)") != std::string::npos);
Expand All @@ -260,7 +259,7 @@ class TestThreadExecutorBase : public TestFixture {
dinit(CheckOptions,
$.showtime = SHOWTIME_MODES::SHOWTIME_FILE));
const std::string output_s = GET_REDIRECT_OUTPUT;
ASSERT_EQUALS(2, cppcheck::count_all_of(output_s, "Overall time:"));
ASSERT_EQUALS(0, cppcheck::count_all_of(output_s, "Overall time:"));
}

void showtime_summary() {
Expand Down