From: Jean-Marc Lasgouttes Date: Tue, 30 Apr 2013 14:43:29 +0000 (+0200) Subject: Small changes to Poor man's profiler X-Git-Tag: 2.1.0beta1~321 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fb0827f8bbc17fc5775122312ad946b6f60ed276;p=lyx.git Small changes to Poor man's profiler * report results in milliseconds instead of microseconds * report total time spent in block, additionally to mean time * cause compilation error with --enable-stdlib-debug --- diff --git a/src/support/pmprof.h b/src/support/pmprof.h index 7f74fe2646..d00eabc015 100644 --- a/src/support/pmprof.h +++ b/src/support/pmprof.h @@ -8,16 +8,6 @@ * Full author contact details are available in file CREDITS. */ -#ifndef PMPROF_H -#define PMPROF_H - -#ifdef _WIN32 -#include -#else -#include -#endif -#include - /** How to use this trivial profiler: * * * at the beginning of the interesting block, just add: @@ -96,8 +86,24 @@ */ +#ifndef PMPROF_H +#define PMPROF_H + #ifdef _WIN32 +#include +#else +#include +#endif +#include +#include + + +#if defined(__GNUG__) && defined(_GLIBCXX_DEBUG) +#error Profiling is not usable when run-time debugging is in effect +#endif + +#ifdef _WIN32 /* This function does not really returns the "time of day", * but it will suffice to evaluate elapsed times. */ @@ -125,10 +131,15 @@ public: : name_(name), sec_(0), usec_(0), count_(0) {}; ~PMProfStat() { - if (count_>0) - std::cerr << "##### " << name_ << ": " - << 1.0 * (sec_ * 1000000 + usec_)/ count_ - << "usec, count=" << count_ << std::endl; + if (count_>0) { + double total = 0.001 * (sec_ * 1000000 + usec_); + std::cerr << std::fixed << std::setprecision(2) + << "#pmprof# " << name_ << ": " + << total / count_ + << "msec, count=" << count_ + << ", total=" << total << "msec" + << std::endl; + } } void add(const long long s, const long long u) {