aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-10-12 18:47:09 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-10-28 23:51:24 +0100
commitb27b352e937dd0760da1e7fb05f9207be05702b8 (patch)
treedf0a1dc555ee1ada807e51260de918dcf6f53370 /include
parent0a1400fc8311268d0a66bb20e0620e546e8d11c8 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/core/stat_item.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index e166579f..003c9e07 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 @@ struct stat_item {
/*! \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 @@ struct stat_item_group *stat_item_group_alloc(
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 @@ struct stat_item_group *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 *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 @@ const struct stat_item *stat_item_get_by_name(
* 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);
+
+/*! \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 *val)
+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;
}
/*! @} */