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>
* 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)