From d142c7f421290ae4e42239746a1eecbc8fd04dbf Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 14 Apr 2026 09:07:49 +0200 Subject: [PATCH] BUILD: traces: add USE_TRACE allowing to disable traces This reduces the total code size by 6-10% and speeds up the build a bit. It can be further reduced by disabling the trace decoding code inside certain subsystems like muxes. But at least like this it will help users on small systems to reduce the footprint when not needed by explicitly passing USE_TRACE=0 (they remain enabled by default). --- Makefile | 6 +++++- include/haproxy/trace.h | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 22c4321d1..0ab2e39eb 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ # USE_CLOSEFROM : enable use of closefrom() on *bsd, solaris. Automatic. # USE_PRCTL : enable use of prctl(). Automatic. # USE_PROCCTL : enable use of procctl(). Automatic. +# USE_TRACE : enable trace subsystem. Always on. # USE_ZLIB : enable zlib library support and disable SLZ # USE_SLZ : enable slz library instead of zlib (default=enabled) # USE_CPU_AFFINITY : enable pinning processes to CPU on Linux. Automatic. @@ -343,7 +344,7 @@ use_opts = USE_EPOLL USE_KQUEUE USE_NETFILTER USE_POLL \ USE_TPROXY USE_LINUX_TPROXY USE_LINUX_CAP \ USE_LINUX_SPLICE USE_LIBCRYPT USE_CRYPT_H USE_ENGINE \ USE_GETADDRINFO USE_OPENSSL USE_OPENSSL_WOLFSSL USE_OPENSSL_AWSLC \ - USE_ECH \ + USE_ECH USE_TRACE \ USE_SSL USE_LUA USE_ACCEPT4 USE_CLOSEFROM USE_ZLIB USE_SLZ \ USE_CPU_AFFINITY USE_TFO USE_NS USE_DL USE_RT USE_LIBATOMIC \ USE_MATH USE_DEVICEATLAS USE_51DEGREES \ @@ -366,6 +367,9 @@ $(warn_unknown_options) # on the make command line. USE_POLL = default +# traces are always enabled +USE_TRACE = default + # SLZ is always supported unless explicitly disabled by passing USE_SLZ="" # or disabled by enabling ZLIB using USE_ZLIB=1 ifeq ($(USE_ZLIB:0=),) diff --git a/include/haproxy/trace.h b/include/haproxy/trace.h index 56c58f109..626609a37 100644 --- a/include/haproxy/trace.h +++ b/include/haproxy/trace.h @@ -34,6 +34,8 @@ #define _TRC_LOC(f,l) __TRC_LOC(f, ":", l) #define __TRC_LOC(f,c,l) f c #l +#if defined(USE_TRACE) + /* truncate a macro arg list to exactly 5 args and replace missing ones with NULL. * The first one (a0) is always ignored. */ @@ -139,8 +141,23 @@ &trace_no_cb, ist2(_msg, _msg_len)); \ } \ } while (0) +#else +# define TRACE_ENABLED(level, mask, args...) 0 +# define TRACE(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_ERROR(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_USER(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_DATA(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_PROTO(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_STATE(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_DEVEL(msg, mask, args...) do { /* do nothing */ } while(0) +# define TRACE_ENTER(mask, args...) do { /* do nothing */ } while(0) +# define TRACE_LEAVE(mask, args...) do { /* do nothing */ } while(0) +# define TRACE_POINT(mask, args...) do { /* do nothing */ } while(0) +# define TRACE_PRINTF(level, args...) do { /* do nothing */ } while(0) +# define TRACE_PRINTF_LOC(level, args...) do { /* do nothing */ } while(0) +#endif -#if defined(DEBUG_DEV) || defined(DEBUG_FULL) +#if defined (USE_TRACE) && (defined(DEBUG_DEV) || defined(DEBUG_FULL)) # define DBG_TRACE(msg, mask, args...) TRACE(msg, mask, ##args) # define DBG_TRACE_ERROR(msg, mask, args...) TRACE_ERROR(msg, mask, ##args) # define DBG_TRACE_USER(msg, mask, args...) TRACE_USER(msg, mask, ##args)