Undocumented --showtime option should now work on other platforms also.
Improved --showtime to give more information.
This commit is contained in:
parent
8e0f868a5e
commit
47e9d174e3
|
@ -34,6 +34,12 @@
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#include <ctime> // clock_t
|
#include <ctime> // clock_t
|
||||||
|
#define TIMER_START() clock_t c1 = clock();
|
||||||
|
#define TIMER_END(str) if(_settings._showtime){clock_t c2 = clock(); std::cout << str << ": " << ((c2 - c1) / 1000) << std::endl;}
|
||||||
|
#else
|
||||||
|
#include <ctime>
|
||||||
|
#define TIMER_START() time_t t1; time(&t1);
|
||||||
|
#define TIMER_END(str) if(_settings._showtime){time_t t2; time(&t2); std::cout << str << ": " << (t2 - t1) << std::endl;}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -132,11 +138,9 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (strncmp(argv[i], "--append=", 9) == 0)
|
else if (strncmp(argv[i], "--append=", 9) == 0)
|
||||||
_settings.append(9 + argv[i]);
|
_settings.append(9 + argv[i]);
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
// show timing information..
|
// show timing information..
|
||||||
else if (strcmp(argv[i], "--showtime") == 0)
|
else if (strcmp(argv[i], "--showtime") == 0)
|
||||||
_settings._showtime = true;
|
_settings._showtime = true;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Print help
|
// Print help
|
||||||
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
|
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
|
||||||
|
@ -406,7 +410,9 @@ unsigned int CppCheck::check()
|
||||||
{
|
{
|
||||||
// Only file name was given, read the content from file
|
// Only file name was given, read the content from file
|
||||||
std::ifstream fin(fname.c_str());
|
std::ifstream fin(fname.c_str());
|
||||||
|
TIMER_START();
|
||||||
preprocessor.preprocess(fin, filedata, configurations, fname, _settings._includePaths);
|
preprocessor.preprocess(fin, filedata, configurations, fname, _settings._includePaths);
|
||||||
|
TIMER_END("Preprocessor::preprocess");
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkCount = 0;
|
int checkCount = 0;
|
||||||
|
@ -423,17 +429,9 @@ unsigned int CppCheck::check()
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = *it;
|
cfg = *it;
|
||||||
#ifdef __GNUC__
|
TIMER_START();
|
||||||
clock_t c1 = clock();
|
|
||||||
const std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, fname, _errorLogger);
|
const std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, fname, _errorLogger);
|
||||||
if (_settings._showtime)
|
TIMER_END("Preprocessor::getcode");
|
||||||
{
|
|
||||||
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 only errors are printed, print filename after the check
|
||||||
if (_settings._errorsOnly == false && it != configurations.begin())
|
if (_settings._errorsOnly == false && it != configurations.begin())
|
||||||
|
@ -482,32 +480,34 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
// Tokenize the file
|
// Tokenize the file
|
||||||
{
|
{
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
TIMER_START();
|
||||||
if (!_tokenizer.tokenize(istr, FileName))
|
if (!_tokenizer.tokenize(istr, FileName))
|
||||||
{
|
{
|
||||||
// File had syntax errors, abort
|
// File had syntax errors, abort
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
TIMER_END("Tokenizer::tokenize");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TIMER_START();
|
||||||
_tokenizer.fillFunctionList();
|
_tokenizer.fillFunctionList();
|
||||||
|
TIMER_END("Tokenizer::fillFunctionList");
|
||||||
|
}
|
||||||
|
|
||||||
// call all "runChecks" in all registered Check classes
|
// call all "runChecks" in all registered Check classes
|
||||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||||
{
|
{
|
||||||
|
TIMER_START();
|
||||||
(*it)->runChecks(&_tokenizer, &_settings, this);
|
(*it)->runChecks(&_tokenizer, &_settings, this);
|
||||||
|
TIMER_END((*it)->name() << "::runChecks");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
{
|
{
|
||||||
clock_t c1 = clock();
|
TIMER_START();
|
||||||
_tokenizer.simplifyTokenList();
|
_tokenizer.simplifyTokenList();
|
||||||
clock_t c2 = clock();
|
TIMER_END("Tokenizer::simplifyTokenList");
|
||||||
if (_settings._showtime)
|
|
||||||
std::cout << "Tokenizer::simplifyTokenList: " << ((c2 - c1) / 1000) << std::endl;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
_tokenizer.simplifyTokenList();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (_settings._unusedFunctions)
|
if (_settings._unusedFunctions)
|
||||||
_checkUnusedFunctions.parseTokens(_tokenizer);
|
_checkUnusedFunctions.parseTokens(_tokenizer);
|
||||||
|
@ -515,15 +515,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
// call all "runSimplifiedChecks" in all registered Check classes
|
// call all "runSimplifiedChecks" in all registered Check classes
|
||||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||||
{
|
{
|
||||||
#ifdef __GNUC__
|
TIMER_START();
|
||||||
clock_t c1 = clock();
|
|
||||||
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
|
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
|
||||||
clock_t c2 = clock();
|
TIMER_END((*it)->name() << "::runSimplifiedChecks");
|
||||||
if (_settings._showtime)
|
|
||||||
std::cout << (*it)->name() << "::runSimplifiedChecks: " << ((c2 - c1) / 1000) << std::endl;
|
|
||||||
#else
|
|
||||||
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue