aboutsummaryrefslogtreecommitdiff
path: root/src/core/stats.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-11 21:29:54 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-11 23:51:13 -0800
commit66ff33813a8cd9d4cba96280bb613762fb0c2ce2 (patch)
tree4d9230b87715ebb1ff876894cd805ee4da42eccb /src/core/stats.h
parent53f20bbc4a2bd0d333e0307640883a778de31e2b (diff)
downloadnng-66ff33813a8cd9d4cba96280bb613762fb0c2ce2.tar.gz
nng-66ff33813a8cd9d4cba96280bb613762fb0c2ce2.tar.bz2
nng-66ff33813a8cd9d4cba96280bb613762fb0c2ce2.zip
fixes #1323 stats framework is *way* to heavy
This should reduce the amount of copying, and the overall size used by pipes and other objects quite a bit. (On my system, the sizeof nni_pipe shrank by 400 bytes, for example.)
Diffstat (limited to 'src/core/stats.h')
-rw-r--r--src/core/stats.h73
1 files changed, 27 insertions, 46 deletions
diff --git a/src/core/stats.h b/src/core/stats.h
index 0375979e..950df78f 100644
--- a/src/core/stats.h
+++ b/src/core/stats.h
@@ -24,6 +24,7 @@
// acquire the lock on the stat first though.
typedef struct nni_stat_item nni_stat_item;
+typedef struct nni_stat_info nni_stat_info;
typedef void (*nni_stat_update)(nni_stat_item *);
typedef enum nng_stat_type_enum nni_stat_type;
@@ -35,21 +36,26 @@ typedef enum nng_unit_enum nni_stat_unit;
// avoid having to spend dereference costs or (worse) to have to include
// extra conditionals on hot code paths.
struct nni_stat_item {
-#ifdef NNG_ENABLE_STATS
- nni_list_node si_node; // list node, framework use only
- nni_list si_children; // children, framework use only
- const char * si_name; // name of statistic
- const char * si_desc; // description of statistic (English)
- nni_mtx * si_lock; // lock for accessing, can be NULL
- nni_stat_type si_type; // type of stat, e.g. NNG_STAT_LEVEL
- nni_stat_unit si_unit; // units, e.g. NNG_UNIT_MILLIS
- nni_stat_update si_update; // update function (can be NULL)
- const char * si_string; // string value (NULL for numerics)
- uint64_t si_number; // numeric value
- nni_atomic_u64 si_atomic; // atomic value
-#else
- char si_disabled; // place holder, cannot be empty in C
-#endif
+ nni_list_node si_node; // list node, framework use only
+ nni_list si_children; // children, framework use only
+ const nni_stat_info *si_info; // statistic description
+ union {
+ uint64_t sv_number;
+ nni_atomic_u64 sv_atomic;
+ char * sv_string;
+ bool sv_bool;
+ int sv_id;
+ } si_value;
+};
+
+struct nni_stat_info {
+ const char * si_name; // name of statistic
+ const char * si_desc; // description of statistic (English)
+ nni_stat_type si_type; // statistic type, e.g. NNG_STAT_LEVEL
+ nni_stat_unit si_unit; // statistic unit, e.g. NNG_UNIT_MILLIS
+ nni_stat_update si_update; // update function (can be NULL)
+ bool si_atomic : 1; // stat is atomic
+ bool si_alloc : 1; // stat string is allocated
};
// nni_stat_add adds a statistic, but the operation is unlocked, and the
@@ -64,37 +70,12 @@ void nni_stat_register(nni_stat_item *);
void nni_stat_unregister(nni_stat_item *);
void nni_stat_set_value(nni_stat_item *, uint64_t);
-void nni_stat_set_lock(nni_stat_item *, nni_mtx *);
-
-#ifdef NNG_ENABLE_STATS
-void nni_stat_init(nni_stat_item *, const char *, const char *);
-void nni_stat_init_scope(nni_stat_item *, const char *, const char *);
-void nni_stat_init_string(
- nni_stat_item *, const char *, const char *, const char *);
-void nni_stat_init_id(nni_stat_item *, const char *, const char *, uint64_t);
-void nni_stat_init_bool(nni_stat_item *, const char *, const char *, bool);
-void nni_stat_init_atomic(nni_stat_item *, const char *, const char *);
-void nni_stat_inc_atomic(nni_stat_item *, uint64_t);
-void nni_stat_dec_atomic(nni_stat_item *, uint64_t);
-void nni_stat_set_type(nni_stat_item *, int);
-void nni_stat_set_unit(nni_stat_item *, int);
-#else
-// We override initialization so that we can avoid compiling static strings
-// into the binary. Presumably if stats are disabled, we are trying to save
-// space for constrained environments. We do evaluate an unused arg to
-// prevent the compiler from bitching about unused values.
-#define nni_stat_init(a, b, c) ((void) (a))
-#define nni_stat_init_scope(a, b, c) ((void) (a))
-#define nni_stat_init_atomic(a, b, c) ((void) (a))
-#define nni_stat_init_id(a, b, c, d) ((void) (a))
-#define nni_stat_init_bool(a, b, c, d) ((void) (a))
-#define nni_stat_init_string(a, b, c, d) ((void) (a))
-#define nni_stat_set_unit(a, b) ((void) (a))
-#define nni_stat_set_type(a, b) ((void) (a))
-#define nni_stat_inc_atomic(stat, inc)
-#define nni_stat_dec_atomic(stat, inc)
-#endif
-
+void nni_stat_set_id(nni_stat_item *, int);
+void nni_stat_set_bool(nni_stat_item *, bool);
+void nni_stat_set_string(nni_stat_item *, const char *);
+void nni_stat_init(nni_stat_item *, const nni_stat_info *);
+void nni_stat_inc(nni_stat_item *, uint64_t);
+void nni_stat_dec(nni_stat_item *, uint64_t);
int nni_stat_sys_init(void);
void nni_stat_sys_fini(void);