Skip to content

Commit 84e655b

Browse files
committed
Refactoring: modernize Statistics & time keeping
1 parent fcf2130 commit 84e655b

File tree

5 files changed

+34
-46
lines changed

5 files changed

+34
-46
lines changed

src/debug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class Timer
118118
double elapsedTimeS()
119119
{
120120
return (std::chrono::duration_cast<
121-
std::chrono::milliseconds>(
122-
std::chrono::system_clock::now() - m_startTime).count()) / 1000.0;
121+
std::chrono::microseconds>(
122+
std::chrono::system_clock::now() - m_startTime).count()) / 1000000.0;
123123
}
124124
private:
125125
std::chrono::time_point<std::chrono::system_clock> m_startTime;

src/doxygen.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
*/
1515

16+
#include <chrono>
1617
#include <locale.h>
1718

1819
#include <qfileinfo.h>
@@ -199,17 +200,18 @@ void clearAll()
199200
class Statistics
200201
{
201202
public:
202-
Statistics() { stats.setAutoDelete(TRUE); }
203+
Statistics() {}
203204
void begin(const char *name)
204205
{
205206
msg("%s", name);
206-
stat *entry= new stat(name,0);
207-
stats.append(entry);
208-
time.restart();
207+
stats.emplace_back(name,0);
208+
startTime = std::chrono::steady_clock::now();
209209
}
210210
void end()
211211
{
212-
stats.getLast()->elapsed=((double)time.elapsed())/1000.0;
212+
std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
213+
stats.back().elapsed = std::chrono::duration_cast<
214+
std::chrono::microseconds>(endTime - startTime).count()/1000000.0;
213215
}
214216
void print()
215217
{
@@ -220,11 +222,9 @@ class Statistics
220222
restore=TRUE;
221223
}
222224
msg("----------------------\n");
223-
QListIterator<stat> sli(stats);
224-
stat *s;
225-
for ( sli.toFirst(); (s=sli.current()); ++sli )
225+
for (const auto &s : stats)
226226
{
227-
msg("Spent %.3f seconds in %s",s->elapsed,s->name);
227+
msg("Spent %.6f seconds in %s",s.elapsed,s.name);
228228
}
229229
if (restore) Debug::setFlag("time");
230230
}
@@ -233,18 +233,14 @@ class Statistics
233233
{
234234
const char *name;
235235
double elapsed;
236-
stat() : name(NULL),elapsed(0) {}
236+
//stat() : name(NULL),elapsed(0) {}
237237
stat(const char *n, double el) : name(n),elapsed(el) {}
238238
};
239-
QList<stat> stats;
240-
QTime time;
239+
std::vector<stat> stats;
240+
std::chrono::steady_clock::time_point startTime;
241241
} g_s;
242242

243243

