stats: Use a global index for stat item values
Currently each stat item has a separate index value which basically
counts each single value added to the item and which can be used by
a reporter to get all new values that have not been reported yet.
The drawback is, that such an index must be stored for each stat
item.
This commit introduces a global index which is incremented for each
new stat item value. This index is then stored together with the item
value. So a single stored index per reporter is sufficient to make
sure that only new values are reported.
Sponsored-by: On-Waves ehf
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index e166579..003c9e0 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -12,6 +12,13 @@
struct stat_item_desc;
+#define STAT_ITEM_NOVALUE_ID 0
+
+struct 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;
@@ -20,7 +27,7 @@
/*! \brief offset to the freshest value in the value fifo */
int16_t last_offs;
/*! \brief value fifo */
- int32_t values[0];
+ struct stat_item_value values[0];
};
/*! \brief statistics value description */
@@ -61,9 +68,9 @@
const struct stat_item_group_desc *desc,
unsigned int idx);
-void stat_item_group_free(struct stat_item_group *grp);
+void stat_item_group_free(struct stat_item_group *statg);
-void stat_item_set(struct stat_item *val, int32_t value);
+void stat_item_set(struct stat_item *item, int32_t value);
int stat_item_init(void *tall_ctx);
@@ -71,7 +78,7 @@
const char *name, const unsigned int idx);
const struct stat_item *stat_item_get_by_name(
- const struct stat_item_group *valg, const char *name);
+ const struct stat_item_group *statg, const char *name);
/*! \brief Retrieve the next value from the stat_item object.
* If a new value has been set, it is returned. The idx is used to decide
@@ -89,16 +96,19 @@
* 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 *val, int32_t *idx, int32_t *value);
+int stat_item_get_next(const struct 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 *val);
+static int32_t stat_item_get_last(const struct stat_item *item);
/*! \brief Skip all values of the item and update idx accordingly */
-int stat_item_discard(const struct stat_item *val, int32_t *idx);
+int stat_item_discard(const struct stat_item *item, int32_t *idx);
-static inline int32_t stat_item_get_last(const struct stat_item *val)
+/*! \brief Skip all values of all items and update idx accordingly */
+int stat_item_discard_all(int32_t *idx);
+
+static inline int32_t stat_item_get_last(const struct stat_item *item)
{
- return val->values[val->last_offs];
+ return item->values[item->last_offs].value;
}
/*! @} */