This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
osmith gerrit-no-reply at lists.osmocom.orgosmith has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/23506 ) Change subject: stat_item: make next_id argument name consistent ...................................................................... stat_item: make next_id argument name consistent Let osmo_stat_item_get_next, osmo_stat_item_discard, osmo_stat_item_discard_all consistently refer to their next_id arg as such (and not idx or next_idx). It refers to an ID (item->values[i].id), not an index (item->values[i]), and it is always the next one, never the current one. Do the same change for _index/_idx variables in stats.c, which are used as arguments to these functions. Replace rd_ with next_id_ in stats_test.c, too. Related: OS#5088 Change-Id: I5dd566b08dff7174d1790f49abd2d6ac020e120e --- M include/osmocom/core/stat_item.h M src/stat_item.c M src/stats.c M tests/stats/stats_test.c 4 files changed, 56 insertions(+), 56 deletions(-) Approvals: Jenkins Builder: Verified osmith: Looks good to me, approved laforge: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve daniel: Looks good to me, but someone else must approve diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h index 4710dba..4a19465 100644 --- a/include/osmocom/core/stat_item.h +++ b/include/osmocom/core/stat_item.h @@ -91,14 +91,14 @@ const struct osmo_stat_item *osmo_stat_item_get_by_name( const struct osmo_stat_item_group *statg, const char *name); -int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value); +int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_id, int32_t *value); /*! Get the last (freshest) value */ static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item); -int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx); +int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *next_id); -int osmo_stat_item_discard_all(int32_t *idx); +int osmo_stat_item_discard_all(int32_t *next_id); typedef int (*osmo_stat_item_handler_t)( struct osmo_stat_item_group *, struct osmo_stat_item *, void *); diff --git a/src/stat_item.c b/src/stat_item.c index ba36464..31298fd 100644 --- a/src/stat_item.c +++ b/src/stat_item.c @@ -195,33 +195,33 @@ } /*! 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 + * If a new value has been set, it is returned. The next_id 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 + * On success, *next_id is updated to refer to the next unread value. If + * values have been missed due to FIFO overflow, *next_id is incremented by * (1 + num_lost). * 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 osmo_stat_item object - * \param idx identifies the next value to be read - * \param value a pointer to store the value + * \param val the osmo_stat_item object + * \param next_id 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 osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_idx, +int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_id, int32_t *value) { const struct osmo_stat_item_value *next_value; const struct osmo_stat_item_value *item_value = NULL; - int idx_delta; + int id_delta; int next_offs; next_offs = item->last_offs; next_value = &item->values[next_offs]; - while (next_value->id - *next_idx >= 0 && + while (next_value->id - *next_id >= 0 && next_value->id != OSMO_STAT_ITEM_NOVALUE_ID) { item_value = next_value; @@ -240,27 +240,27 @@ *value = item_value->value; - idx_delta = item_value->id + 1 - *next_idx; + id_delta = item_value->id + 1 - *next_id; - *next_idx = item_value->id + 1; + *next_id = item_value->id + 1; - return idx_delta; + return id_delta; } -/*! Skip/discard all values of this item and update \a idx accordingly */ -int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx) +/*! Skip/discard all values of this item and update \a next_id accordingly */ +int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *next_id) { - int discarded = item->values[item->last_offs].id + 1 - *idx; - *idx = item->values[item->last_offs].id + 1; + int discarded = item->values[item->last_offs].id + 1 - *next_id; + *next_id = item->values[item->last_offs].id + 1; return discarded; } -/*! Skip all values of all items and update \a idx accordingly */ -int osmo_stat_item_discard_all(int32_t *idx) +/*! Skip all values of all items and update \a next_id accordingly */ +int osmo_stat_item_discard_all(int32_t *next_id) { - int discarded = global_value_id + 1 - *idx; - *idx = global_value_id + 1; + int discarded = global_value_id + 1 - *next_id; + *next_id = global_value_id + 1; return discarded; } diff --git a/src/stats.c b/src/stats.c index f2820a4..88b733f 100644 --- a/src/stats.c +++ b/src/stats.c @@ -107,7 +107,7 @@ 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 int32_t current_stat_item_next_id = 0; static struct osmo_stats_config s_stats_config = { .interval = STATS_DEFAULT_INTERVAL, @@ -241,7 +241,7 @@ void osmo_stats_init(void *ctx) { osmo_stats_ctx = ctx; - osmo_stat_item_discard_all(¤t_stat_item_index); + osmo_stat_item_discard_all(¤t_stat_item_next_id); is_initialised = 1; start_timer(); @@ -694,18 +694,18 @@ struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_) { struct osmo_stats_reporter *srep; - int32_t idx = current_stat_item_index; + int32_t next_id = current_stat_item_next_id; int32_t value; int have_value; - have_value = osmo_stat_item_get_next(item, &idx, &value) > 0; + have_value = osmo_stat_item_get_next(item, &next_id, &value) > 0; if (!have_value) { /* Send the last value in case a flush is requested */ value = osmo_stat_item_get_last(item); } else { int32_t next_val; /* If we have multiple values only send the max */ - while (osmo_stat_item_get_next(item, &idx, &next_val) > 0) + while (osmo_stat_item_get_next(item, &next_id, &next_val) > 0) value = OSMO_MAX(value, next_val); } @@ -798,7 +798,7 @@ osmo_stat_item_for_each_group(osmo_stat_item_group_handler, NULL); /* global actions */ - osmo_stat_item_discard_all(¤t_stat_item_index); + osmo_stat_item_discard_all(¤t_stat_item_next_id); flush_all_reporters(); TRACE(LIBOSMOCORE_STATS_DONE()); diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c index 707f606..e5f7f20 100644 --- a/tests/stats/stats_test.c +++ b/tests/stats/stats_test.c @@ -90,8 +90,8 @@ const struct osmo_stat_item *sitem1, *sitem2; int rc; int32_t value; - int32_t rd_a = 0; - int32_t rd_b = 0; + int32_t next_id_a = 0; + int32_t next_id_b = 0; int i; OSMO_ASSERT(statg != NULL); @@ -120,7 +120,7 @@ value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]); OSMO_ASSERT(value == -1); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc == 0); osmo_stat_item_set(statg->items[TEST_A_ITEM], 1); @@ -128,39 +128,39 @@ value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]); OSMO_ASSERT(value == 1); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc == 0); for (i = 2; i <= 32; i++) { osmo_stat_item_set(statg->items[TEST_A_ITEM], i); osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); - rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } /* check if dec & inc is working */ osmo_stat_item_set(statg->items[TEST_A_ITEM], 42); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 42); osmo_stat_item_dec(statg->items[TEST_A_ITEM], 21); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 21); osmo_stat_item_inc(statg->items[TEST_A_ITEM], 21); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 42); @@ -172,20 +172,20 @@ osmo_stat_item_set(statg->items[TEST_A_ITEM], i); osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i-1); - rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i-1); } - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 64); - rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + 64); @@ -195,43 +195,43 @@ osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); } - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 93); for (i = 94; i <= 96; i++) { - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); } - rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + 90); for (i = 91; i <= 96; i++) { - rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } /* Test Discard (single item) */ osmo_stat_item_set(statg->items[TEST_A_ITEM], 97); - rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &next_id_a); OSMO_ASSERT(rc > 0); - rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &next_id_a); OSMO_ASSERT(rc == 0); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc == 0); osmo_stat_item_set(statg->items[TEST_A_ITEM], 98); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 98); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc == 0); /* Test Discard (all items) */ @@ -241,12 +241,12 @@ osmo_stat_item_set(statg->items[TEST_B_ITEM], 99); osmo_stat_item_set(statg->items[TEST_B_ITEM], 100); - rc = osmo_stat_item_discard_all(&rd_a); - rc = osmo_stat_item_discard_all(&rd_b); + rc = osmo_stat_item_discard_all(&next_id_a); + rc = osmo_stat_item_discard_all(&next_id_b); - rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value); OSMO_ASSERT(rc == 0); - rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value); OSMO_ASSERT(rc == 0); osmo_stat_item_group_free(statg); -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23506 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I5dd566b08dff7174d1790f49abd2d6ac020e120e Gerrit-Change-Number: 23506 Gerrit-PatchSet: 2 Gerrit-Owner: osmith <osmith at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann at sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de> Gerrit-Reviewer: osmith <osmith at sysmocom.de> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210406/37fed034/attachment.htm>