From fc9533d6c4bde795dc0e18f02f91f54ab92888a2 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Thu, 29 Oct 2015 00:55:58 +0100 Subject: stats: Add osmo_ name prefix to identifiers Since the the stat_item and stats functions and data types are meant to be exported, they get an osmo_ prefix. Sponsored-by: On-Waves ehf [hfreyther: Prepended the enum values too. This was requested by Jacob] --- include/osmocom/core/stat_item.h | 68 ++++++------- include/osmocom/core/stats.h | 60 +++++------ include/osmocom/gprs/gprs_ns.h | 2 +- include/osmocom/vty/misc.h | 2 +- include/osmocom/vty/stats.h | 2 +- src/gb/gprs_ns.c | 8 +- src/stat_item.c | 62 ++++++------ src/stats.c | 214 +++++++++++++++++++-------------------- src/vty/stats_vty.c | 80 +++++++-------- src/vty/utils.c | 16 +-- tests/stats/stats_test.c | 110 ++++++++++---------- 11 files changed, 312 insertions(+), 312 deletions(-) diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h index 0786a3ba..40474958 100644 --- a/include/osmocom/core/stat_item.h +++ b/include/osmocom/core/stat_item.h @@ -1,6 +1,6 @@ #pragma once -/*! \defgroup stat_item Statistics value item +/*! \defgroup osmo_stat_item Statistics value item * @{ */ @@ -10,28 +10,28 @@ #include -struct stat_item_desc; +struct osmo_stat_item_desc; #define STAT_ITEM_NOVALUE_ID 0 -struct stat_item_value { +struct osmo_stat_item_value { int32_t id; int32_t value; }; /*! \brief data we keep for each actual value */ -struct stat_item { - const struct stat_item_desc *desc; +struct osmo_stat_item { + const struct osmo_stat_item_desc *desc; /*! \brief the index of the freshest value */ int32_t last_value_index; /*! \brief offset to the freshest value in the value fifo */ int16_t last_offs; /*! \brief value fifo */ - struct stat_item_value values[0]; + struct osmo_stat_item_value values[0]; }; /*! \brief statistics value description */ -struct stat_item_desc { +struct osmo_stat_item_desc { const char *name; /*!< \brief name of the item */ const char *description;/*!< \brief description of the item */ const char *unit; /*!< \brief unit of a value */ @@ -40,7 +40,7 @@ struct stat_item_desc { }; /*! \brief description of a statistics value group */ -struct stat_item_group_desc { +struct osmo_stat_item_group_desc { /*! \brief The prefix to the name of all values in this group */ const char *group_name_prefix; /*! \brief The human-readable description of the group */ @@ -48,80 +48,80 @@ struct stat_item_group_desc { /*! \brief The number of values in this group */ const unsigned int num_items; /*! \brief Pointer to array of value names */ - const struct stat_item_desc *item_desc; + const struct osmo_stat_item_desc *item_desc; }; /*! \brief One instance of a counter group class */ -struct stat_item_group { +struct osmo_stat_item_group { /*! \brief Linked list of all value groups in the system */ struct llist_head list; /*! \brief Pointer to the counter group class */ - const struct stat_item_group_desc *desc; + const struct osmo_stat_item_group_desc *desc; /*! \brief The index of this value group within its class */ unsigned int idx; /*! \brief Actual counter structures below */ - struct stat_item *items[0]; + struct osmo_stat_item *items[0]; }; -struct stat_item_group *stat_item_group_alloc( +struct osmo_stat_item_group *osmo_stat_item_group_alloc( void *ctx, - const struct stat_item_group_desc *desc, + const struct osmo_stat_item_group_desc *desc, unsigned int idx); -void stat_item_group_free(struct stat_item_group *statg); +void osmo_stat_item_group_free(struct osmo_stat_item_group *statg); -void stat_item_set(struct stat_item *item, int32_t value); +void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value); -int stat_item_init(void *tall_ctx); +int osmo_stat_item_init(void *tall_ctx); -struct stat_item_group *stat_item_get_group_by_name_idx( +struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx( const char *name, const unsigned int idx); -const struct stat_item *stat_item_get_by_name( - const struct stat_item_group *statg, const char *name); +const struct osmo_stat_item *osmo_stat_item_get_by_name( + const struct osmo_stat_item_group *statg, const char *name); -/*! \brief Retrieve the next value from the stat_item object. +/*! \brief Retrieve the next value from the osmo_stat_item object. * If a new value has been set, it is returned. The idx is used to decide * which value to return. * On success, *idx is updated to refer to the next unread value. If * values have been missed due to FIFO overflow, *idx is incremented by * (1 + num_lost). - * This way, the stat_item object can be kept stateless from the reader's + * This way, the osmo_stat_item object can be kept stateless from the reader's * perspective and therefore be used by several backends simultaneously. * - * \param val the stat_item object + * \param val the osmo_stat_item object * \param idx identifies the next value to be read * \param value a pointer to store the value * \returns the increment of the index (0: no value has been read, * 1: one value has been taken, * (1+n): n values have been skipped, one has been taken) */ -int stat_item_get_next(const struct stat_item *item, int32_t *idx, int32_t *value); +int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value); /*! \brief Get the last (freshest) value */ -static int32_t stat_item_get_last(const struct stat_item *item); +static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item); /*! \brief Skip all values of the item and update idx accordingly */ -int stat_item_discard(const struct stat_item *item, int32_t *idx); +int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx); /*! \brief Skip all values of all items and update idx accordingly */ -int stat_item_discard_all(int32_t *idx); +int osmo_stat_item_discard_all(int32_t *idx); -typedef int (*stat_item_handler_t)( - struct stat_item_group *, struct stat_item *, void *); +typedef int (*osmo_stat_item_handler_t)( + struct osmo_stat_item_group *, struct osmo_stat_item *, void *); -typedef int (*stat_item_group_handler_t)(struct stat_item_group *, void *); +typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *); /*! \brief Iteate over all items * \param[in] handle_item Call-back function, aborts if rc < 0 * \param[in] data Private data handed through to \a handle_item */ -int stat_item_for_each_item(struct stat_item_group *statg, - stat_item_handler_t handle_item, void *data); +int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg, + osmo_stat_item_handler_t handle_item, void *data); -int stat_item_for_each_group(stat_item_group_handler_t handle_group, void *data); +int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data); -static inline int32_t stat_item_get_last(const struct stat_item *item) +static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item) { return item->values[item->last_offs].value; } diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h index 68c2e016..7b3d0211 100644 --- a/include/osmocom/core/stats.h +++ b/include/osmocom/core/stats.h @@ -23,18 +23,18 @@ #include struct msgb; -struct stat_item_group; -struct stat_item_desc; +struct osmo_stat_item_group; +struct osmo_stat_item_desc; struct rate_ctr_group; struct rate_ctr_desc; -enum stats_reporter_type { - STATS_REPORTER_STATSD, - STATS_REPORTER_LOG, +enum osmo_stats_reporter_type { + OSMO_STATS_REPORTER_STATSD, + OSMO_STATS_REPORTER_LOG, }; -struct stats_reporter { - enum stats_reporter_type type; +struct osmo_stats_reporter { + enum osmo_stats_reporter_type type; char *name; unsigned int have_net_config : 1; @@ -58,43 +58,43 @@ struct stats_reporter { int agg_enabled; struct llist_head list; - int (*open)(struct stats_reporter *srep); - int (*close)(struct stats_reporter *srep); - int (*send_counter)(struct stats_reporter *srep, + int (*open)(struct osmo_stats_reporter *srep); + int (*close)(struct osmo_stats_reporter *srep); + int (*send_counter)(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta); - int (*send_item)(struct stats_reporter *srep, - const struct stat_item_group *statg, - const struct stat_item_desc *desc, + int (*send_item)(struct osmo_stats_reporter *srep, + const struct osmo_stat_item_group *statg, + const struct osmo_stat_item_desc *desc, int32_t value); }; -struct stats_config { +struct osmo_stats_config { int interval; }; -extern struct stats_config *stats_config; +extern struct osmo_stats_config *osmo_stats_config; -void stats_init(void *ctx); -int stats_report(); +void osmo_stats_init(void *ctx); +int osmo_stats_report(); -int stats_set_interval(int interval); +int osmo_stats_set_interval(int interval); -struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type, +struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, const char *name); -void stats_reporter_free(struct stats_reporter *srep); +void osmo_stats_reporter_free(struct osmo_stats_reporter *srep); -struct stats_reporter *stats_reporter_create_statsd(const char *name); -struct stats_reporter *stats_reporter_create_log(const char *name); +struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name); +struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name); -struct stats_reporter *stats_reporter_find(enum stats_reporter_type type, +struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type, const char *name); -int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr); -int stats_reporter_set_remote_port(struct stats_reporter *srep, int port); -int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr); -int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu); -int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix); -int stats_reporter_enable(struct stats_reporter *srep); -int stats_reporter_disable(struct stats_reporter *srep); +int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr); +int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port); +int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr); +int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu); +int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix); +int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep); +int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep); diff --git a/include/osmocom/gprs/gprs_ns.h b/include/osmocom/gprs/gprs_ns.h index 42e0d884..7c3b23c1 100644 --- a/include/osmocom/gprs/gprs_ns.h +++ b/include/osmocom/gprs/gprs_ns.h @@ -126,7 +126,7 @@ struct gprs_nsvc { unsigned int nsvci_is_valid:1; struct rate_ctr_group *ctrg; - struct stat_item_group *statg; + struct osmo_stat_item_group *statg; /*! \brief which link-layer are we based on? */ enum gprs_ns_ll ll; diff --git a/include/osmocom/vty/misc.h b/include/osmocom/vty/misc.h index 99c2ee68..f3b46dbd 100644 --- a/include/osmocom/vty/misc.h +++ b/include/osmocom/vty/misc.h @@ -14,7 +14,7 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, struct rate_ctr_group *ctrg); void vty_out_stat_item_group(struct vty *vty, const char *prefix, - struct stat_item_group *statg); + struct osmo_stat_item_group *statg); void vty_out_statistics_full(struct vty *vty, const char *prefix); diff --git a/include/osmocom/vty/stats.h b/include/osmocom/vty/stats.h index eaf854e5..3851b4df 100644 --- a/include/osmocom/vty/stats.h +++ b/include/osmocom/vty/stats.h @@ -1,3 +1,3 @@ #pragma once -void stats_vty_add_cmds(); +void osmo_stats_vty_add_cmds(); diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index afc62497..5025d575 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -135,11 +135,11 @@ enum ns_stat { NS_STAT_ALIVE_DELAY, }; -static const struct stat_item_desc nsvc_stat_description[] = { +static const struct osmo_stat_item_desc nsvc_stat_description[] = { { "alive.delay", "ALIVE reponse time ", "ms", 16, 0 }, }; -static const struct stat_item_group_desc nsvc_statg_desc = { +static const struct osmo_stat_item_group_desc nsvc_statg_desc = { .group_name_prefix = "ns.nsvc", .group_description = "NSVC Peer Statistics", .num_items = ARRAY_SIZE(nsvc_stat_description), @@ -238,7 +238,7 @@ struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci) nsvc->timer.cb = gprs_ns_timer_cb; nsvc->timer.data = nsvc; nsvc->ctrg = rate_ctr_group_alloc(nsvc, &nsvc_ctrg_desc, nsvci); - nsvc->statg = stat_item_group_alloc(nsvc, &nsvc_statg_desc, nsvci); + nsvc->statg = osmo_stat_item_group_alloc(nsvc, &nsvc_statg_desc, nsvci); llist_add(&nsvc->list, &nsi->gprs_nsvcs); @@ -1306,7 +1306,7 @@ int gprs_ns_process_msg(struct gprs_ns_inst *nsi, struct msgb *msg, break; case NS_PDUT_ALIVE_ACK: if ((*nsvc)->timer_mode == NSVC_TIMER_TNS_ALIVE) - stat_item_set((*nsvc)->statg->items[NS_STAT_ALIVE_DELAY], + osmo_stat_item_set((*nsvc)->statg->items[NS_STAT_ALIVE_DELAY], nsvc_timer_elapsed_ms(*nsvc)); /* stop Tns-alive and start Tns-test */ nsvc_start_timer(*nsvc, NSVC_TIMER_TNS_TEST); diff --git a/src/stat_item.c b/src/stat_item.c index 525a94b9..0545ea0d 100644 --- a/src/stat_item.c +++ b/src/stat_item.c @@ -21,7 +21,7 @@ * */ -/*! \addtogroup stat_item +/*! \addtogroup osmo_stat_item * @{ */ @@ -37,7 +37,7 @@ #include #include -static LLIST_HEAD(stat_item_groups); +static LLIST_HEAD(osmo_stat_item_groups); static int32_t global_value_id = 0; static void *tall_stat_item_ctx; @@ -47,8 +47,8 @@ static void *tall_stat_item_ctx; * \param[in] desc Statistics item group description * \param[in] idx Index of new stat item group */ -struct stat_item_group *stat_item_group_alloc(void *ctx, - const struct stat_item_group_desc *desc, +struct osmo_stat_item_group *osmo_stat_item_group_alloc(void *ctx, + const struct osmo_stat_item_group_desc *desc, unsigned int idx) { unsigned int group_size; @@ -56,10 +56,10 @@ struct stat_item_group *stat_item_group_alloc(void *ctx, unsigned int item_idx; void *items; - struct stat_item_group *group; + struct osmo_stat_item_group *group; - group_size = sizeof(struct stat_item_group) + - desc->num_items * sizeof(struct stat_item *); + group_size = sizeof(struct osmo_stat_item_group) + + desc->num_items * sizeof(struct osmo_stat_item *); if (!ctx) ctx = tall_stat_item_ctx; @@ -74,8 +74,8 @@ struct stat_item_group *stat_item_group_alloc(void *ctx, /* Get combined size of all items */ for (item_idx = 0; item_idx < desc->num_items; item_idx++) { unsigned int size; - size = sizeof(struct stat_item) + - sizeof(struct stat_item_value) * + size = sizeof(struct osmo_stat_item) + + sizeof(struct osmo_stat_item_value) * desc->item_desc[item_idx].num_values; /* Align to pointer size */ size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1); @@ -94,7 +94,7 @@ struct stat_item_group *stat_item_group_alloc(void *ctx, /* Update item pointers */ for (item_idx = 0; item_idx < desc->num_items; item_idx++) { - struct stat_item *item = (struct stat_item *) + struct osmo_stat_item *item = (struct osmo_stat_item *) ((uint8_t *)items + (int)group->items[item_idx]); unsigned int i; @@ -109,19 +109,19 @@ struct stat_item_group *stat_item_group_alloc(void *ctx, } } - llist_add(&group->list, &stat_item_groups); + llist_add(&group->list, &osmo_stat_item_groups); return group; } /*! \brief Free the memory for the specified group of counters */ -void stat_item_group_free(struct stat_item_group *grp) +void osmo_stat_item_group_free(struct osmo_stat_item_group *grp) { llist_del(&grp->list); talloc_free(grp); } -void stat_item_set(struct stat_item *item, int32_t value) +void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value) { item->last_offs += 1; if (item->last_offs >= item->desc->num_values) @@ -135,11 +135,11 @@ void stat_item_set(struct stat_item *item, int32_t value) item->values[item->last_offs].id = global_value_id; } -int stat_item_get_next(const struct stat_item *item, int32_t *next_idx, +int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_idx, int32_t *value) { - const struct stat_item_value *next_value; - const struct stat_item_value *item_value = NULL; + const struct osmo_stat_item_value *next_value; + const struct osmo_stat_item_value *item_value = NULL; int idx_delta; int next_offs; @@ -173,7 +173,7 @@ int stat_item_get_next(const struct stat_item *item, int32_t *next_idx, } /*! \brief Skip all values of this item and update idx accordingly */ -int stat_item_discard(const struct stat_item *item, int32_t *idx) +int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx) { int discarded = item->values[item->last_offs].id + 1 - *idx; *idx = item->values[item->last_offs].id + 1; @@ -182,7 +182,7 @@ int stat_item_discard(const struct stat_item *item, int32_t *idx) } /*! \brief Skip all values of all items and update idx accordingly */ -int stat_item_discard_all(int32_t *idx) +int osmo_stat_item_discard_all(int32_t *idx) { int discarded = global_value_id + 1 - *idx; *idx = global_value_id + 1; @@ -191,7 +191,7 @@ int stat_item_discard_all(int32_t *idx) } /*! \brief Initialize the stat item module */ -int stat_item_init(void *tall_ctx) +int osmo_stat_item_init(void *tall_ctx) { tall_stat_item_ctx = tall_ctx; @@ -199,12 +199,12 @@ int stat_item_init(void *tall_ctx) } /*! \brief Search for item group based on group name and index */ -struct stat_item_group *stat_item_get_group_by_name_idx( +struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx( const char *name, const unsigned int idx) { - struct stat_item_group *statg; + struct osmo_stat_item_group *statg; - llist_for_each_entry(statg, &stat_item_groups, list) { + llist_for_each_entry(statg, &osmo_stat_item_groups, list) { if (!statg->desc) continue; @@ -216,11 +216,11 @@ struct stat_item_group *stat_item_get_group_by_name_idx( } /*! \brief Search for item group based on group name */ -const struct stat_item *stat_item_get_by_name( - const struct stat_item_group *statg, const char *name) +const struct osmo_stat_item *osmo_stat_item_get_by_name( + const struct osmo_stat_item_group *statg, const char *name) { int i; - const struct stat_item_desc *item_desc; + const struct osmo_stat_item_desc *item_desc; if (!statg->desc) return NULL; @@ -235,14 +235,14 @@ const struct stat_item *stat_item_get_by_name( return NULL; } -int stat_item_for_each_item(struct stat_item_group *statg, - stat_item_handler_t handle_item, void *data) +int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg, + osmo_stat_item_handler_t handle_item, void *data) { int rc = 0; int i; for (i = 0; i < statg->desc->num_items; i++) { - struct stat_item *item = statg->items[i]; + struct osmo_stat_item *item = statg->items[i]; rc = handle_item(statg, item, data); if (rc < 0) return rc; @@ -251,12 +251,12 @@ int stat_item_for_each_item(struct stat_item_group *statg, return rc; } -int stat_item_for_each_group(stat_item_group_handler_t handle_group, void *data) +int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data) { - struct stat_item_group *statg; + struct osmo_stat_item_group *statg; int rc = 0; - llist_for_each_entry(statg, &stat_item_groups, list) { + llist_for_each_entry(statg, &osmo_stat_item_groups, list) { rc = handle_group(statg, data); if (rc < 0) return rc; diff --git a/src/stats.c b/src/stats.c index 5027a621..155f8a2c 100644 --- a/src/stats.c +++ b/src/stats.c @@ -46,41 +46,41 @@ #define STATS_DEFAULT_INTERVAL 5 /* secs */ #define STATS_DEFAULT_STATSD_BUFLEN 256 -static LLIST_HEAD(stats_reporter_list); -static void *stats_ctx = NULL; +static LLIST_HEAD(osmo_stats_reporter_list); +static void *osmo_stats_ctx = NULL; static int is_initialised = 0; static int32_t current_stat_item_index = 0; -static struct stats_config s_stats_config = { +static struct osmo_stats_config s_stats_config = { .interval = STATS_DEFAULT_INTERVAL, }; -struct stats_config *stats_config = &s_stats_config; +struct osmo_stats_config *osmo_stats_config = &s_stats_config; -static struct osmo_timer_list stats_timer; +static struct osmo_timer_list osmo_stats_timer; -static int stats_reporter_statsd_open(struct stats_reporter *srep); -static int stats_reporter_statsd_close(struct stats_reporter *srep); -static int stats_reporter_statsd_send_counter(struct stats_reporter *srep, +static int osmo_stats_reporter_statsd_open(struct osmo_stats_reporter *srep); +static int osmo_stats_reporter_statsd_close(struct osmo_stats_reporter *srep); +static int osmo_stats_reporter_statsd_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta); -static int stats_reporter_statsd_send_item(struct stats_reporter *srep, - const struct stat_item_group *statg, - const struct stat_item_desc *desc, int value); +static int osmo_stats_reporter_statsd_send_item(struct osmo_stats_reporter *srep, + const struct osmo_stat_item_group *statg, + const struct osmo_stat_item_desc *desc, int value); -static int stats_reporter_log_send_counter(struct stats_reporter *srep, +static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta); -static int stats_reporter_log_send_item(struct stats_reporter *srep, - const struct stat_item_group *statg, - const struct stat_item_desc *desc, int value); +static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep, + const struct osmo_stat_item_group *statg, + const struct osmo_stat_item_desc *desc, int value); -static int stats_reporter_send(struct stats_reporter *srep, const char *data, +static int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data, int data_len); -static int stats_reporter_send_buffer(struct stats_reporter *srep); +static int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep); -static int update_srep_config(struct stats_reporter *srep) +static int update_srep_config(struct osmo_stats_reporter *srep) { int rc = 0; @@ -106,14 +106,14 @@ static int update_srep_config(struct stats_reporter *srep) return rc; } -static void stats_timer_cb(void *data) +static void osmo_stats_timer_cb(void *data) { - int interval = stats_config->interval; + int interval = osmo_stats_config->interval; - if (!llist_empty(&stats_reporter_list)) - stats_report(); + if (!llist_empty(&osmo_stats_reporter_list)) + osmo_stats_report(); - osmo_timer_schedule(&stats_timer, interval, 0); + osmo_timer_schedule(&osmo_stats_timer, interval, 0); } static int start_timer() @@ -121,49 +121,49 @@ static int start_timer() if (!is_initialised) return -ESRCH; - stats_timer.cb = stats_timer_cb; - osmo_timer_schedule(&stats_timer, 0, 1); + osmo_stats_timer.cb = osmo_stats_timer_cb; + osmo_timer_schedule(&osmo_stats_timer, 0, 1); return 0; } -struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type, +struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, const char *name) { - struct stats_reporter *srep; - srep = talloc_zero(stats_ctx, struct stats_reporter); + struct osmo_stats_reporter *srep; + srep = talloc_zero(osmo_stats_ctx, struct osmo_stats_reporter); OSMO_ASSERT(srep); srep->type = type; if (name) srep->name = talloc_strdup(srep, name); srep->fd = -1; - llist_add(&srep->list, &stats_reporter_list); + llist_add(&srep->list, &osmo_stats_reporter_list); return srep; } -void stats_reporter_free(struct stats_reporter *srep) +void osmo_stats_reporter_free(struct osmo_stats_reporter *srep) { - stats_reporter_disable(srep); + osmo_stats_reporter_disable(srep); llist_del(&srep->list); talloc_free(srep); } -void stats_init(void *ctx) +void osmo_stats_init(void *ctx) { - stats_ctx = ctx; - stat_item_discard_all(¤t_stat_item_index); + osmo_stats_ctx = ctx; + osmo_stat_item_discard_all(¤t_stat_item_index); is_initialised = 1; start_timer(); } -struct stats_reporter *stats_reporter_find(enum stats_reporter_type type, +struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type, const char *name) { - struct stats_reporter *srep; - llist_for_each_entry(srep, &stats_reporter_list, list) { + struct osmo_stats_reporter *srep; + llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { if (srep->type != type) continue; if (srep->name != name) { @@ -176,7 +176,7 @@ struct stats_reporter *stats_reporter_find(enum stats_reporter_type type, return NULL; } -int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr) +int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr) { int rc; struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr; @@ -201,7 +201,7 @@ int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr return update_srep_config(srep); } -int stats_reporter_set_remote_port(struct stats_reporter *srep, int port) +int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port) { struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr; @@ -214,7 +214,7 @@ int stats_reporter_set_remote_port(struct stats_reporter *srep, int port) return update_srep_config(srep); } -int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr) +int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr) { int rc; struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->bind_addr; @@ -241,7 +241,7 @@ int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr) return update_srep_config(srep); } -int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu) +int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu) { if (!srep->have_net_config) return -ENOTSUP; @@ -254,19 +254,19 @@ int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu) return update_srep_config(srep); } -int stats_set_interval(int interval) +int osmo_stats_set_interval(int interval) { if (interval <= 0) return -EINVAL; - stats_config->interval = interval; + osmo_stats_config->interval = interval; if (is_initialised) start_timer(); return 0; } -int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix) +int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix) { talloc_free(srep->name_prefix); srep->name_prefix = prefix ? talloc_strdup(srep, prefix) : NULL; @@ -274,21 +274,21 @@ int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *pref return update_srep_config(srep); } -int stats_reporter_enable(struct stats_reporter *srep) +int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep) { srep->enabled = 1; return update_srep_config(srep); } -int stats_reporter_disable(struct stats_reporter *srep) +int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep) { srep->enabled = 0; return update_srep_config(srep); } -static int stats_reporter_send(struct stats_reporter *srep, const char *data, +static int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data, int data_len) { int rc; @@ -302,14 +302,14 @@ static int stats_reporter_send(struct stats_reporter *srep, const char *data, return rc; } -static int stats_reporter_send_buffer(struct stats_reporter *srep) +static int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep) { int rc; if (!srep->buffer || msgb_length(srep->buffer) == 0) return 0; - rc = stats_reporter_send(srep, + rc = osmo_stats_reporter_send(srep, (const char *)msgb_data(srep->buffer), msgb_length(srep->buffer)); msgb_trim(srep->buffer, 0); @@ -319,20 +319,20 @@ static int stats_reporter_send_buffer(struct stats_reporter *srep) /*** log reporter ***/ -struct stats_reporter *stats_reporter_create_log(const char *name) +struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name) { - struct stats_reporter *srep; - srep = stats_reporter_alloc(STATS_REPORTER_LOG, name); + struct osmo_stats_reporter *srep; + srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_LOG, name); srep->have_net_config = 0; - srep->send_counter = stats_reporter_log_send_counter; - srep->send_item = stats_reporter_log_send_item; + srep->send_counter = osmo_stats_reporter_log_send_counter; + srep->send_item = osmo_stats_reporter_log_send_item; return srep; } -static int stats_reporter_log_send(struct stats_reporter *srep, +static int osmo_stats_reporter_log_send(struct osmo_stats_reporter *srep, const char *type, const char *name1, int index1, const char *name2, int value, const char *unit) @@ -347,56 +347,56 @@ static int stats_reporter_log_send(struct stats_reporter *srep, } -static int stats_reporter_log_send_counter(struct stats_reporter *srep, +static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta) { if (ctrg) - return stats_reporter_log_send(srep, "c", + return osmo_stats_reporter_log_send(srep, "c", ctrg->desc->group_name_prefix, ctrg->idx, desc->name, value, NULL); else - return stats_reporter_log_send(srep, "c", + return osmo_stats_reporter_log_send(srep, "c", NULL, -1, desc->name, value, NULL); } -static int stats_reporter_log_send_item(struct stats_reporter *srep, - const struct stat_item_group *statg, - const struct stat_item_desc *desc, int value) +static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep, + const struct osmo_stat_item_group *statg, + const struct osmo_stat_item_desc *desc, int value) { - return stats_reporter_log_send(srep, "i", + return osmo_stats_reporter_log_send(srep, "i", statg->desc->group_name_prefix, statg->idx, desc->name, value, desc->unit); } /*** statsd reporter ***/ -struct stats_reporter *stats_reporter_create_statsd(const char *name) +struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name) { - struct stats_reporter *srep; - srep = stats_reporter_alloc(STATS_REPORTER_STATSD, name); + struct osmo_stats_reporter *srep; + srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_STATSD, name); srep->have_net_config = 1; - srep->open = stats_reporter_statsd_open; - srep->close = stats_reporter_statsd_close; - srep->send_counter = stats_reporter_statsd_send_counter; - srep->send_item = stats_reporter_statsd_send_item; + srep->open = osmo_stats_reporter_statsd_open; + srep->close = osmo_stats_reporter_statsd_close; + srep->send_counter = osmo_stats_reporter_statsd_send_counter; + srep->send_item = osmo_stats_reporter_statsd_send_item; return srep; } -static int stats_reporter_statsd_open(struct stats_reporter *srep) +static int osmo_stats_reporter_statsd_open(struct osmo_stats_reporter *srep) { int sock; int rc; int buffer_size = STATS_DEFAULT_STATSD_BUFLEN; if (srep->fd != -1) - stats_reporter_statsd_close(srep); + osmo_stats_reporter_statsd_close(srep); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) @@ -426,13 +426,13 @@ failed: return rc; } -static int stats_reporter_statsd_close(struct stats_reporter *srep) +static int osmo_stats_reporter_statsd_close(struct osmo_stats_reporter *srep) { int rc; if (srep->fd == -1) return -EBADF; - stats_reporter_send_buffer(srep); + osmo_stats_reporter_send_buffer(srep); rc = close(srep->fd); srep->fd = -1; @@ -441,7 +441,7 @@ static int stats_reporter_statsd_close(struct stats_reporter *srep) return rc == -1 ? -errno : 0; } -static int stats_reporter_statsd_send(struct stats_reporter *srep, +static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep, const char *name1, int index1, const char *name2, int value, const char *unit) { @@ -482,7 +482,7 @@ static int stats_reporter_statsd_send(struct stats_reporter *srep, /* Restore original buffer (without trailing LF) */ msgb_trim(srep->buffer, old_len); /* Send it */ - rc = stats_reporter_send_buffer(srep); + rc = osmo_stats_reporter_send_buffer(srep); /* Try again */ buf = (char *)msgb_put(srep->buffer, 0); @@ -500,39 +500,39 @@ static int stats_reporter_statsd_send(struct stats_reporter *srep, msgb_trim(srep->buffer, msgb_length(srep->buffer) + nchars); if (!srep->agg_enabled) - rc = stats_reporter_send_buffer(srep); + rc = osmo_stats_reporter_send_buffer(srep); return rc; } -static int stats_reporter_statsd_send_counter(struct stats_reporter *srep, +static int osmo_stats_reporter_statsd_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta) { if (ctrg) - return stats_reporter_statsd_send(srep, + return osmo_stats_reporter_statsd_send(srep, ctrg->desc->group_name_prefix, ctrg->idx, desc->name, delta, "c"); else - return stats_reporter_statsd_send(srep, + return osmo_stats_reporter_statsd_send(srep, NULL, -1, desc->name, delta, "c"); } -static int stats_reporter_statsd_send_item(struct stats_reporter *srep, - const struct stat_item_group *statg, - const struct stat_item_desc *desc, int value) +static int osmo_stats_reporter_statsd_send_item(struct osmo_stats_reporter *srep, + const struct osmo_stat_item_group *statg, + const struct osmo_stat_item_desc *desc, int value) { - return stats_reporter_statsd_send(srep, + return osmo_stats_reporter_statsd_send(srep, statg->desc->group_name_prefix, statg->idx, desc->name, value, desc->unit); } /*** generic rate counter support ***/ -static int stats_reporter_send_counter(struct stats_reporter *srep, +static int osmo_stats_reporter_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta) @@ -547,18 +547,18 @@ static int rate_ctr_handler( struct rate_ctr_group *ctrg, struct rate_ctr *ctr, const struct rate_ctr_desc *desc, void *sctx_) { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; int rc; int64_t delta = rate_ctr_difference(ctr); if (delta == 0) return 0; - llist_for_each_entry(srep, &stats_reporter_list, list) { + llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { if (!srep->running) continue; - rc = stats_reporter_send_counter(srep, ctrg, desc, + rc = osmo_stats_reporter_send_counter(srep, ctrg, desc, ctr->current, delta); /* TODO: handle rc (log?, inc counter(!)?) or remove it */ @@ -576,9 +576,9 @@ static int rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_) /*** stat item support ***/ -static int stats_reporter_send_item(struct stats_reporter *srep, - const struct stat_item_group *statg, - const struct stat_item_desc *desc, +static int osmo_stats_reporter_send_item(struct osmo_stats_reporter *srep, + const struct osmo_stat_item_group *statg, + const struct osmo_stat_item_desc *desc, int32_t value) { if (!srep->send_item) @@ -587,20 +587,20 @@ static int stats_reporter_send_item(struct stats_reporter *srep, return srep->send_item(srep, statg, desc, value); } -static int stat_item_handler( - struct stat_item_group *statg, struct stat_item *item, void *sctx_) +static int osmo_stat_item_handler( + struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_) { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; int rc; int32_t idx = current_stat_item_index; int32_t value; - while (stat_item_get_next(item, &idx, &value) > 0) { - llist_for_each_entry(srep, &stats_reporter_list, list) { + while (osmo_stat_item_get_next(item, &idx, &value) > 0) { + llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { if (!srep->running) continue; - rc = stats_reporter_send_item(srep, statg, + rc = osmo_stats_reporter_send_item(srep, statg, item->desc, value); } } @@ -608,10 +608,10 @@ static int stat_item_handler( return 0; } -static int stat_item_group_handler(struct stat_item_group *statg, void *sctx_) +static int osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_) { - stat_item_for_each_item(statg, stat_item_handler, sctx_); - stat_item_discard_all(¤t_stat_item_index); + osmo_stat_item_for_each_item(statg, osmo_stat_item_handler, sctx_); + osmo_stat_item_discard_all(¤t_stat_item_index); return 0; } @@ -620,7 +620,7 @@ static int stat_item_group_handler(struct stat_item_group *statg, void *sctx_) static int handle_counter(struct osmo_counter *counter, void *sctx_) { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; int rc; struct rate_ctr_desc desc = {0}; /* Fake a rate counter description */ @@ -632,11 +632,11 @@ static int handle_counter(struct osmo_counter *counter, void *sctx_) if (delta == 0) return 0; - llist_for_each_entry(srep, &stats_reporter_list, list) { + llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { if (!srep->running) continue; - rc = stats_reporter_send_counter(srep, NULL, &desc, + rc = osmo_stats_reporter_send_counter(srep, NULL, &desc, counter->value, delta); /* TODO: handle rc (log?, inc counter(!)?) */ @@ -650,21 +650,21 @@ static int handle_counter(struct osmo_counter *counter, void *sctx_) static void flush_all_reporters() { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - llist_for_each_entry(srep, &stats_reporter_list, list) { + llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { if (!srep->running) continue; - stats_reporter_send_buffer(srep); + osmo_stats_reporter_send_buffer(srep); } } -int stats_report() +int osmo_stats_report() { osmo_counters_for_each(handle_counter, NULL); rate_ctr_for_each_group(rate_ctr_group_handler, NULL); - stat_item_for_each_group(stat_item_group_handler, NULL); + osmo_stat_item_for_each_group(osmo_stat_item_group_handler, NULL); flush_all_reporters(); diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 839dc829..f072b1ba 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -45,7 +45,7 @@ struct cmd_node cfg_stats_node = { 1 }; -static struct stats_reporter *osmo_stats_vty2srep(struct vty *vty) +static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty) { if (vty->node == CFG_STATS_NODE) return vty->index; @@ -54,11 +54,11 @@ static struct stats_reporter *osmo_stats_vty2srep(struct vty *vty) } static int set_srep_parameter_str(struct vty *vty, - int (*fun)(struct stats_reporter *, const char *), + int (*fun)(struct osmo_stats_reporter *, const char *), const char *val, const char *param_name) { int rc; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); rc = fun(srep, val); @@ -72,12 +72,12 @@ static int set_srep_parameter_str(struct vty *vty, } static int set_srep_parameter_int(struct vty *vty, - int (*fun)(struct stats_reporter *, int), + int (*fun)(struct osmo_stats_reporter *, int), const char *val, const char *param_name) { int rc; int int_val; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); int_val = atoi(val); @@ -97,7 +97,7 @@ DEFUN(cfg_stats_reporter_local_ip, cfg_stats_reporter_local_ip_cmd, "Set the IP address to which we bind locally\n" "IP Address\n") { - return set_srep_parameter_str(vty, stats_reporter_set_local_addr, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, argv[0], "local address"); } @@ -106,7 +106,7 @@ DEFUN(cfg_no_stats_reporter_local_ip, cfg_no_stats_reporter_local_ip_cmd, NO_STR "Set the IP address to which we bind locally\n") { - return set_srep_parameter_str(vty, stats_reporter_set_local_addr, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, NULL, "local address"); } @@ -115,7 +115,7 @@ DEFUN(cfg_stats_reporter_remote_ip, cfg_stats_reporter_remote_ip_cmd, "Set the remote IP address to which we connect\n" "IP Address\n") { - return set_srep_parameter_str(vty, stats_reporter_set_remote_addr, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_remote_addr, argv[0], "remote address"); } @@ -124,7 +124,7 @@ DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, "Set the remote port to which we connect\n" "Remote port number\n") { - return set_srep_parameter_int(vty, stats_reporter_set_remote_port, + return set_srep_parameter_int(vty, osmo_stats_reporter_set_remote_port, argv[0], "remote port"); } @@ -133,7 +133,7 @@ DEFUN(cfg_stats_reporter_mtu, cfg_stats_reporter_mtu_cmd, "Set the maximum packet size\n" "Size in byte\n") { - return set_srep_parameter_int(vty, stats_reporter_set_mtu, + return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, argv[0], "mtu"); } @@ -141,7 +141,7 @@ DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd, "no mtu", NO_STR "Set the maximum packet size\n") { - return set_srep_parameter_int(vty, stats_reporter_set_mtu, + return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, 0, "mtu"); } @@ -150,7 +150,7 @@ DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, "Set the item name prefix\n" "The prefix string\n") { - return set_srep_parameter_str(vty, stats_reporter_set_name_prefix, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, argv[0], "prefix string"); } @@ -159,7 +159,7 @@ DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd, NO_STR "Set the item name prefix\n") { - return set_srep_parameter_str(vty, stats_reporter_set_name_prefix, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, "", "prefix string"); } @@ -168,10 +168,10 @@ DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd, "Enable the reporter\n") { int rc; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); - rc = stats_reporter_enable(srep); + rc = osmo_stats_reporter_enable(srep); if (rc < 0) { vty_out(vty, "%% Unable to enable the reporter: %s%s", strerror(-rc), VTY_NEWLINE); @@ -186,10 +186,10 @@ DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd, "Disable the reporter\n") { int rc; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); - rc = stats_reporter_disable(srep); + rc = osmo_stats_reporter_disable(srep); if (rc < 0) { vty_out(vty, "%% Unable to disable the reporter: %s%s", strerror(-rc), VTY_NEWLINE); @@ -203,17 +203,17 @@ DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, "stats reporter statsd", CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); if (!srep) { - srep = stats_reporter_create_statsd(NULL); + srep = osmo_stats_reporter_create_statsd(NULL); if (!srep) { vty_out(vty, "%% Unable to create statsd reporter%s", VTY_NEWLINE); return CMD_WARNING; } - /* TODO: if needed, add stats_add_reporter(srep); */ + /* TODO: if needed, add osmo_stats_add_reporter(srep); */ } vty->index = srep; @@ -229,7 +229,7 @@ DEFUN(cfg_stats_interval, cfg_stats_interval_cmd, { int rc; int interval = atoi(argv[0]); - rc = stats_set_interval(interval); + rc = osmo_stats_set_interval(interval); if (rc < 0) { vty_out(vty, "%% Unable to set interval: %s%s", strerror(-rc), VTY_NEWLINE); @@ -244,16 +244,16 @@ DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, "no stats reporter statsd", NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); if (!srep) { vty_out(vty, "%% No statsd logging active%s", VTY_NEWLINE); return CMD_WARNING; } - stats_reporter_free(srep); + osmo_stats_reporter_free(srep); return CMD_SUCCESS; } @@ -262,17 +262,17 @@ DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, "stats reporter log", CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); if (!srep) { - srep = stats_reporter_create_log(NULL); + srep = osmo_stats_reporter_create_log(NULL); if (!srep) { vty_out(vty, "%% Unable to create log reporter%s", VTY_NEWLINE); return CMD_WARNING; } - /* TODO: if needed, add stats_add_reporter(srep); */ + /* TODO: if needed, add osmo_stats_add_reporter(srep); */ } vty->index = srep; @@ -285,16 +285,16 @@ DEFUN(cfg_no_stats_reporter_log, cfg_no_stats_reporter_log_cmd, "no stats reporter log", NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); if (!srep) { vty_out(vty, "%% No log reporting active%s", VTY_NEWLINE); return CMD_WARNING; } - stats_reporter_free(srep); + osmo_stats_reporter_free(srep); return CMD_SUCCESS; } @@ -309,16 +309,16 @@ DEFUN(show_stats, return CMD_SUCCESS; } -static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *srep) +static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep) { if (srep == NULL) return 0; switch (srep->type) { - case STATS_REPORTER_STATSD: + case OSMO_STATS_REPORTER_STATSD: vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); break; - case STATS_REPORTER_LOG: + case OSMO_STATS_REPORTER_LOG: vty_out(vty, "stats reporter log%s", VTY_NEWLINE); break; } @@ -354,20 +354,20 @@ static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *s static int config_write_stats(struct vty *vty) { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; /* TODO: loop through all reporters */ - srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); config_write_stats_reporter(vty, srep); - srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); config_write_stats_reporter(vty, srep); - vty_out(vty, "stats interval %d%s", stats_config->interval, VTY_NEWLINE); + vty_out(vty, "stats interval %d%s", osmo_stats_config->interval, VTY_NEWLINE); return 1; } -void stats_vty_add_cmds() +void osmo_stats_vty_add_cmds() { install_element_ve(&show_stats_cmd); diff --git a/src/vty/utils.c b/src/vty/utils.c index 474a25ef..8df44ae1 100644 --- a/src/vty/utils.c +++ b/src/vty/utils.c @@ -80,15 +80,15 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, rate_ctr_for_each_counter(ctrg, rate_ctr_handler, &vctx); } -static int stat_item_handler( - struct stat_item_group *statg, struct stat_item *item, void *vctx_) +static int osmo_stat_item_handler( + struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *vctx_) { struct vty_out_context *vctx = vctx_; struct vty *vty = vctx->vty; vty_out(vty, " %s%s: %8" PRIi32 " %s%s", vctx->prefix, item->desc->description, - stat_item_get_last(item), + osmo_stat_item_get_last(item), item->desc->unit, VTY_NEWLINE); return 0; @@ -100,16 +100,16 @@ static int stat_item_handler( * \param[in] statg Stat item group to be printed */ void vty_out_stat_item_group(struct vty *vty, const char *prefix, - struct stat_item_group *statg) + struct osmo_stat_item_group *statg) { struct vty_out_context vctx = {vty, prefix}; vty_out(vty, "%s%s:%s", prefix, statg->desc->group_description, VTY_NEWLINE); - stat_item_for_each_item(statg, stat_item_handler, &vctx); + osmo_stat_item_for_each_item(statg, osmo_stat_item_handler, &vctx); } -static int stat_item_group_handler(struct stat_item_group *statg, void *vctx_) +static int osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *vctx_) { struct vty_out_context *vctx = vctx_; struct vty *vty = vctx->vty; @@ -122,7 +122,7 @@ static int stat_item_group_handler(struct stat_item_group *statg, void *vctx_) vty_out(vty, "%s%s:%s", vctx->prefix, statg->desc->group_description, VTY_NEWLINE); - stat_item_for_each_item(statg, stat_item_handler, vctx); + osmo_stat_item_for_each_item(statg, osmo_stat_item_handler, vctx); return 0; } @@ -163,7 +163,7 @@ void vty_out_statistics_full(struct vty *vty, const char *prefix) vty_out(vty, "%sUngrouped counters:%s", prefix, VTY_NEWLINE); osmo_counters_for_each(handle_counter, &vctx); rate_ctr_for_each_group(rate_ctr_group_handler, &vctx); - stat_item_for_each_group(stat_item_group_handler, &vctx); + osmo_stat_item_for_each_group(osmo_stat_item_group_handler, &vctx); } /*! \brief Generate a VTY command string from value_string */ diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c index 9da49a4f..f8c7dc00 100644 --- a/tests/stats/stats_test.c +++ b/tests/stats/stats_test.c @@ -33,23 +33,23 @@ static void stat_test(void) TEST_B_ITEM, }; - static const struct stat_item_desc item_description[] = { + static const struct osmo_stat_item_desc item_description[] = { { "item.a", "The A value", "ma", 4, -1 }, { "item.b", "The B value", "kb", 7, -1 }, }; - static const struct stat_item_group_desc statg_desc = { + static const struct osmo_stat_item_group_desc statg_desc = { .group_name_prefix = "test.one", .group_description = "Test number 1", .num_items = ARRAY_SIZE(item_description), .item_desc = item_description, }; - struct stat_item_group *statg = - stat_item_group_alloc(NULL, &statg_desc, 0); + struct osmo_stat_item_group *statg = + osmo_stat_item_group_alloc(NULL, &statg_desc, 0); - struct stat_item_group *sgrp2; - const struct stat_item *sitem1, *sitem2; + struct osmo_stat_item_group *sgrp2; + const struct osmo_stat_item *sitem1, *sitem2; int rc; int32_t value; int32_t rd_a = 0; @@ -58,146 +58,146 @@ static void stat_test(void) OSMO_ASSERT(statg != NULL); - sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); OSMO_ASSERT(sgrp2 == statg); - sgrp2 = stat_item_get_group_by_name_idx("test.one", 1); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 1); OSMO_ASSERT(sgrp2 == NULL); - sgrp2 = stat_item_get_group_by_name_idx("test.two", 0); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.two", 0); OSMO_ASSERT(sgrp2 == NULL); - sitem1 = stat_item_get_by_name(statg, "item.c"); + sitem1 = osmo_stat_item_get_by_name(statg, "item.c"); OSMO_ASSERT(sitem1 == NULL); - sitem1 = stat_item_get_by_name(statg, "item.a"); + sitem1 = osmo_stat_item_get_by_name(statg, "item.a"); OSMO_ASSERT(sitem1 != NULL); OSMO_ASSERT(sitem1 == statg->items[TEST_A_ITEM]); - sitem2 = stat_item_get_by_name(statg, "item.b"); + sitem2 = osmo_stat_item_get_by_name(statg, "item.b"); OSMO_ASSERT(sitem2 != NULL); OSMO_ASSERT(sitem2 != sitem1); OSMO_ASSERT(sitem2 == statg->items[TEST_B_ITEM]); - value = stat_item_get_last(statg->items[TEST_A_ITEM]); + value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]); OSMO_ASSERT(value == -1); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); - stat_item_set(statg->items[TEST_A_ITEM], 1); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 1); - value = stat_item_get_last(statg->items[TEST_A_ITEM]); + value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]); OSMO_ASSERT(value == 1); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); for (i = 2; i <= 32; i++) { - stat_item_set(statg->items[TEST_A_ITEM], i); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + osmo_stat_item_set(statg->items[TEST_A_ITEM], i); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } /* Keep 2 in FIFO */ - stat_item_set(statg->items[TEST_A_ITEM], 33); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + 33); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 33); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + 33); for (i = 34; i <= 64; i++) { - stat_item_set(statg->items[TEST_A_ITEM], i); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + osmo_stat_item_set(statg->items[TEST_A_ITEM], i); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i-1); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i-1); } - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 64); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + 64); /* Overrun FIFOs */ for (i = 65; i <= 96; i++) { - stat_item_set(statg->items[TEST_A_ITEM], i); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + osmo_stat_item_set(statg->items[TEST_A_ITEM], i); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); } - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 93); for (i = 94; i <= 96; i++) { - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); } - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + 90); for (i = 91; i <= 96; i++) { - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } /* Test Discard (single item) */ - stat_item_set(statg->items[TEST_A_ITEM], 97); - rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 97); + rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); OSMO_ASSERT(rc > 0); - rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); OSMO_ASSERT(rc == 0); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); - stat_item_set(statg->items[TEST_A_ITEM], 98); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 98); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 98); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); /* Test Discard (all items) */ - stat_item_set(statg->items[TEST_A_ITEM], 99); - stat_item_set(statg->items[TEST_A_ITEM], 100); - stat_item_set(statg->items[TEST_A_ITEM], 101); - stat_item_set(statg->items[TEST_B_ITEM], 99); - stat_item_set(statg->items[TEST_B_ITEM], 100); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 99); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 100); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 101); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 99); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 100); - rc = stat_item_discard_all(&rd_a); - rc = stat_item_discard_all(&rd_b); + rc = osmo_stat_item_discard_all(&rd_a); + rc = osmo_stat_item_discard_all(&rd_b); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc == 0); - stat_item_group_free(statg); + osmo_stat_item_group_free(statg); - sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); OSMO_ASSERT(sgrp2 == NULL); } @@ -206,7 +206,7 @@ int main(int argc, char **argv) static const struct log_info log_info = {}; log_init(&log_info, NULL); - stat_item_init(NULL); + osmo_stat_item_init(NULL); stat_test(); return 0; -- cgit v1.2.3