logging: use G_UNLIKELY in BT_LOG_ON macros
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 22 May 2022 01:53:00 +0000 (21:53 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 15 Jun 2022 18:15:50 +0000 (14:15 -0400)
Use G_UNLIKELY to hint the compiler (and the processor) that logging is
likely not going to be enabled.  We care about performance in the
logging disabled case more than in the logging enabled case.

I see a small but consistent speedup.  Not scientific (sample size of
2), but before it looks like:

    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.98s user 0.05s system 99% cpu 4.025 total
    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.96s user 0.04s system 99% cpu 4.000 total

And after:

    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.81s user 0.04s system 99% cpu 3.848 total
    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.77s user 0.04s system 100% cpu 3.806 total

This is with babeltrace configured with:

    --enable-python-bindings --enable-python-plugins --disable-man-pages 'CFLAGS=-gdwarf-5 -g3 -O2' 'CXXFLAGS=-gdwarf-5 -g3 -O2' --prefix=/tmp/babeltrace 'CC=ccache clang' 'CXX=ccache clang++'

Change-Id: I3b11d1023f4dfad9c88ffa24e98a07afccb8cc61
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8106
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/logging/log.h

index 25136ab7d99ce67114bf94e6834a9d9aabce686c..41370963d68c9638c382702298588b6c367b26a8 100644 (file)
@@ -644,9 +644,9 @@ bt_log_spec;
  * See BT_LOG_OUTPUT_LEVEL for details.
  */
 #define BT_LOG_ON_CUR_LVL(lvl, cur_lvl) \
-               (BT_LOG_ENABLED((lvl)) && (lvl) >= (cur_lvl))
+               G_UNLIKELY(BT_LOG_ENABLED((lvl)) && (lvl) >= (cur_lvl))
 #define BT_LOG_ON(lvl) \
-               (BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL)
+               G_UNLIKELY(BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL)
 #define BT_LOG_ON_TRACE     BT_LOG_ON(BT_LOG_TRACE)
 #define BT_LOG_ON_DEBUG     BT_LOG_ON(BT_LOG_DEBUG)
 #define BT_LOG_ON_INFO      BT_LOG_ON(BT_LOG_INFO)
This page took 0.026131 seconds and 4 git commands to generate.