Skip to content

Commit

Permalink
stats: Reduce some wasted space for disabled stats.
Browse files Browse the repository at this point in the history
Unfortunately for now we have the struct itsel,f but it can become
mostly empty.
  • Loading branch information
gdamore committed Oct 13, 2024
1 parent 9996cfc commit fd11edd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 78 deletions.
18 changes: 17 additions & 1 deletion src/core/stats.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -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.
Expand Down Expand Up @@ -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 *);
Expand Down
108 changes: 31 additions & 77 deletions src/sp/transport/udp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &copy_max_info);
Expand Down

0 comments on commit fd11edd

Please sign in to comment.