stat_item: Add function to reset stat items and groups

Change-Id: I80fc0ea8865ec4efdcd4c982e69d863275fd9919
Related: SYS#4877
This commit is contained in:
Daniel Willmann 2020-07-14 18:10:20 +02:00 committed by laforge
parent 26a9539e18
commit ea71b439ec
3 changed files with 34 additions and 0 deletions

View File

@ -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()

View File

@ -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);
/*! @} */

View File

@ -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);
}
}
/*! @} */