]> git.lyx.org Git - lyx.git/blobdiff - src/support/pmprof.h
Use more informative descriptions fro Springer layouts
[lyx.git] / src / support / pmprof.h
index 8aa269a6a8ce6f1012a6c4de85bfdd2cb785b4e4..8f91125f54dc5c5c1d7471aa9e0ea117fd730fa1 100644 (file)
@@ -28,6 +28,9 @@
  *      hit: 96%, 4.36usec, count=6849, total=29.89msec
  *     miss: 3%, 60.65usec, count=271, total=16.43msec
  *
+ * * if DISABLE_PMPROF is defined before including pmprof.h, the
+ *   profiler is replaced by empty macros. This is useful for quickly
+ *   checking the overhead.
  *
  * ==== ABOUT PROFILING SCOPE:
  *
 #ifndef PMPROF_H
 #define PMPROF_H
 
+#if defined(DISABLE_PMPROF)
+
+// Make pmprof an empty shell
+#define PROFILE_THIS_BLOCK(a)
+#define PROFILE_CACHE_MISS(a)
+
+#else
+
 #ifdef _WIN32
 #include <windows.h>
 #else
@@ -134,16 +145,27 @@ int gettimeofday(struct timeval * tv, struct timezone * /*tz*/)
 
 namespace {
 
+void dumpTime(long long value)
+{
+       std::cerr << std::fixed << std::setprecision(2);
+       if (value >= 1000000)
+               std::cerr << value / 1000000 << "sec";
+       else if (value >= 1000)
+               std::cerr << value / 1000 << "msec";
+       else
+               std::cerr << value << "usec";
+}
+
 void dump(long long sec, long long usec, unsigned long long count) {
        double const total = sec * 1000000 + usec;
-       std::cerr << std::fixed << std::setprecision(2)
-                         << total / count
-                         << "usec, count=" << count
-                         << ", total=" << total * 0.001 << "msec"
-                         << std::endl;
+       dumpTime(total / count);
+       std::cerr << ", count=" << count
+                         << ", total=";
+       dumpTime(total);
+       std::cerr << std::endl;
 }
 
-}
+} // namespace
 
 
 /* Helper class for gathering data. Instantiate this as a static
@@ -228,5 +250,6 @@ private:
 #define PROFILE_CACHE_MISS(a) \
        PMPI_##a.hit = false;
 
+#endif // !defined(DISABLE_PMPROF)
 
 #endif