]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: traces: add USE_TRACE allowing to disable traces
authorWilly Tarreau <w@1wt.eu>
Tue, 14 Apr 2026 07:07:49 +0000 (09:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 20 May 2026 09:46:43 +0000 (11:46 +0200)
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
include/haproxy/trace.h

index 22c4321d1d2f3e14325052cf87fb76d324908f6f..0ab2e39eba4b425cbb5126979ed5b05bb6676afd 100644 (file)
--- 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=),)
index 56c58f1093457060896a253b9edb4b8a9234d3e6..626609a377a3012bc5cd6606a128ec4657740800 100644 (file)
@@ -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.
  */
                               &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)