From 55db301b8cf7dd4ec49ae1f63479cf11c73065c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 27 Jul 2009 14:41:34 +0200 Subject: [PATCH] gcc: added an option '--showtime' => show some simple timing information --- src/cppcheck.cpp | 34 ++++++++++++++++++++++++++++++++++ src/settings.cpp | 3 +++ src/settings.h | 5 +++++ 3 files changed, 42 insertions(+) diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index 819a0c281..e1395e29b 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -110,6 +110,12 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) else if (strcmp(argv[i], "--unused-functions") == 0) _settings._unusedFunctions = true; +#ifdef __GNUC__ + // show timing information.. + else if (strcmp(argv[i], "--showtime") == 0) + _settings._showtime = true; +#endif + // Print help else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { @@ -367,7 +373,17 @@ unsigned int CppCheck::check() } cfg = *it; +#ifdef __GNUC__ + clock_t c1 = clock(); + const std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, fname, _errorLogger); + if (_settings._showtime) + { + clock_t c2 = clock(); + std::cout << "Preprocessor::getcode: " << ((c2 - c1) / 1000) << std::endl; + } +#else std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, fname, _errorLogger); +#endif // If only errors are printed, print filename after the check if (_settings._errorsOnly == false && it != configurations.begin()) @@ -434,7 +450,17 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) (*it)->runChecks(&_tokenizer, &_settings, this); } +#ifdef __GNUC__ + { + clock_t c1 = clock(); + _tokenizer.simplifyTokenList(); + clock_t c2 = clock(); + if (_settings._showtime) + std::cout << "Tokenizer::simplifyTokenList: " << ((c2 - c1) / 1000) << std::endl; + } +#else _tokenizer.simplifyTokenList(); +#endif if (_settings._unusedFunctions) _checkUnusedFunctions.parseTokens(_tokenizer); @@ -442,7 +468,15 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) // call all "runSimplifiedChecks" in all registered Check classes for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { +#ifdef __GNUC__ + clock_t c1 = clock(); (*it)->runSimplifiedChecks(&_tokenizer, &_settings, this); + clock_t c2 = clock(); + if (_settings._showtime) + std::cout << (*it)->name() << "::runSimplifiedChecks: " << ((c2 - c1) / 1000) << std::endl; +#else + (*it)->runSimplifiedChecks(&_tokenizer, &_settings, this); +#endif } } diff --git a/src/settings.cpp b/src/settings.cpp index ecc8ba92d..310876330 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -32,6 +32,9 @@ Settings::Settings() _unusedFunctions = false; _jobs = 1; _exitCode = 0; +#ifdef __GNUC__ + _showtime = false; +#endif } Settings::~Settings() diff --git a/src/settings.h b/src/settings.h index 41a3f235d..4ff8bad01 100644 --- a/src/settings.h +++ b/src/settings.h @@ -65,6 +65,11 @@ public: Default value is 0. */ int _exitCode; +#ifdef __GNUC__ + /** show timing information */ + bool _showtime; +#endif + /** List of include paths, e.g. "my/includes/" which should be used for finding include files inside source files. */ std::list _includePaths;