]> git.lyx.org Git - lyx.git/blobdiff - src/support/pmprof.h
Fix C++11 test
[lyx.git] / src / support / pmprof.h
index 7f74fe2646836254f27190f783c14cbd924118fc..fe5ab7a4fdde0466c3460e8acb7f021c96221bf6 100644 (file)
@@ -8,16 +8,6 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef PMPROF_H
-#define PMPROF_H
-
-#ifdef _WIN32
-#include <windows.h>
-#else
-#include <sys/time.h>
-#endif
-#include <iostream>
-
 /** How to use this trivial profiler:
  *
  * * at the beginning of the interesting block, just add:
 
  */
 
+#ifndef PMPROF_H
+#define PMPROF_H
+
 #ifdef _WIN32
+#include <windows.h>
+#else
+#include <sys/time.h>
+#endif
 
+#include <iomanip>
+#include <iostream>
+
+
+#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.
  */
@@ -122,13 +128,18 @@ int gettimeofday(struct timeval * tv, struct timezone * /*tz*/)
 class PMProfStat {
 public:
        PMProfStat(char const * name)
-         : name_(name), sec_(0), usec_(0), count_(0) {};
+         : 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) {