From: Simon Marchi Date: Sun, 22 May 2022 01:53:00 +0000 (-0400) Subject: logging: use G_UNLIKELY in BT_LOG_ON macros X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=088b0bbe10be6143d390eff198c459cc03333650 logging: use G_UNLIKELY in BT_LOG_ON macros 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/8106 Tested-by: jenkins Reviewed-by: Philippe Proulx --- diff --git a/src/logging/log.h b/src/logging/log.h index 25136ab7..41370963 100644 --- a/src/logging/log.h +++ b/src/logging/log.h @@ -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)