aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2020-07-14 18:10:20 +0200
committerlaforge <laforge@osmocom.org>2020-07-17 16:41:31 +0000
commitea71b439ec3c9ba1e39174972664be4c2f62a0ca (patch)
tree61f515c1bb8c76452f12bed69643c44d0600aae6
parent26a9539e18295dcd84597cacbd736652075426e2 (diff)
stat_item: Add function to reset stat items and groups
-rw-r--r--TODO-RELEASE1
-rw-r--r--include/osmocom/core/stat_item.h4
-rw-r--r--src/stat_item.c29
3 files changed, 34 insertions, 0 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 36966819..a4d9dfbd 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -16,3 +16,4 @@ gsm API/ABI change add new member to lapd_datalink
gsm new API new gsm0808_create_common_id()
gb new API new bssgp_tx_bvc_reset2()
core new API new rate_ctr_reset(), rate_ctr_group_reset()
+core new API new osmo_stat_item_reset(), osmo_stat_item_group_reset()
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index 806173ab..4710dba7 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -114,4 +114,8 @@ static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
{
return item->values[item->last_offs].value;
}
+
+void osmo_stat_item_reset(struct osmo_stat_item *item);
+void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg);
+
/*! @} */
diff --git a/src/stat_item.c b/src/stat_item.c
index 67165754..ba364640 100644
--- a/src/stat_item.c
+++ b/src/stat_item.c
@@ -356,4 +356,33 @@ int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, v
return rc;
}
+
+/*! Remove all values of a stat item
+ * \param[in] item stat item to reset
+ */
+void osmo_stat_item_reset(struct osmo_stat_item *item)
+{
+ unsigned int i;
+
+ item->last_offs = item->desc->num_values - 1;
+ item->last_value_index = -1;
+
+ for (i = 0; i <= item->last_offs; i++) {
+ item->values[i].value = item->desc->default_value;
+ item->values[i].id = OSMO_STAT_ITEM_NOVALUE_ID;
+ }
+}
+
+/*! Reset all osmo stat items in a group
+ * \param[in] statg stat item group to reset
+ */
+void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg)
+{
+ int i;
+
+ for (i = 0; i < statg->desc->num_items; i++) {
+ struct osmo_stat_item *item = statg->items[i];
+ osmo_stat_item_reset(item);
+ }
+}
/*! @} */