Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gdamore/udp stats tests #1891

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,18 @@ NNG_DECL nng_listener nng_pipe_listener(nng_pipe);
// low order 16 bits will be set. This is provided in native byte order,
// which makes it more convenient than using the NNG_OPT_LOCADDR option.
#define NNG_OPT_TCP_BOUND_PORT "tcp-bound-port"

// UDP options.

// UDP alias for convenience uses the same value
#define NNG_OPT_UDP_BOUND_PORT NNG_OPT_TCP_BOUND_PORT

// UDP short message size. Messages smaller than (or equal to) this
// will be copied, instead of loan up. This can allow for a faster
// pass up as we can allocate smaller message buffers instead of having
// to replace a full message buffer.
#define NNG_OPT_UDP_COPY_MAX "udp:copy-max"

// IPC options. These will largely vary depending on the platform,
// as POSIX systems have very different options than Windows.

Expand Down
63 changes: 63 additions & 0 deletions src/core/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <stdio.h>
#include <string.h>

#include "core/defs.h"
#include "core/nng_impl.h"
#include "nng/nng.h"

typedef struct nng_stat nni_stat;

Expand Down Expand Up @@ -377,72 +379,123 @@ nng_stat_parent(nng_stat *stat)
nng_stat *
nng_stat_next(nng_stat *stat)
{
#if NNG_ENABLE_STATS
if (stat->s_parent == NULL) {
return (NULL); // Root node, no siblings.
}
return (nni_list_next(&stat->s_parent->s_children, stat));
#else
NNI_ARG_UNUSED(stat);
return (NULL);
#endif
}

nng_stat *
nng_stat_child(nng_stat *stat)
{
#if NNG_ENABLE_STATS
return (nni_list_first(&stat->s_children));
#else
NNI_ARG_UNUSED(stat);
return (NULL);
#endif
}

const char *
nng_stat_name(nni_stat *stat)
{
#if NNG_ENABLE_STATS
return (stat->s_info->si_name);
#else
NNI_ARG_UNUSED(stat);
return (NULL);
#endif
}

uint64_t
nng_stat_value(nni_stat *stat)
{
#if NNG_ENABLE_STATS
return (stat->s_val.sv_value);
#else
NNI_ARG_UNUSED(stat);
return (0);
#endif
}

bool
nng_stat_bool(nni_stat *stat)
{
#if NNG_ENABLE_STATS
return (stat->s_val.sv_bool);
#else
NNI_ARG_UNUSED(stat);
return (false);
#endif
}

const char *
nng_stat_string(nng_stat *stat)
{
#if NNG_ENABLE_STATS
if (stat->s_info->si_type != NNG_STAT_STRING) {
return ("");
}
return (stat->s_val.sv_string);
#else
NNI_ARG_UNUSED(stat);
return ("");
#endif
}

uint64_t
nng_stat_timestamp(nng_stat *stat)
{
#if NNG_ENABLE_STATS
return ((uint64_t) stat->s_timestamp);
#else
NNI_ARG_UNUSED(stat);
return (0);
#endif
}

int
nng_stat_type(nng_stat *stat)
{
#if NNG_ENABLE_STATS
return (stat->s_info->si_type);
#else
NNI_ARG_UNUSED(stat);
return (NNG_STAT_ID);
#endif
}

int
nng_stat_unit(nng_stat *stat)
{
#if NNG_ENABLE_STATS
return (stat->s_info->si_unit);
#else
NNI_ARG_UNUSED(stat);
return (NNG_UNIT_NONE);
#endif
}

const char *
nng_stat_desc(nng_stat *stat)
{
#if NNG_ENABLE_STATS
return (stat->s_info->si_desc);
#else
NNI_ARG_UNUSED(stat);
return ("");
#endif
}

nng_stat *
nng_stat_find(nng_stat *stat, const char *name)
{
#if NNG_ENABLE_STATS
nng_stat *child;
if (stat == NULL) {
return (NULL);
Expand All @@ -456,12 +509,17 @@ nng_stat_find(nng_stat *stat, const char *name)
return (result);
}
}
#else
NNI_ARG_UNUSED(stat);
NNI_ARG_UNUSED(name);
#endif
return (NULL);
}

nng_stat *
nng_stat_find_scope(nng_stat *stat, const char *name, int id)
{
#if NNG_ENABLE_STATS
nng_stat *child;
if (stat == NULL || stat->s_info->si_type != NNG_STAT_SCOPE) {
return (NULL);
Expand All @@ -477,6 +535,11 @@ nng_stat_find_scope(nng_stat *stat, const char *name, int id)
return (result);
}
}
#else
NNI_ARG_UNUSED(stat);
NNI_ARG_UNUSED(name);
NNI_ARG_UNUSED(id);
#endif
return (NULL);
}

Expand Down
8 changes: 5 additions & 3 deletions src/core/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ 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 nni_stat_info *si_info; // statistic description
union {
uint64_t sv_number;
nni_atomic_u64 sv_atomic;
char * sv_string;
char *sv_string;
bool sv_bool;
int sv_id;
} si_u;
#endif
};

struct nni_stat_info {
const char * si_name; // name of statistic
const char * si_desc; // description of statistic (English)
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)
Expand Down
Loading
Loading