From 84e655b1e4792b232ed72c70c80269d002142a7f Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Mon, 18 Jan 2021 20:54:45 +0100 Subject: Refactoring: modernize Statistics & time keeping --- src/debug.cpp | 4 ++-- src/doxygen.cpp | 33 +++++++++++++-------------------- src/portable.cpp | 36 +++++++++++++++++++----------------- src/pyscanner.l | 3 --- src/vhdljjparser.cpp | 4 ---- 5 files changed, 34 insertions(+), 46 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index f56ef3a..c270b47 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -118,8 +118,8 @@ class Timer double elapsedTimeS() { return (std::chrono::duration_cast< - std::chrono::milliseconds>( - std::chrono::system_clock::now() - m_startTime).count()) / 1000.0; + std::chrono::microseconds>( + std::chrono::system_clock::now() - m_startTime).count()) / 1000000.0; } private: std::chrono::time_point m_startTime; diff --git a/src/doxygen.cpp b/src/doxygen.cpp index b7076d7..483426f 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -13,6 +13,7 @@ * */ +#include #include #include @@ -199,17 +200,18 @@ void clearAll() class Statistics { public: - Statistics() { stats.setAutoDelete(TRUE); } + Statistics() {} void begin(const char *name) { msg("%s", name); - stat *entry= new stat(name,0); - stats.append(entry); - time.restart(); + stats.emplace_back(name,0); + startTime = std::chrono::steady_clock::now(); } void end() { - stats.getLast()->elapsed=((double)time.elapsed())/1000.0; + std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now(); + stats.back().elapsed = std::chrono::duration_cast< + std::chrono::microseconds>(endTime - startTime).count()/1000000.0; } void print() { @@ -220,11 +222,9 @@ class Statistics restore=TRUE; } msg("----------------------\n"); - QListIterator sli(stats); - stat *s; - for ( sli.toFirst(); (s=sli.current()); ++sli ) + for (const auto &s : stats) { - msg("Spent %.3f seconds in %s",s->elapsed,s->name); + msg("Spent %.6f seconds in %s",s.elapsed,s.name); } if (restore) Debug::setFlag("time"); } @@ -233,18 +233,14 @@ class Statistics { const char *name; double elapsed; - stat() : name(NULL),elapsed(0) {} + //stat() : name(NULL),elapsed(0) {} stat(const char *n, double el) : name(n),elapsed(el) {} }; - QList stats; - QTime time; + std::vector stats; + std::chrono::steady_clock::time_point startTime; } g_s; -void statistics() -{ -} - static void addMemberDocs(const Entry *root,MemberDefMutable *md, const char *funcDecl, const ArgumentList *al,bool over_load,uint64 spec); static void findMember(const Entry *root, @@ -1781,9 +1777,6 @@ static void findUsingDirectives(const Entry *root) nd->setMetaData(root->metaData); nd->setInline((root->spec&Entry::Inline)!=0); - //QListIterator gli(*root->groups); - //Grouping *g; - //for (;(g=gli.current());++gli) for (const Grouping &g : root->groups) { GroupDef *gd=0; @@ -11890,7 +11883,7 @@ void generateOutput() if (Debug::isFlagSet(Debug::Time)) { - msg("Total elapsed time: %.3f seconds\n(of which %.3f seconds waiting for external tools to finish)\n", + msg("Total elapsed time: %.6f seconds\n(of which %.6f seconds waiting for external tools to finish)\n", ((double)Debug::elapsedTime()), Portable::getSysElapsedTime() ); diff --git a/src/portable.cpp b/src/portable.cpp index 0ffbd49..85a6718 100644 --- a/src/portable.cpp +++ b/src/portable.cpp @@ -2,6 +2,7 @@ #include #include +#include #if defined(_WIN32) && !defined(__CYGWIN__) #undef UNICODE @@ -17,7 +18,6 @@ extern char **environ; #include #include -#include #include #include #include @@ -34,7 +34,7 @@ static std::map proc_env = std::map(endTime - g_startTime).count()/1000000.0; } double Portable::getSysElapsedTime() @@ -561,7 +563,7 @@ static const char * portable_memmem (const char *haystack, size_t haystack_len, const char *Portable::strnstr(const char *haystack, const char *needle, size_t haystack_len) { size_t needle_len = strnlen(needle, haystack_len); - if (needle_len < haystack_len || !needle[needle_len]) + if (needle_len < haystack_len || !needle[needle_len]) { const char *x = portable_memmem(haystack, haystack_len, needle, needle_len); if (x && !memchr(haystack, 0, x - haystack)) diff --git a/src/pyscanner.l b/src/pyscanner.l index 56e8dc8..403b400 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -1141,9 +1141,6 @@ STARTDOCSYMS "##" // do something based on the type of the IDENTIFIER if (yyextra->current->type.isEmpty()) { - //QListIterator eli(*(yyextra->current_root->children())); - //Entry *child; - //for (eli.toFirst();(child=eli.yyextra->current());++eli) for (const auto &child : yyextra->current_root->children()) { if (child->name == QCString(yytext)) diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index 4ca4bbe..2d67ec6 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -656,10 +656,6 @@ void VHDLOutlineParser::addProto(const char *s1,const char *s2,const char *s3, */ void VHDLOutlineParser::mapLibPackage( Entry* root) { - //QList epp=libUse; - //EntryListIterator eli(epp); - //Entry *rt; - //for (;(rt=eli.current());++eli) for (const auto &rt : p->libUse) { if (addLibUseClause(rt->name)) -- cgit v0.12