From ea10a722fc2a8eef766ccb298521b663641fc5fc Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Fri, 3 Jan 2014 10:24:57 +0100 Subject: [PATCH] Fixed #5306 (Implement --showtime=top5) --- lib/cppcheck.cpp | 3 +-- lib/settings.cpp | 2 +- lib/settings.h | 3 ++- lib/timer.cpp | 12 +++++++++--- lib/timer.h | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index d5a0aa914..d509833a0 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -46,8 +46,7 @@ CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions) CppCheck::~CppCheck() { - if (_settings._showtime != SHOWTIME_NONE) - S_timerResults.ShowResults(); + S_timerResults.ShowResults(_settings._showtime); } const char * CppCheck::version() diff --git a/lib/settings.cpp b/lib/settings.cpp index 89faedc54..37e92b64f 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -35,7 +35,7 @@ Settings::Settings() _xml(false), _xml_version(1), _jobs(1), _exitCode(0), - _showtime(0), + _showtime(SHOWTIME_NONE), _maxConfigs(12), enforcedLang(None), reportProgress(false), diff --git a/lib/settings.h b/lib/settings.h index 23d02651e..9e5f9bfe8 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -29,6 +29,7 @@ #include "library.h" #include "suppressions.h" #include "standards.h" +#include "timer.h" /// @addtogroup Core /// @{ @@ -120,7 +121,7 @@ public: std::string _outputFormat; /** @brief show timing information (--showtime=file|summary|top5) */ - unsigned int _showtime; + SHOWTIME_MODES _showtime; /** @brief List of include paths, e.g. "my/includes/" which should be used for finding include files inside source files. (-I) */ diff --git a/lib/timer.cpp b/lib/timer.cpp index a4e3123c4..f75bc04f9 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -20,7 +20,6 @@ /* TODO: - - handle SHOWTIME_TOP5 in TimerResults - sort list by time - do not sort the results alphabetically - rename "file" to "single" @@ -31,13 +30,17 @@ */ -void TimerResults::ShowResults() const +void TimerResults::ShowResults(SHOWTIME_MODES mode) const { + if (mode == SHOWTIME_NONE) + return; + + std::cout << std::endl; TimerResultsData overallData; std::map::const_iterator I = _results.begin(); const std::map::const_iterator E = _results.end(); - + size_t item = 0; while (I != E) { const double sec = I->second.seconds(); const double secAverage = sec / (double)(I->second._numberOfResults); @@ -46,6 +49,9 @@ void TimerResults::ShowResults() const overallData._clocks += I->second._clocks; ++I; + ++item; + if ((mode == SHOWTIME_TOP5) && (item>=5)) + break; } const double secOverall = overallData.seconds(); diff --git a/lib/timer.h b/lib/timer.h index 38a782b7d..cb1011bbd 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -25,7 +25,7 @@ #include #include "config.h" -enum { +enum SHOWTIME_MODES { SHOWTIME_NONE = 0, SHOWTIME_FILE, SHOWTIME_SUMMARY, @@ -59,7 +59,7 @@ public: TimerResults() { } - void ShowResults() const; + void ShowResults(SHOWTIME_MODES mode) const; virtual void AddResults(const std::string& str, std::clock_t clocks); private: