diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-10-19 13:45:42 +0200 |
---|---|---|
committer | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-10-28 23:51:24 +0100 |
commit | 423c1e5a4fc7ad2cd5e95e852b778c7e2c892bc1 (patch) | |
tree | dbbeef0fb12974fb1a4af423368d13a5b06110a7 /include/osmocom/core | |
parent | b27b352e937dd0760da1e7fb05f9207be05702b8 (diff) |
core: Extend rate_ctr by helper functions
For global value reporting, some additional helper functions are
needed. The statsd protocol expects differential counter values,
which are currently not provided by rate_ctr (except for s/m/h/d
intervals).
This commit adds several helper functions to rate_ctr:
- rate_ctr_difference returns the counter delta since the last
call to this function for a given counter
- rate_ctr_for_each_counter
iterates through each counter of a group
- rate_ctr_for_each_group
iterates through all globally registered
counter groups
Note that the rate_ctr_difference function can only be used by a
single backend, since it modifies the 'previous' field in the
rate_ctr obj.
Sponsored-by: On-Waves ehf
Diffstat (limited to 'include/osmocom/core')
-rw-r--r-- | include/osmocom/core/rate_ctr.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h index 821c7cfd..f3c03de3 100644 --- a/include/osmocom/core/rate_ctr.h +++ b/include/osmocom/core/rate_ctr.h @@ -30,6 +30,7 @@ struct rate_ctr_per_intv { /*! \brief data we keep for each actual value */ struct rate_ctr { uint64_t current; /*!< \brief current value */ + uint64_t previous; /*!< \brief previous value, used for delta */ /*! \brief per-interval data */ struct rate_ctr_per_intv intv[RATE_CTR_INTV_NUM]; }; @@ -78,9 +79,27 @@ static inline void rate_ctr_inc(struct rate_ctr *ctr) rate_ctr_add(ctr, 1); } +/*! \brief Return the counter difference since the last call to this function */ +int64_t rate_ctr_difference(struct rate_ctr *ctr); + int rate_ctr_init(void *tall_ctx); struct rate_ctr_group *rate_ctr_get_group_by_name_idx(const char *name, const unsigned int idx); const struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name); +typedef int (*rate_ctr_handler_t)( + struct rate_ctr_group *, struct rate_ctr *, + const struct rate_ctr_desc *, void *); +typedef int (*rate_ctr_group_handler_t)(struct rate_ctr_group *, void *); + + +/*! \brief Iterate over all counters + * \param[in] handle_item Call-back function, aborts if rc < 0 + * \param[in] data Private data handed through to \a handle_counter + */ +int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg, + rate_ctr_handler_t handle_counter, void *data); + +int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data); + /*! @} */ |