From: Willy Tarreau Date: Fri, 6 Nov 2026 15:17:00 +0000 (+0100) Subject: CLEANUP: debug/tree-wide: replace COUNT_IF(1, ...) with COUNT() X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=78bd79a8d0ed6d40968298a48cbfa727da31b3c6;p=haproxy.git CLEANUP: debug/tree-wide: replace COUNT_IF(1, ...) with COUNT() This patch replaces 28 occurrences of COUNT_IF(1, msg) with COUNT(msg). This makes the counters output more readable, the code as well, and even saves a few bytes (148) in the executable. --- diff --git a/include/haproxy/http.h b/include/haproxy/http.h index 2b2832fea..8ff8327bf 100644 --- a/include/haproxy/http.h +++ b/include/haproxy/http.h @@ -134,9 +134,9 @@ static inline void http_reset_hardening_check(struct http_hdng_chk *chk) int _ret = 0; \ if (unlikely((http_hdng_chk.rules | ~http_hdng_chk.found) & _flag)) { \ http_hdng_chk.found |= _flag; \ - (void)COUNT_IF(1, "hardening " #flag " condition met"); \ + COUNT("hardening " #flag " condition met"); \ if (http_hdng_chk.rules & _flag) { \ - (void)COUNT_IF(1, "hardening " #flag " enforced"); \ + COUNT("hardening " #flag " enforced"); \ http_hdng_chk.fixed |= _flag; \ _ret = 1; \ } \ diff --git a/src/ev_epoll.c b/src/ev_epoll.c index 5e205fe69..6183d449a 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -293,7 +293,7 @@ static void _do_poll(struct poller *p, int exp, int wake) * events for statistics purposes. */ if (e & (EPOLLRDHUP|EPOLLHUP|EPOLLERR)) - COUNT_IF(1, "epoll report of HUP/ERR on a stale fd reopened on another thread (harmless)"); + COUNT("epoll report of HUP/ERR on a stale fd reopened on another thread (harmless)"); } else { /* same thread but different generation, this smells bad, * maybe that could be caused by crossed takeovers with a @@ -303,16 +303,16 @@ static void _do_poll(struct poller *p, int exp, int wake) * once we've read all pending data. */ if (e & EPOLLERR) - COUNT_IF(1, "epoll report of ERR on a stale fd reopened on the same thread (suspicious)"); + COUNT("epoll report of ERR on a stale fd reopened on the same thread (suspicious)"); else if (e & (EPOLLRDHUP|EPOLLHUP)) - COUNT_IF(1, "epoll report of HUP on a stale fd reopened on the same thread (suspicious)"); + COUNT("epoll report of HUP on a stale fd reopened on the same thread (suspicious)"); else - COUNT_IF(1, "epoll report of a harmless event on a stale fd reopened on the same thread (suspicious)"); + COUNT("epoll report of a harmless event on a stale fd reopened on the same thread (suspicious)"); } } else if (ev_gen + 1 != fd_gen) { - COUNT_IF(1, "epoll report of event on a closed recycled fd (rare)"); + COUNT("epoll report of event on a closed recycled fd (rare)"); } else { - COUNT_IF(1, "epoll report of event on a just closed fd (harmless)"); + COUNT("epoll report of event on a just closed fd (harmless)"); } continue; } else if (fd_tgid(fd) != tgid) { diff --git a/src/mux_h1.c b/src/mux_h1.c index 3b6e479f6..032e1865d 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -3158,7 +3158,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, if (h1m->flags & H1_MF_CLEN) { if (count > h1m->curr_len) { - COUNT_IF(1, "more payload than announced (0-copy)"); + COUNT("more payload than announced (0-copy)"); TRACE_ERROR("more payload than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -3182,7 +3182,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, /* If is a new chunk, prepend the chunk size */ if (h1m->state == H1_MSG_CHUNK_CRLF || h1m->state == H1_MSG_CHUNK_SIZE) { if (h1m->curr_len) { - COUNT_IF(1, "chunk bigger than announced (0-copy)"); + COUNT("chunk bigger than announced (0-copy)"); TRACE_ERROR("chunk bigger than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -3211,7 +3211,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, /* It is the end of the message, add the last chunk with the extra CRLF */ if (eom) { if (h1m->curr_len) { - COUNT_IF(1, "chunk smaller than announced (0-copy)"); + COUNT("chunk smaller than announced (0-copy)"); TRACE_ERROR("chunk smaller than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -3236,7 +3236,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, /* Handle now case of CRLF at the end of a chun. */ if ((h1m->flags & H1_MF_CHNK) && h1m->state == H1_MSG_CHUNK_CRLF) { if (h1m->curr_len) { - COUNT_IF(1, "chunk bigger than announced"); + COUNT("chunk bigger than announced"); TRACE_ERROR("chunk bigger than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -3311,7 +3311,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, if (h1m->flags & H1_MF_CLEN) { if (vlen > h1m->curr_len) { - COUNT_IF(1, "more payload than announced"); + COUNT("more payload than announced"); TRACE_ERROR("more payload than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -3328,7 +3328,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, } if (last_data) { if (h1m->curr_len) { - COUNT_IF(1, "chunk smaller than announced"); + COUNT("chunk smaller than announced"); TRACE_ERROR("chunk smaller than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -3349,7 +3349,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, } else if (h1m->flags & H1_MF_CHNK) { if (h1m->curr_len) { - COUNT_IF(1, "chunk smaller than announced"); + COUNT("chunk smaller than announced"); TRACE_ERROR("chunk smaller than announced", H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto error; @@ -4863,7 +4863,7 @@ static void h1_detach(struct sedesc *sd) h1c->state = H1_CS_DRAINING; h1c->flags &= ~H1C_F_WANT_FASTFWD; h1c_report_term_evt(h1c, muxc_tevt_type_graceful_shut); - COUNT_IF(1, "Deferring H1S destroy to drain message"); + COUNT("Deferring H1S destroy to drain message"); TRACE_DEVEL("Deferring H1S destroy to drain message", H1_EV_STRM_END, h1s->h1c->conn, h1s); /* If we have a pending data, process it immediately or * subscribe for reads waiting for new data @@ -5539,7 +5539,7 @@ static int h1_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags) if ((uint64_t)total > h1m->curr_len) { h1s->flags |= H1S_F_PARSING_ERROR; se_fl_set(h1s->sd, SE_FL_ERROR); - COUNT_IF(1, "more payload than announced"); + COUNT("more payload than announced"); TRACE_ERROR("too much payload, more than announced", H1_EV_STRM_RECV|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); goto end; diff --git a/src/mux_quic.c b/src/mux_quic.c index 769b6eb68..484c6af78 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -2724,7 +2724,7 @@ static void qcs_destroy(struct qcs *qcs) * the connection flow control consistency */ if (!qcs_is_close_remote(qcs) && qcs->rx.offset_max > qcs->rx.offset) { - COUNT_IF(1, "QCS is released while not remotely closed. " + COUNT("QCS is released while not remotely closed. " "This may cause miscalculation in conn flow control."); qcc_account_for_conn_fctl(qcc, qcs->rx.offset_max - qcs->rx.offset); } diff --git a/src/quic_rx.c b/src/quic_rx.c index 5dff2f398..74e3f79a5 100644 --- a/src/quic_rx.c +++ b/src/quic_rx.c @@ -757,7 +757,7 @@ static int qc_handle_crypto_frm(struct quic_conn *qc, */ if (ncbmb_head(ncbuf) + data >= ncbmb_wrap(ncbuf)) { TRACE_ERROR("unsupported wrapping CRYPTO frames", QUIC_EV_CONN_PRSHPKT, qc); - COUNT_IF(1, "connection closed on unsupported wrapping CRYPTO content"); + COUNT("connection closed on unsupported wrapping CRYPTO content"); quic_set_connection_close(qc, quic_err_transport(QC_ERR_CRYPTO_BUFFER_EXCEEDED)); quic_free_ncbuf(ncbuf); goto err; diff --git a/src/sock.c b/src/sock.c index a5a6f6e2c..071a6fe30 100644 --- a/src/sock.c +++ b/src/sock.c @@ -1020,7 +1020,7 @@ int sock_conn_check(struct connection *conn) * - https://www.spinics.net/lists/netdev/msg876470.html */ if (unlikely((fdtab[fd].state & (FD_POLL_HUP|FD_POLL_ERR)) == FD_POLL_HUP)) { - COUNT_IF(1, "Removing FD_POLL_HUP if no FD_POLL_ERR to let connect() decide"); + COUNT("Removing FD_POLL_HUP if no FD_POLL_ERR to let connect() decide"); fdtab[fd].state &= ~FD_POLL_HUP; } diff --git a/src/stream.c b/src/stream.c index efa83e1f1..87817c2a1 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2049,7 +2049,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) sc_abort(scf); sc_shutdown(scf); if (!(req->analysers) && !(res->analysers)) { - COUNT_IF(1, "Report a client abort (no analysers)"); + COUNT("Report a client abort (no analysers)"); if (s->be_tgcounters) _HA_ATOMIC_INC(&s->be_tgcounters->cli_aborts); if (sess->fe_tgcounters) @@ -2075,7 +2075,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->failed_resp); if (!(req->analysers) && !(res->analysers)) { - COUNT_IF(1, "Report a client abort (no analysers)"); + COUNT("Report a client abort (no analysers)"); if (s->be_tgcounters) _HA_ATOMIC_INC(&s->be_tgcounters->srv_aborts); if (sess->fe_tgcounters) @@ -2396,7 +2396,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->cli_aborts); s->flags |= SF_ERR_CLICL; - COUNT_IF(1, "Report unhandled client error"); + COUNT("Report unhandled client error"); } else if (req->flags & CF_READ_TIMEOUT) { if (s->be_tgcounters) @@ -2408,7 +2408,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->cli_aborts); s->flags |= SF_ERR_CLITO; - COUNT_IF(1, "Report unhandled client timeout (RD)"); + COUNT("Report unhandled client timeout (RD)"); } else { if (s->be_tgcounters) @@ -2420,7 +2420,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->srv_aborts); s->flags |= SF_ERR_SRVTO; - COUNT_IF(1, "Report unhandled server timeout (WR)"); + COUNT("Report unhandled server timeout (WR)"); } sess_set_term_flags(s); @@ -2452,7 +2452,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->srv_aborts); s->flags |= SF_ERR_SRVCL; - COUNT_IF(1, "Report unhandled server error"); + COUNT("Report unhandled server error"); } else if (res->flags & CF_READ_TIMEOUT) { if (s->be_tgcounters) @@ -2464,7 +2464,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->srv_aborts); s->flags |= SF_ERR_SRVTO; - COUNT_IF(1, "Report unhandled server timeout (RD)"); + COUNT("Report unhandled server timeout (RD)"); } else { if (s->be_tgcounters) @@ -2476,7 +2476,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) if (s->sv_tgcounters) _HA_ATOMIC_INC(&s->sv_tgcounters->cli_aborts); s->flags |= SF_ERR_CLITO; - COUNT_IF(1, "Report unhandled client timeout (WR)"); + COUNT("Report unhandled client timeout (WR)"); } sess_set_term_flags(s); }