lavu/timer.h: factor out timer report
authorClément Bœsch <cboesch@gopro.com>
Sat, 2 Sep 2017 17:17:45 +0000 (19:17 +0200)
committerClément Bœsch <u@pkh.me>
Fri, 8 Sep 2017 16:51:05 +0000 (18:51 +0200)
This commit is meant to reduce the diff in the following one.

libavutil/timer.h

index ed3b047..da0761b 100644 (file)
 #   define FF_TIMER_UNITS "UNITS"
 #endif
 
-#ifdef AV_READ_TIME
-#define START_TIMER                             \
-    uint64_t tend;                              \
-    uint64_t tstart = AV_READ_TIME();           \
-
-#define STOP_TIMER(id)                                                    \
-    tend = AV_READ_TIME();                                                \
+#define TIMER_REPORT(id, tdiff)                                           \
     {                                                                     \
         static uint64_t tsum   = 0;                                       \
         static int tcount      = 0;                                       \
         static int tskip_count = 0;                                       \
         static int thistogram[32] = {0};                                  \
-        thistogram[av_log2(tend - tstart)]++;                             \
-        if (tcount < 2                        ||                          \
-            tend - tstart < 8 * tsum / tcount ||                          \
-            tend - tstart < 2000) {                                       \
-            tsum+= tend - tstart;                                         \
+        thistogram[av_log2(tdiff)]++;                                     \
+        if (tcount < 2                ||                                  \
+            (tdiff) < 8 * tsum / tcount ||                                \
+            (tdiff) < 2000) {                                             \
+            tsum += (tdiff);                                              \
             tcount++;                                                     \
         } else                                                            \
             tskip_count++;                                                \
             av_log(NULL, AV_LOG_ERROR, "\n");                             \
         }                                                                 \
     }
+
+#ifdef AV_READ_TIME
+#define START_TIMER                             \
+    uint64_t tend;                              \
+    uint64_t tstart = AV_READ_TIME();           \
+
+#define STOP_TIMER(id)                                                    \
+    tend = AV_READ_TIME();                                                \
+    TIMER_REPORT(id, tend - tstart)
 #else
 #define START_TIMER
 #define STOP_TIMER(id) { }