From: Willy Tarreau Date: Wed, 1 Jul 2026 13:40:44 +0000 (+0200) Subject: CLEANUP: trace/tree-wide: drop trace decoding/definition when USE_TRACE=0 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/%7B@url%7D?a=commitdiff_plain;h=75163e93a8c0d48df53dd10f1807bf59d7047785;p=haproxy.git CLEANUP: trace/tree-wide: drop trace decoding/definition when USE_TRACE=0 The various trace sources always have the same pattern: - trace events - trace source - trace decoding function Dropping these when USE_TRACE=0 definitely makes sense. There are two modes of definition here: - those designed after mux_h2 which interleave #define and the entry definition in the event. These ones cannot be removed without a significant code move to split the #define and usage apart. Instead here we mark the struct __maybe_unused, so that the compiler will just not implement it. - those designed like stream.c where defines are separated. Here we can simply enclose the events definition inside the USE_TRACE guard For most of these the static declaration of the trace function was moved after the events so that the #if defined(USE_TRACE) could be placed between the two. Nothing else was changed. This saves another 51 kB of object code when USE_TRACE=0. --- diff --git a/src/acme.c b/src/acme.c index 6e6758766..6d07eb744 100644 --- a/src/acme.c +++ b/src/acme.c @@ -52,6 +52,7 @@ static EVP_PKEY *tmp_pkey = NULL; static X509 *tmp_x509 = NULL; +#if defined(USE_TRACE) static void acme_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where, const struct ist func, @@ -159,6 +160,7 @@ static void acme_trace(enum trace_level level, uint64_t mask, const struct trace } } } +#endif struct eb_root acme_tasks = EB_ROOT_UNIQUE; __decl_thread(HA_RWLOCK_T acme_lock); diff --git a/src/applet.c b/src/applet.c index a6e6a4e78..63f2654c0 100644 --- a/src/applet.c +++ b/src/applet.c @@ -31,16 +31,10 @@ unsigned int nb_applets = 0; DECLARE_TYPED_POOL(pool_head_appctx, "appctx", struct appctx); -/* trace source and events */ -static void applet_trace(enum trace_level level, uint64_t mask, - const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); - /* The event representation is split like this : * app - applet */ -static const struct trace_event applet_trace_events[] = { +static const struct trace_event applet_trace_events[] __maybe_unused = { #define APPLET_EV_NEW (1ULL << 0) { .mask = APPLET_EV_NEW, .name = "app_new", .desc = "new appctx" }, #define APPLET_EV_FREE (1ULL << 1) @@ -64,6 +58,14 @@ static const struct trace_event applet_trace_events[] = { {} }; +#if defined(USE_TRACE) + +/* trace source and events */ +static void applet_trace(enum trace_level level, uint64_t mask, + const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); + static const struct name_desc applet_trace_lockon_args[4] = { /* arg1 */ { /* already used by the applet */ }, /* arg2 */ { }, @@ -216,6 +218,8 @@ static void applet_trace(enum trace_level level, uint64_t mask, const struct tra } } +#endif /* USE_TRACE */ + /* Tries to allocate a new appctx and initialize all of its fields. The appctx * is returned on success, NULL on failure. The appctx must be released using * appctx_free(). is assigned as the applet, but it can be NULL. diff --git a/src/check.c b/src/check.c index 8d0effa4c..3cd9a835d 100644 --- a/src/check.c +++ b/src/check.c @@ -66,6 +66,11 @@ #include #include +/* Dummy frontend used to create all checks sessions. */ +struct proxy checks_fe; + +#if defined(USE_TRACE) + /* trace source and events */ static void check_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, @@ -139,11 +144,6 @@ struct trace_source trace_check = { #define TRACE_SOURCE &trace_check INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); - -/* Dummy frontend used to create all checks sessions. */ -struct proxy checks_fe; - - static inline void check_trace_buf(const struct buffer *buf, size_t ofs, size_t len) { size_t block1, block2; @@ -285,6 +285,7 @@ static void check_trace(enum trace_level level, uint64_t mask, } +#endif /* USE_TRACE */ /**************************************************************************/ /************************ Handle check results ****************************/ diff --git a/src/haterm.c b/src/haterm.c index f1b227214..5ee284852 100644 --- a/src/haterm.c +++ b/src/haterm.c @@ -83,23 +83,7 @@ size_t master_pipesize = 0; static size_t hstream_add_ff_data(struct hstream *hs, struct sedesc *sd, unsigned long long len); static size_t hstream_add_htx_data(struct hstream *hs, struct htx *htx, unsigned long long len); -#define TRACE_SOURCE &trace_haterm -struct trace_source trace_haterm; -static void hterm_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); - -static const struct name_desc hterm_trace_logon_args[4] = { - /* arg1 */ { /* already used by the haterm stream */ }, - /* arg2 */ { - .name="haterm", - .desc="haterm server", - }, - /* arg3 */ { }, - /* arg4 */ { } -}; - -static const struct trace_event hterm_trace_events[] = { +static const struct trace_event hterm_trace_events[] __maybe_unused = { #define HS_EV_HSTRM_NEW (1ULL << 0) { .mask = HS_EV_HSTRM_NEW, .name = "hstrm_new", .desc = "new haterm stream" }, #define HS_EV_PROCESS_HSTRM (1ULL << 1) @@ -116,6 +100,24 @@ static const struct trace_event hterm_trace_events[] = { { .mask = HS_EV_HSTRM_ADD_DATA, .name = "hstrm_add_data", .desc = "add data to HTX haterm stream" }, }; +#if defined(USE_TRACE) + +#define TRACE_SOURCE &trace_haterm +struct trace_source trace_haterm; +static void hterm_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); + +static const struct name_desc hterm_trace_logon_args[4] = { + /* arg1 */ { /* already used by the haterm stream */ }, + /* arg2 */ { + .name="haterm", + .desc="haterm server", + }, + /* arg3 */ { }, + /* arg4 */ { } +}; + static const struct name_desc hterm_trace_decoding[] = { #define HATERM_VERB_CLEAN 1 { .name = "clean", .desc = "only user-friendly stuff, generally suitable for level \"user\"" }, @@ -150,6 +152,8 @@ static void hterm_trace(enum trace_level level, uint64_t mask, const struct trac } +#endif /* USE_TRACE */ + int hstream_buf_available(void *target) { struct hstream *hs = target; diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index f3a9b9d2c..3c8f0d2e1 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -148,12 +148,6 @@ struct fcgi_strm_params { /* Maximum amount of data we're OK with re-aligning for buffer optimizations */ #define MAX_DATA_REALIGN 1024 -/* trace source and events */ -static void fcgi_trace(enum trace_level level, uint64_t mask, - const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); - /* The event representation is split like this : * fconn - internal FCGI connection * fstrm - internal FCGI stream @@ -162,7 +156,7 @@ static void fcgi_trace(enum trace_level level, uint64_t mask, * tx - data transmission * rsp - response parsing */ -static const struct trace_event fcgi_trace_events[] = { +static const struct trace_event fcgi_trace_events[] __maybe_unused = { #define FCGI_EV_FCONN_NEW (1ULL << 0) { .mask = FCGI_EV_FCONN_NEW, .name = "fconn_new", .desc = "new FCGI connection" }, #define FCGI_EV_FCONN_RECV (1ULL << 1) @@ -248,6 +242,14 @@ static const struct trace_event fcgi_trace_events[] = { { } }; +#if defined(USE_TRACE) + +/* trace source and events */ +static void fcgi_trace(enum trace_level level, uint64_t mask, + const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); + static const struct name_desc fcgi_trace_lockon_args[4] = { /* arg1 */ { /* already used by the connection */ }, /* arg2 */ { .name="fstrm", .desc="FCGI stream" }, @@ -284,6 +286,8 @@ static struct trace_source trace_fcgi __read_mostly = { #define TRACE_SOURCE &trace_fcgi INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); +#endif /* USE_TRACE */ + /* FCGI connection and stream pools */ DECLARE_STATIC_TYPED_POOL(pool_head_fcgi_conn, "fcgi_conn", struct fcgi_conn); DECLARE_STATIC_TYPED_POOL(pool_head_fcgi_strm, "fcgi_strm", struct fcgi_strm); @@ -333,6 +337,8 @@ static forceinline struct stconn *fcgi_strm_sc(const struct fcgi_strm *fstrm) } +#if defined(USE_TRACE) + /* the FCGI traces always expect that arg1, if non-null, is of type connection * (from which we can derive fconn), that arg2, if non-null, is of type fstrm, * and that arg3, if non-null, is a htx for rx/tx headers. @@ -434,6 +440,8 @@ static void fcgi_trace(enum trace_level level, uint64_t mask, const struct trace } } +#endif /* USE_TRACE */ + /*****************************************************/ /* functions below are for dynamic buffer management */ /*****************************************************/ diff --git a/src/mux_h1.c b/src/mux_h1.c index 41aa3c984..264cddd28 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -99,15 +99,6 @@ static int accept_payload_with_any_method = 0; static int h1_be_glitches_threshold = 0; /* backend's max glitches: unlimited */ static int h1_fe_glitches_threshold = 0; /* frontend's max glitches: unlimited */ -/* trace source and events */ -static void h1_trace(enum trace_level level, uint64_t mask, - const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); - -static void h1_trace_fill_ctx(struct trace_ctx *ctx, const struct trace_source *src, - const void *a1, const void *a2, const void *a3, const void *a4); - /* The event representation is split like this : * h1c - internal H1 connection * h1s - internal H1 stream @@ -116,7 +107,7 @@ static void h1_trace_fill_ctx(struct trace_ctx *ctx, const struct trace_source * * tx - data transmission * */ -static const struct trace_event h1_trace_events[] = { +static const struct trace_event h1_trace_events[] __maybe_unused = { #define H1_EV_H1C_NEW (1ULL << 0) { .mask = H1_EV_H1C_NEW, .name = "h1c_new", .desc = "new H1 connection" }, #define H1_EV_H1C_RECV (1ULL << 1) @@ -181,6 +172,17 @@ static const struct trace_event h1_trace_events[] = { { } }; +#if defined(USE_TRACE) + +/* trace source and events */ +static void h1_trace(enum trace_level level, uint64_t mask, + const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); + +static void h1_trace_fill_ctx(struct trace_ctx *ctx, const struct trace_source *src, + const void *a1, const void *a2, const void *a3, const void *a4); + static const struct name_desc h1_trace_lockon_args[4] = { /* arg1 */ { /* already used by the connection */ }, /* arg2 */ { .name="h1s", .desc="H1 stream" }, @@ -217,6 +219,7 @@ static struct trace_source trace_h1 __read_mostly = { #define TRACE_SOURCE &trace_h1 INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); +#endif /* USE_TRACE */ /* h1 stats module */ enum { @@ -368,6 +371,8 @@ static forceinline struct stconn *h1s_sc(const struct h1s *h1s) return h1s->sd->sc; } +#if defined(USE_TRACE) + /* the H1 traces always expect that arg1, if non-null, is of type connection * (from which we can derive h1c), that arg2, if non-null, is of type h1s, and * that arg3, if non-null, is a htx for rx/tx headers. @@ -515,6 +520,8 @@ static void h1_trace_fill_ctx(struct trace_ctx *ctx, const struct trace_source * } } +#endif /* USE_TRACE */ + /* report one or more glitches on the connection. That is any unexpected event * that may occasionally happen but if repeated a bit too much, might indicate * a misbehaving or completely bogus peer. It normally returns zero, unless the diff --git a/src/mux_pt.c b/src/mux_pt.c index fe8897b40..7bfae0b0e 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -29,17 +29,17 @@ struct mux_pt_ctx { DECLARE_STATIC_TYPED_POOL(pool_head_pt_ctx, "mux_pt", struct mux_pt_ctx); -/* trace source and events */ -static void pt_trace(enum trace_level level, uint64_t mask, - const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); +/* returns the stconn associated to the stream */ +static forceinline struct stconn *pt_sc(const struct mux_pt_ctx *pt) +{ + return pt->sd->sc; +} /* The event representation is split like this : * pt_ctx - internal PT context * strm - application layer */ -static const struct trace_event pt_trace_events[] = { +static const struct trace_event pt_trace_events[] __maybe_unused = { #define PT_EV_CONN_NEW (1ULL << 0) { .mask = PT_EV_CONN_NEW, .name = "pt_conn_new", .desc = "new PT connection" }, #define PT_EV_CONN_WAKE (1ULL << 1) @@ -64,6 +64,13 @@ static const struct trace_event pt_trace_events[] = { {} }; +#if defined(USE_TRACE) + +/* trace source and events */ +static void pt_trace(enum trace_level level, uint64_t mask, + const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); static const struct name_desc pt_trace_decoding[] = { #define PT_VERB_CLEAN 1 @@ -93,12 +100,6 @@ static struct trace_source trace_pt __read_mostly = { #define TRACE_SOURCE &trace_pt INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); -/* returns the stconn associated to the stream */ -static forceinline struct stconn *pt_sc(const struct mux_pt_ctx *pt) -{ - return pt->sd->sc; -} - static inline void pt_trace_buf(const struct buffer *buf, size_t ofs, size_t len) { size_t block1, block2; @@ -200,6 +201,7 @@ static void pt_trace(enum trace_level level, uint64_t mask, const struct trace_s } } } +#endif static inline void mux_pt_report_term_evt(struct mux_pt_ctx *ctx, enum muxc_term_event_type type) { diff --git a/src/mux_spop.c b/src/mux_spop.c index 3a921ca4e..c8551b7ac 100644 --- a/src/mux_spop.c +++ b/src/mux_spop.c @@ -91,12 +91,6 @@ struct spop_frame_header { uint8_t type; /* frame type */ }; -/* trace source and events */ -static void spop_trace(enum trace_level level, uint64_t mask, - const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); - /* The event representation is split like this : * spop_conn - internal SPOP connection * spop_strm - internal SPOP stream @@ -104,7 +98,7 @@ static void spop_trace(enum trace_level level, uint64_t mask, * rx - data receipt * tx - data transmission */ -static const struct trace_event spop_trace_events[] = { +static const struct trace_event spop_trace_events[] __maybe_unused = { #define SPOP_EV_SPOP_CONN_NEW (1ULL << 0) { .mask = SPOP_EV_SPOP_CONN_NEW, .name = "spop_conn_new", .desc = "new SPOP connection" }, #define SPOP_EV_SPOP_CONN_RECV (1ULL << 1) @@ -173,6 +167,14 @@ static const struct trace_event spop_trace_events[] = { { } }; +#if defined(USE_TRACE) + +/* trace source and events */ +static void spop_trace(enum trace_level level, uint64_t mask, + const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); + static const struct name_desc spop_trace_lockon_args[4] = { /* arg1 */ { /* already used by the connection */ }, /* arg2 */ { .name="spop_strm", .desc="SPOP stream" }, @@ -209,6 +211,8 @@ static struct trace_source trace_spop __read_mostly = { #define TRACE_SOURCE &trace_spop INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); +#endif /* USE_TRACE */ + /* SPOP connection and stream pools */ DECLARE_STATIC_TYPED_POOL(pool_head_spop_conn, "spop_conn", struct spop_conn); DECLARE_STATIC_TYPED_POOL(pool_head_spop_strm, "spop_strm", struct spop_strm); @@ -304,6 +308,8 @@ static inline struct sedesc *spop_strm_opposite_sd(struct spop_strm *spop_strm) return se_opposite(spop_strm->sd); } +#if defined(USE_TRACE) + static inline void spop_trace_buf(const struct buffer *buf, size_t ofs, size_t len) { size_t block1, block2; @@ -445,6 +451,7 @@ static void spop_trace(enum trace_level level, uint64_t mask, const struct trace } } +#endif /* USE_TRACE */ /*****************************************************/ /* functions below are for dynamic buffer management */ diff --git a/src/peers.c b/src/peers.c index b8a6cae86..07b1097cc 100644 --- a/src/peers.c +++ b/src/peers.c @@ -267,18 +267,12 @@ static struct ebpt_node *dcache_tx_insert(struct dcache *dc, struct dcache_tx_entry *i); static inline void flush_dcache(struct peer *peer); -/* trace source and events */ -static void peers_trace(enum trace_level level, uint64_t mask, - const struct trace_source *src, - const struct ist where, const struct ist func, - const void *a1, const void *a2, const void *a3, const void *a4); - static const char *statuscode_str(int statuscode); static const char *peer_app_state_str(enum peer_app_state appstate); static const char *peer_learn_state_str(enum peer_learn_state learnstate); static const char *peer_applet_state_str(int state); -static const struct trace_event peers_trace_events[] = { +static const struct trace_event peers_trace_events[] __maybe_unused = { #define PEERS_EV_SESS_NEW (1ULL << 0) { .mask = PEERS_EV_SESS_NEW, .name = "sess_new", .desc = "create new peer session" }, #define PEERS_EV_SESS_END (1ULL << 1) @@ -328,6 +322,14 @@ static const struct trace_event peers_trace_events[] = { { } }; +#if defined(USE_TRACE) + +/* trace source and events */ +static void peers_trace(enum trace_level level, uint64_t mask, + const struct trace_source *src, + const struct ist where, const struct ist func, + const void *a1, const void *a2, const void *a3, const void *a4); + static const struct name_desc peers_trace_lockon_args[4] = { /* arg1 */ { /* already used by the appctx */ }, /* arg2 */ { .name="peer", .desc="Peer" }, @@ -455,6 +457,8 @@ static void peers_trace(enum trace_level level, uint64_t mask, return; } +#endif /* USE_TRACE */ + static const char *statuscode_str(int statuscode) { switch (statuscode) { @@ -511,7 +515,7 @@ static const char *peer_learn_state_str(enum peer_learn_state learnstate) } } -static const char *peer_applet_state_str(int state) +static inline const char *peer_applet_state_str(int state) { switch (state) { case PEER_SESS_ST_ACCEPT: return "ACCEPT"; diff --git a/src/qcm_trace.c b/src/qcm_trace.c index 4492ed4ea..fcb2017cb 100644 --- a/src/qcm_trace.c +++ b/src/qcm_trace.c @@ -10,6 +10,8 @@ #include #include +#if defined(USE_TRACE) + /* trace source and events */ static void qcm_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, @@ -133,6 +135,8 @@ static void qcm_trace_fill_ctx(struct trace_ctx *ctx, const struct trace_source /* register qcm traces */ INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); +#endif /* USE_TRACE*/ + static char *qcc_app_st_to_str(const enum qcc_app_st st) { switch (st) { diff --git a/src/quic_trace.c b/src/quic_trace.c index 98d120969..c0a7cfe4f 100644 --- a/src/quic_trace.c +++ b/src/quic_trace.c @@ -22,6 +22,8 @@ #include #include +#if defined(USE_TRACE) + static void quic_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where, const struct ist func, const void *a1, const void *a2, const void *a3, const void *a4); @@ -664,6 +666,8 @@ static void quic_trace(enum trace_level level, uint64_t mask, const struct trace } +#endif /* USE_TRACE */ + void quic_dump_qc_info(struct buffer *msg, const struct quic_conn *qc) { chunk_appendf(msg, " qc.wnd=%llu/%llu", (ullong)qc->path->in_flight, diff --git a/src/session.c b/src/session.c index 4c6bbf604..0f86898a9 100644 --- a/src/session.c +++ b/src/session.c @@ -34,7 +34,7 @@ DECLARE_TYPED_POOL(pool_head_sess_priv_conns, "sess_priv_conns", struct sess_pri int conn_complete_session(struct connection *conn); -static const struct trace_event sess_trace_events[] = { +static const struct trace_event sess_trace_events[] __maybe_unused = { #define SESS_EV_NEW (1ULL << 0) { .mask = SESS_EV_NEW, .name = "sess_new", .desc = "new session creation" }, #define SESS_EV_END (1ULL << 1) @@ -44,6 +44,8 @@ static const struct trace_event sess_trace_events[] = { { } }; +#if defined(USE_TRACE) + static const struct name_desc sess_trace_lockon_args[4] = { /* arg1 */ { /* already used by the session */ }, /* arg2 */ { }, @@ -63,6 +65,8 @@ static struct trace_source trace_sess __read_mostly = { #define TRACE_SOURCE &trace_sess INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); +#endif /* USE_TRACE */ + /* Create a a new session and assign it to frontend , listener
  • , * origin , set the current date and clear the stick counters pointers. * Returns the session upon success or NULL. The session may be released using diff --git a/src/stream.c b/src/stream.c index 10543f862..2f8dacd1c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -71,6 +71,8 @@ unsigned stream_epoch = 0; static struct list service_keywords = LIST_HEAD_INIT(service_keywords); +#if defined(USE_TRACE) + /* trace source and events */ static void strm_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, @@ -272,6 +274,7 @@ static void strm_trace(enum trace_level level, uint64_t mask, const struct trace htx_dump(&trace_buf, htx, full); } } +#endif /* Upgrade an existing stream for stream connector . Return < 0 on error. This * is only valid right after a TCP to H1 upgrade. The stream should be