diff --git a/include/haproxy/counters-t.h b/include/haproxy/counters-t.h index fde3930dd..8c21d9b70 100644 --- a/include/haproxy/counters-t.h +++ b/include/haproxy/counters-t.h @@ -185,6 +185,27 @@ struct be_counters { } p; /* protocol-specific stats */ }; +/* extra counters that are registered at boot by various modules */ +enum counters_type { + COUNTERS_FE = 0, + COUNTERS_BE, + COUNTERS_SV, + COUNTERS_LI, + COUNTERS_RSLV, + + COUNTERS_OFF_END /* must always be last */ +}; + +struct extra_counters { + char *data; /* heap containing counters allocated in a linear fashion */ + size_t size; /* size of allocated data */ + enum counters_type type; /* type of object containing the counters */ +}; + + +#define EXTRA_COUNTERS(name) \ + struct extra_counters *name + #endif /* _HAPROXY_COUNTERS_T_H */ /* diff --git a/include/haproxy/counters.h b/include/haproxy/counters.h index a6a68623d..a9e6c30ea 100644 --- a/include/haproxy/counters.h +++ b/include/haproxy/counters.h @@ -27,6 +27,8 @@ #include #include +extern THREAD_LOCAL void *trash_counters; + int counters_fe_shared_prepare(struct fe_counters_shared *counters, const struct guid_node *guid, char **errmsg); int counters_be_shared_prepare(struct be_counters_shared *counters, const struct guid_node *guid, char **errmsg); @@ -101,4 +103,50 @@ void counters_be_shared_drop(struct be_counters_shared *counters); __ret; \ }) +/* Manipulation of extra_counters, for boot-time registrable modules */ +#define EXTRA_COUNTERS_GET(counters, mod) \ + (likely(counters) ? \ + ((void *)((counters)->data + (mod)->counters_off[(counters)->type])) : \ + (trash_counters)) + +#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label) \ + do { \ + typeof(*counters) _ctr; \ + _ctr = calloc(1, sizeof(*_ctr)); \ + if (!_ctr) \ + goto alloc_failed_label; \ + _ctr->type = (ctype); \ + *(counters) = _ctr; \ + } while (0) + +#define EXTRA_COUNTERS_ADD(mod, counters, new_counters, csize) \ + do { \ + typeof(counters) _ctr = (counters); \ + (mod)->counters_off[_ctr->type] = _ctr->size; \ + _ctr->size += (csize); \ + } while (0) + +#define EXTRA_COUNTERS_ALLOC(counters, alloc_failed_label) \ + do { \ + typeof(counters) _ctr = (counters); \ + _ctr->data = malloc((_ctr)->size); \ + if (!_ctr->data) \ + goto alloc_failed_label; \ + } while (0) + +#define EXTRA_COUNTERS_INIT(counters, mod, init_counters, init_counters_size) \ + do { \ + typeof(counters) _ctr = (counters); \ + memcpy(_ctr->data + mod->counters_off[_ctr->type], \ + (init_counters), (init_counters_size)); \ + } while (0) + +#define EXTRA_COUNTERS_FREE(counters) \ + do { \ + if (counters) { \ + free((counters)->data); \ + free(counters); \ + } \ + } while (0) + #endif /* _HAPROXY_COUNTERS_H */ diff --git a/include/haproxy/quic_conn.h b/include/haproxy/quic_conn.h index 5eb9f92c3..92e6c1c74 100644 --- a/include/haproxy/quic_conn.h +++ b/include/haproxy/quic_conn.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include diff --git a/include/haproxy/stats-t.h b/include/haproxy/stats-t.h index 1ca0621da..8c857a23b 100644 --- a/include/haproxy/stats-t.h +++ b/include/haproxy/stats-t.h @@ -25,6 +25,7 @@ #include #include #include +#include /* Flags for applet.ctx.stats.flags */ #define STAT_F_FMT_HTML 0x00000001 /* dump the stats in HTML format */ @@ -515,16 +516,6 @@ struct field { } u; }; -enum counters_type { - COUNTERS_FE = 0, - COUNTERS_BE, - COUNTERS_SV, - COUNTERS_LI, - COUNTERS_RSLV, - - COUNTERS_OFF_END -}; - /* Entity used to generate statistics on an HAProxy component */ struct stats_module { struct list list; @@ -543,12 +534,6 @@ struct stats_module { char clearable; /* reset on a clear counters */ }; -struct extra_counters { - char *data; /* heap containing counters allocated in a linear fashion */ - size_t size; /* size of allocated data */ - enum counters_type type; /* type of object containing the counters */ -}; - /* stats_domain is used in a flag as a 1 byte field */ enum stats_domain { STATS_DOMAIN_PROXY = 0, @@ -597,54 +582,4 @@ struct show_stat_ctx { enum stat_state state; /* phase of output production */ }; -extern THREAD_LOCAL void *trash_counters; - -#define EXTRA_COUNTERS(name) \ - struct extra_counters *name - -#define EXTRA_COUNTERS_GET(counters, mod) \ - (likely(counters) ? \ - ((void *)((counters)->data + (mod)->counters_off[(counters)->type])) : \ - (trash_counters)) - -#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label) \ - do { \ - typeof(*counters) _ctr; \ - _ctr = calloc(1, sizeof(*_ctr)); \ - if (!_ctr) \ - goto alloc_failed_label; \ - _ctr->type = (ctype); \ - *(counters) = _ctr; \ - } while (0) - -#define EXTRA_COUNTERS_ADD(mod, counters, new_counters, csize) \ - do { \ - typeof(counters) _ctr = (counters); \ - (mod)->counters_off[_ctr->type] = _ctr->size; \ - _ctr->size += (csize); \ - } while (0) - -#define EXTRA_COUNTERS_ALLOC(counters, alloc_failed_label) \ - do { \ - typeof(counters) _ctr = (counters); \ - _ctr->data = malloc((_ctr)->size); \ - if (!_ctr->data) \ - goto alloc_failed_label; \ - } while (0) - -#define EXTRA_COUNTERS_INIT(counters, mod, init_counters, init_counters_size) \ - do { \ - typeof(counters) _ctr = (counters); \ - memcpy(_ctr->data + mod->counters_off[_ctr->type], \ - (init_counters), (init_counters_size)); \ - } while (0) - -#define EXTRA_COUNTERS_FREE(counters) \ - do { \ - if (counters) { \ - free((counters)->data); \ - free(counters); \ - } \ - } while (0) - #endif /* _HAPROXY_STATS_T_H */ diff --git a/include/haproxy/stats.h b/include/haproxy/stats.h index ca77513ee..acebd27b8 100644 --- a/include/haproxy/stats.h +++ b/include/haproxy/stats.h @@ -24,6 +24,7 @@ #define _HAPROXY_STATS_H #include +#include #include #include #include