From fd11edd9d94fdd43ba541abc30b7868f79ffadb6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 13 Oct 2024 15:14:53 -0700 Subject: stats: Reduce some wasted space for disabled stats. Unfortunately for now we have the struct itsel,f but it can become mostly empty. --- src/core/stats.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/core/stats.h') 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. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // 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 *); -- cgit v1.2.3-70-g09d2