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 /src/core/stats.h | |
| 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.
Diffstat (limited to 'src/core/stats.h')
| -rw-r--r-- | src/core/stats.h | 18 |
1 files changed, 17 insertions, 1 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 *); |
