diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-10-13 15:14:53 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-10-13 15:14:53 -0700 |
| commit | fd11edd9d94fdd43ba541abc30b7868f79ffadb6 (patch) | |
| tree | 6df6fb5a4006caf2472632229c1ac700b6b6adda | |
| parent | 9996cfc15029a236c6ea907a35eafad6697f9a2e (diff) | |
| download | nng-fd11edd9d94fdd43ba541abc30b7868f79ffadb6.tar.gz nng-fd11edd9d94fdd43ba541abc30b7868f79ffadb6.tar.bz2 nng-fd11edd9d94fdd43ba541abc30b7868f79ffadb6.zip | |
stats: Reduce some wasted space for disabled stats.
Unfortunately for now we have the struct itsel,f but it can become
mostly empty.
| -rw-r--r-- | src/core/stats.h | 18 | ||||
| -rw-r--r-- | src/sp/transport/udp/udp.c | 108 |
2 files changed, 48 insertions, 78 deletions
diff --git a/src/core/stats.h b/src/core/stats.h index ff4db25c..5a2e2831 100644 --- a/src/core/stats.h +++ b/src/core/stats.h @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -12,6 +12,8 @@ #define CORE_STATS_H #include "core/defs.h" +#include "core/list.h" +#include "core/platform.h" // Statistics support. This is inspired in part by the Solaris // kernel stats framework, but we've simplified and tuned it for our use. @@ -60,6 +62,20 @@ struct nni_stat_info { bool si_alloc : 1; // stat string is allocated }; +#ifdef NNG_ENABLE_STATS +#define NNI_STAT_FIELDS(var, ...) \ + static const nni_stat_info var = { __VA_ARGS__ } +#else +#define NNI_STAT_FIELDS(var, ...) static const nni_stat_info var +#endif + +#define NNI_STAT_INFO(var, name, desc, type, unit) \ + NNI_STAT_FIELDS(var, .si_name = name, .si_desc = desc, \ + .si_type = type, .si_unit = unit) +#define NNI_STAT_ATOMIC(var, name, desc, type, unit) \ + NNI_STAT_FIELDS(var, .si_name = name, .si_desc = desc, \ + .si_type = type, .si_unit = unit, .si_atomic = true) + // nni_stat_add adds a statistic, but the operation is unlocked, and the // add is to an unregistered stats tree. void nni_stat_add(nni_stat_item *, nni_stat_item *); diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c index 0e3b4ae8..fd513386 100644 --- a/src/sp/transport/udp/udp.c +++ b/src/sp/transport/udp/udp.c @@ -1347,83 +1347,37 @@ udp_ep_init(udp_ep **epp, nng_url *url, nni_sock *sock, nni_dialer *dialer, nni_aio_init(&ep->resaio, udp_resolv_cb, ep); nni_aio_completions_init(&ep->complq); - static const nni_stat_info rcv_max_info = { - .si_name = "rcv_max", - .si_desc = "maximum receive size", - .si_type = NNG_STAT_LEVEL, - .si_unit = NNG_UNIT_BYTES, - .si_atomic = true, - }; - static const nni_stat_info rcv_reorder_info = { - .si_name = "rcv_reorder", - .si_desc = "messages received out of order", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info rcv_toobig_info = { - .si_name = "rcv_toobig", - .si_desc = "received messages rejected because too big", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info rcv_nomatch_info = { - .si_name = "rcv_nomatch", - .si_desc = "received messages without a matching connection", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info rcv_copy_info = { - .si_name = "rcv_copy", - .si_desc = "received messages copied (small)", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info rcv_nocopy_info = { - .si_name = "rcv_nocopy", - .si_desc = "received messages zero copy (large)", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info rcv_nobuf_info = { - .si_name = "rcv_nobuf", - .si_desc = "received messages dropped no buffer", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info snd_toobig_info = { - .si_name = "snd_toobig", - .si_desc = "sent messages rejected because too big", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info snd_nobuf_info = { - .si_name = "snd_nobuf", - .si_desc = "sent messages dropped no buffer", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_MESSAGES, - .si_atomic = true, - }; - static const nni_stat_info peer_inactive_info = { - .si_name = "peer_inactive", - .si_desc = "connections closed due to inactive peer", - .si_type = NNG_STAT_COUNTER, - .si_unit = NNG_UNIT_EVENTS, - .si_atomic = true, - }; - static const nni_stat_info copy_max_info = { - .si_name = "rcv_copy_max", - .si_desc = "threshold to copy instead of loan-up", - .si_type = NNG_STAT_LEVEL, - .si_unit = NNG_UNIT_BYTES, - .si_atomic = true, - }; + NNI_STAT_ATOMIC(rcv_max_info, "rcv_max", "maximum receive size", + NNG_STAT_LEVEL, NNG_UNIT_BYTES); + NNI_STAT_ATOMIC(copy_max_info, "copy_max", + "threshold to switch to loan-up", NNG_STAT_LEVEL, NNG_UNIT_BYTES); + NNI_STAT_ATOMIC(rcv_reorder_info, "rcv_reorder", + "messages received out of order", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(rcv_nomatch_info, "rcv_nomatch", + "messages without a matching connection", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(rcv_toobig_info, "rcv_toobig", + "received messages rejected because too big", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(rcv_copy_info, "rcv_copy", + "received messages copied (small)", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(rcv_nocopy_info, "rcv_nocopy", + "received messages zero copy (large)", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(rcv_nobuf_info, "rcv_nobuf", + "received messages dropped no buffer", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(snd_toobig_info, "snd_toobig", + "sent messages rejected because too big", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(snd_nobuf_info, "snd_nobuf", + "sent messages dropped no buffer", NNG_STAT_COUNTER, + NNG_UNIT_MESSAGES); + NNI_STAT_ATOMIC(peer_inactive_info, "peer_inactive", + "connections closed due to inactive peer", NNG_STAT_COUNTER, + NNG_UNIT_EVENTS); nni_stat_init(&ep->st_rcv_max, &rcv_max_info); nni_stat_init(&ep->st_copy_max, ©_max_info); |
