Fixed #5306 (Implement --showtime=top5)

This commit is contained in:
Alexander Mai 2014-01-03 10:24:57 +01:00 committed by Daniel Marjamäki
parent 7a6386bc4b
commit ea10a722fc
5 changed files with 15 additions and 9 deletions

View File

@ -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()

View File

@ -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),

View File

@ -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) */

View File

@ -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<std::string, struct TimerResultsData>::const_iterator I = _results.begin();
const std::map<std::string, struct TimerResultsData>::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();

View File

@ -25,7 +25,7 @@
#include <ctime>
#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: