2014-06-16 08:13:40 +00:00
|
|
|
#pragma once
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \file statistics.h
|
|
|
|
* \brief Common routines regarding statistics */
|
|
|
|
|
|
|
|
/*! structure representing a single counter */
|
2011-05-07 10:43:04 +00:00
|
|
|
struct osmo_counter {
|
2011-08-16 21:26:52 +00:00
|
|
|
struct llist_head list; /*!< \brief internal list head */
|
|
|
|
const char *name; /*!< \brief human-readable name */
|
|
|
|
const char *description; /*!< \brief humn-readable description */
|
|
|
|
unsigned long value; /*!< \brief current value */
|
2015-10-26 13:39:08 +00:00
|
|
|
unsigned long previous; /*!< \brief previous value */
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
2016-08-22 19:42:57 +00:00
|
|
|
/*! \brief Decrement counter */
|
|
|
|
static inline void osmo_counter_dec(struct osmo_counter *ctr)
|
|
|
|
{
|
|
|
|
ctr->value--;
|
|
|
|
}
|
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \brief Increment counter */
|
2011-05-07 10:43:04 +00:00
|
|
|
static inline void osmo_counter_inc(struct osmo_counter *ctr)
|
2010-02-20 19:34:29 +00:00
|
|
|
{
|
|
|
|
ctr->value++;
|
|
|
|
}
|
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \brief Get current value of counter */
|
2011-05-07 10:43:04 +00:00
|
|
|
static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
|
2010-02-20 19:34:29 +00:00
|
|
|
{
|
|
|
|
return ctr->value;
|
|
|
|
}
|
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \brief Reset current value of counter to 0 */
|
2011-05-07 10:43:04 +00:00
|
|
|
static inline void osmo_counter_reset(struct osmo_counter *ctr)
|
2010-02-20 19:34:29 +00:00
|
|
|
{
|
|
|
|
ctr->value = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \brief Allocate a new counter */
|
2011-05-07 10:43:04 +00:00
|
|
|
struct osmo_counter *osmo_counter_alloc(const char *name);
|
2011-08-16 21:26:52 +00:00
|
|
|
|
|
|
|
/*! \brief Free the specified counter
|
2013-02-15 12:27:59 +00:00
|
|
|
* \param[in] ctr Counter
|
2011-08-16 21:26:52 +00:00
|
|
|
*/
|
2011-05-07 10:43:04 +00:00
|
|
|
void osmo_counter_free(struct osmo_counter *ctr);
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2015-10-19 13:00:59 +00:00
|
|
|
/*! \brief Iterate over all counters
|
|
|
|
* \param[in] handle_counter Call-back function, aborts if rc < 0
|
2011-08-16 21:26:52 +00:00
|
|
|
* \param[in] data Private dtata handed through to \a handle_counter
|
|
|
|
*/
|
2011-05-07 10:43:04 +00:00
|
|
|
int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! \brief Resolve counter by human-readable name
|
|
|
|
* \param[in] name human-readable name of counter
|
|
|
|
* \returns pointer to counter (\ref osmo_counter) or NULL otherwise
|
|
|
|
*/
|
2011-05-07 10:43:04 +00:00
|
|
|
struct osmo_counter *osmo_counter_get_by_name(const char *name);
|
2015-10-26 13:39:08 +00:00
|
|
|
|
|
|
|
/*! \brief Return the counter difference since the last call to this function */
|
|
|
|
int osmo_counter_difference(struct osmo_counter *ctr);
|