244-
void statistics()
245-
{
246-
}
247-
248244
static void addMemberDocs(const Entry *root,MemberDefMutable *md, const char *funcDecl,
249245
const ArgumentList *al,bool over_load,uint64 spec);
250246
static void findMember(const Entry *root,
@@ -1781,9 +1777,6 @@ static void findUsingDirectives(const Entry *root)
17811777
nd->setMetaData(root->metaData);
17821778
nd->setInline((root->spec&Entry::Inline)!=0);
17831779

1784-
//QListIterator<Grouping> gli(*root->groups);
1785-
//Grouping *g;
1786-
//for (;(g=gli.current());++gli)
17871780
for (const Grouping &g : root->groups)
17881781
{
17891782
GroupDef *gd=0;
@@ -11890,7 +11883,7 @@ void generateOutput()
1189011883

1189111884
if (Debug::isFlagSet(Debug::Time))
1189211885
{
11893-
msg("Total elapsed time: %.3f seconds\n(of which %.3f seconds waiting for external tools to finish)\n",
11886+
msg("Total elapsed time: %.6f seconds\n(of which %.6f seconds waiting for external tools to finish)\n",
1189411887
((double)Debug::elapsedTime()),
1189511888
Portable::getSysElapsedTime()
1189611889
);

src/portable.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stdlib.h>
44
#include <stdio.h>
5+
#include <chrono>
56

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

1819
#include <ctype.h>
1920
#include <qglobal.h>
20-
#include <qdatetime.h>
2121
#include <qglobal.h>
2222
#include <qdir.h>
2323
#include <map>
@@ -34,7 +34,7 @@ static std::map<std::string,std::string> proc_env = std::map<std::string,std::st
3434
#endif
3535

3636
static double g_sysElapsedTime;
37-
static QTime g_time;
37+
static std::chrono::steady_clock::time_point g_startTime;
3838

3939

4040
int Portable::system(const char *command,const char *args,bool commandHasConsole)
@@ -69,7 +69,7 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
6969

7070
// on Solaris fork() duplicates the memory usage
7171
// so we use vfork instead
72-
72+
7373
// spawn shell
7474
if ((pid=vfork())<0)
7575
{
@@ -138,11 +138,11 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
138138
}
139139
else
140140
{
141-
// Because ShellExecuteEx can delegate execution to Shell extensions
142-
// (data sources, context menu handlers, verb implementations) that
143-
// are activated using Component Object Model (COM), COM should be
144-
// initialized before ShellExecuteEx is called. Some Shell extensions
145-
// require the COM single-threaded apartment (STA) type.
141+
// Because ShellExecuteEx can delegate execution to Shell extensions
142+
// (data sources, context menu handlers, verb implementations) that
143+
// are activated using Component Object Model (COM), COM should be
144+
// initialized before ShellExecuteEx is called. Some Shell extensions
145+
// require the COM single-threaded apartment (STA) type.
146146
// For that case COM is initialized as follows
147147
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
148148

@@ -156,13 +156,13 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
156156
SHELLEXECUTEINFOW sInfo = {
157157
sizeof(SHELLEXECUTEINFOW), /* structure size */
158158
SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI, /* tell us the process
159-
* handle so we can wait till it's done |
160-
* do not display msg box if error
159+
* handle so we can wait till it's done |
160+
* do not display msg box if error
161161
*/
162162
NULL, /* window handle */
163163
NULL, /* action to perform: open */
164164
(LPCWSTR)commandw.ucs2(), /* file to execute */
165-
(LPCWSTR)argsw.ucs2(), /* argument list */
165+
(LPCWSTR)argsw.ucs2(), /* argument list */
166166
NULL, /* use current working dir */
167167
SW_HIDE, /* minimize on start-up */
168168
0, /* application instance handle */
@@ -180,7 +180,7 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
180180
}
181181
else if (sInfo.hProcess) /* executable was launched, wait for it to finish */
182182
{
183-
WaitForSingleObject(sInfo.hProcess,INFINITE);
183+
WaitForSingleObject(sInfo.hProcess,INFINITE);
184184
/* get process exit code */
185185
DWORD exitCode;
186186
if (!GetExitCodeProcess(sInfo.hProcess,&exitCode))
@@ -269,7 +269,7 @@ void Portable::unsetenv(const char *variable)
269269
}
270270

271271
const char *Portable::getenv(const char *variable)
272-
{
272+
{
273273
#if defined(_WIN32) && !defined(__CYGWIN__)
274274
return ::getenv(variable);
275275
#else
@@ -303,7 +303,7 @@ portable_off_t Portable::fseek(FILE *f,portable_off_t offset, int whence)
303303
portable_off_t Portable::ftell(FILE *f)
304304
{
305305
#if defined(__MINGW32__)
306-
return ftello64(f);
306+
return ftello64(f);
307307
#elif defined(_WIN32) && !defined(__CYGWIN__)
308308
return _ftelli64(f);
309309
#else
@@ -448,12 +448,14 @@ int Portable::pclose(FILE *stream)
448448

449449
void Portable::sysTimerStart()
450450
{
451-
g_time.start();
451+
g_startTime = std::chrono::steady_clock::now();
452452
}
453453

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

459461
double Portable::getSysElapsedTime()
@@ -561,7 +563,7 @@ static const char * portable_memmem (const char *haystack, size_t haystack_len,
561563
const char *Portable::strnstr(const char *haystack, const char *needle, size_t haystack_len)
562564
{
563565
size_t needle_len = strnlen(needle, haystack_len);
564-
if (needle_len < haystack_len || !needle[needle_len])
566+
if (needle_len < haystack_len || !needle[needle_len])
565567
{
566568
const char *x = portable_memmem(haystack, haystack_len, needle, needle_len);
567569
if (x && !memchr(haystack, 0, x - haystack))

src/pyscanner.l

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,6 @@ STARTDOCSYMS "##"
11411141
// do something based on the type of the IDENTIFIER
11421142
if (yyextra->current->type.isEmpty())
11431143
{
1144-
//QListIterator<Entry> eli(*(yyextra->current_root->children()));
1145-
//Entry *child;
1146-
//for (eli.toFirst();(child=eli.yyextra->current());++eli)
11471144
for (const auto &child : yyextra->current_root->children())
11481145
{
11491146
if (child->name == QCString(yytext))

src/vhdljjparser.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,6 @@ void VHDLOutlineParser::addProto(const char *s1,const char *s2,const char *s3,
656656
*/
657657
void VHDLOutlineParser::mapLibPackage( Entry* root)
658658
{
659-
//QList<Entry> epp=libUse;
660-
//EntryListIterator eli(epp);
661-
//Entry *rt;
662-
//for (;(rt=eli.current());++eli)
663659
for (const auto &rt : p->libUse)
664660
{
665661
if (addLibUseClause(rt->name))

0 commit comments

Comments
 (0)