Skip to content

Commit

Permalink
Refactoring: modernize Statistics & time keeping
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Jan 22, 2021
1 parent fcf2130 commit 84e655b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/debug.cpp
Expand Up @@ -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<std::chrono::system_clock> m_startTime;
Expand Down
33 changes: 13 additions & 20 deletions src/doxygen.cpp
Expand Up @@ -13,6 +13,7 @@
*
*/

#include <chrono>
#include <locale.h>

#include <qfileinfo.h>
Expand Down Expand Up @@ -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()
{
Expand All @@ -220,11 +222,9 @@ class Statistics
restore=TRUE;
}
msg("----------------------\n");
QListIterator<stat> 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");
}
Expand All @@ -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<stat> stats;
QTime time;
std::vector<stat> 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,
Expand Down Expand Up @@ -1781,9 +1777,6 @@ static void findUsingDirectives(const Entry *root)
nd->setMetaData(root->metaData);
nd->setInline((root->spec&Entry::Inline)!=0);

//QListIterator<Grouping> gli(*root->groups);
//Grouping *g;
//for (;(g=gli.current());++gli)
for (const Grouping &g : root->groups)
{
GroupDef *gd=0;
Expand Down Expand Up @@ -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()
);
Expand Down
36 changes: 19 additions & 17 deletions src/portable.cpp
Expand Up @@ -2,6 +2,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <chrono>

#if defined(_WIN32) && !defined(__CYGWIN__)
#undef UNICODE
Expand All @@ -17,7 +18,6 @@ extern char **environ;

#include <ctype.h>
#include <qglobal.h>
#include <qdatetime.h>
#include <qglobal.h>
#include <qdir.h>
#include <map>
Expand All @@ -34,7 +34,7 @@ static std::map<std::string,std::string> proc_env = std::map<std::string,std::st
#endif

static double g_sysElapsedTime;
static QTime g_time;
static std::chrono::steady_clock::time_point g_startTime;


int Portable::system(const char *command,const char *args,bool commandHasConsole)
Expand Down Expand Up @@ -69,7 +69,7 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole

// on Solaris fork() duplicates the memory usage
// so we use vfork instead

// spawn shell
if ((pid=vfork())<0)
{
Expand Down Expand Up @@ -138,11 +138,11 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
}
else
{
// Because ShellExecuteEx can delegate execution to Shell extensions
// (data sources, context menu handlers, verb implementations) that
// are activated using Component Object Model (COM), COM should be
// initialized before ShellExecuteEx is called. Some Shell extensions
// require the COM single-threaded apartment (STA) type.
// Because ShellExecuteEx can delegate execution to Shell extensions
// (data sources, context menu handlers, verb implementations) that
// are activated using Component Object Model (COM), COM should be
// initialized before ShellExecuteEx is called. Some Shell extensions
// require the COM single-threaded apartment (STA) type.
// For that case COM is initialized as follows
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

Expand All @@ -156,13 +156,13 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
SHELLEXECUTEINFOW sInfo = {
sizeof(SHELLEXECUTEINFOW), /* structure size */
SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI, /* tell us the process
* handle so we can wait till it's done |
* do not display msg box if error
* handle so we can wait till it's done |
* do not display msg box if error
*/
NULL, /* window handle */
NULL, /* action to perform: open */
(LPCWSTR)commandw.ucs2(), /* file to execute */
(LPCWSTR)argsw.ucs2(), /* argument list */
(LPCWSTR)argsw.ucs2(), /* argument list */
NULL, /* use current working dir */
SW_HIDE, /* minimize on start-up */
0, /* application instance handle */
Expand All @@ -180,7 +180,7 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
}
else if (sInfo.hProcess) /* executable was launched, wait for it to finish */
{
WaitForSingleObject(sInfo.hProcess,INFINITE);
WaitForSingleObject(sInfo.hProcess,INFINITE);
/* get process exit code */
DWORD exitCode;
if (!GetExitCodeProcess(sInfo.hProcess,&exitCode))
Expand Down Expand Up @@ -269,7 +269,7 @@ void Portable::unsetenv(const char *variable)
}

const char *Portable::getenv(const char *variable)
{
{
#if defined(_WIN32) && !defined(__CYGWIN__)
return ::getenv(variable);
#else
Expand Down Expand Up @@ -303,7 +303,7 @@ portable_off_t Portable::fseek(FILE *f,portable_off_t offset, int whence)
portable_off_t Portable::ftell(FILE *f)
{
#if defined(__MINGW32__)
return ftello64(f);
return ftello64(f);
#elif defined(_WIN32) && !defined(__CYGWIN__)
return _ftelli64(f);
#else
Expand Down Expand Up @@ -448,12 +448,14 @@ int Portable::pclose(FILE *stream)

void Portable::sysTimerStart()
{
g_time.start();
g_startTime = std::chrono::steady_clock::now();
}

void Portable::sysTimerStop()
{
g_sysElapsedTime+=((double)g_time.elapsed())/1000.0;
std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
g_sysElapsedTime+= std::chrono::duration_cast<
std::chrono::microseconds>(endTime - g_startTime).count()/1000000.0;
}

double Portable::getSysElapsedTime()
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions src/pyscanner.l
Expand Up @@ -1141,9 +1141,6 @@ STARTDOCSYMS "##"
// do something based on the type of the IDENTIFIER
if (yyextra->current->type.isEmpty())
{
//QListIterator<Entry> 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))
Expand Down
4 changes: 0 additions & 4 deletions src/vhdljjparser.cpp
Expand Up @@ -656,10 +656,6 @@ void VHDLOutlineParser::addProto(const char *s1,const char *s2,const char *s3,
*/
void VHDLOutlineParser::mapLibPackage( Entry* root)
{
//QList<Entry> epp=libUse;
//EntryListIterator eli(epp);
//Entry *rt;
//for (;(rt=eli.current());++eli)
for (const auto &rt : p->libUse)
{
if (addLibUseClause(rt->name))
Expand Down

0 comments on commit 84e655b

Please sign in to comment.