diff options
Diffstat (limited to 'include/osmocom/core/rate_ctr.h')
-rw-r--r-- | include/osmocom/core/rate_ctr.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h index f7e6e225..0a3eb2ce 100644 --- a/include/osmocom/core/rate_ctr.h +++ b/include/osmocom/core/rate_ctr.h @@ -61,7 +61,9 @@ struct rate_ctr_group { const struct rate_ctr_group_desc *desc; /*! The index of this ctr_group within its class */ unsigned int idx; - /*! Actual counter structures below */ + /*! Optional string-based identifier to be used instead of index at report time */ + char *name; + /*! Actual counter structures below. Don't access it directly, use APIs below! */ struct rate_ctr ctr[0]; }; @@ -73,6 +75,9 @@ static inline void rate_ctr_group_upd_idx(struct rate_ctr_group *grp, unsigned i { grp->idx = idx; } +void rate_ctr_group_set_name(struct rate_ctr_group *grp, const char *name); + +struct rate_ctr *rate_ctr_group_get_ctr(struct rate_ctr_group *grp, unsigned int idx); void rate_ctr_group_free(struct rate_ctr_group *grp); @@ -81,6 +86,15 @@ void rate_ctr_group_free(struct rate_ctr_group *grp); * \param inc quantity to increment \a ctr by */ void rate_ctr_add(struct rate_ctr *ctr, int inc); +/*! Increment the counter by \a inc + * \param ctrg \ref rate_ctr_group of counter + * \param idx index into \a ctrg counter group + * \param inc quantity to increment \a ctr by */ +static inline void rate_ctr_add2(struct rate_ctr_group *ctrg, unsigned int idx, int inc) +{ + rate_ctr_add(rate_ctr_group_get_ctr(ctrg, idx), inc); +} + /*! Increment the counter by 1 * \param ctr \ref rate_ctr to increment */ static inline void rate_ctr_inc(struct rate_ctr *ctr) @@ -93,7 +107,7 @@ static inline void rate_ctr_inc(struct rate_ctr *ctr) * \param idx index into \a ctrg counter group */ static inline void rate_ctr_inc2(struct rate_ctr_group *ctrg, unsigned int idx) { - rate_ctr_inc(&ctrg->ctr[idx]); + rate_ctr_inc(rate_ctr_group_get_ctr(ctrg, idx)); } @@ -116,4 +130,7 @@ int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg, int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data); +void rate_ctr_reset(struct rate_ctr *ctr); +void rate_ctr_group_reset(struct rate_ctr_group *ctrg); + /*! @} */ |