blob: de250bec33d7fa831bf064a9c4fee8aad7b9cd9e [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welteec8b4502010-02-20 20:34:29 +01002
Harald Weltebd598e32011-08-16 23:26:52 +02003/*! \file statistics.h
4 * \brief Common routines regarding statistics */
5
6/*! structure representing a single counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +02007struct osmo_counter {
Harald Weltebd598e32011-08-16 23:26:52 +02008 struct llist_head list; /*!< \brief internal list head */
9 const char *name; /*!< \brief human-readable name */
10 const char *description; /*!< \brief humn-readable description */
11 unsigned long value; /*!< \brief current value */
Harald Welteec8b4502010-02-20 20:34:29 +010012};
13
Harald Weltebd598e32011-08-16 23:26:52 +020014/*! \brief Increment counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020015static inline void osmo_counter_inc(struct osmo_counter *ctr)
Harald Welteec8b4502010-02-20 20:34:29 +010016{
17 ctr->value++;
18}
19
Harald Weltebd598e32011-08-16 23:26:52 +020020/*! \brief Get current value of counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020021static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
Harald Welteec8b4502010-02-20 20:34:29 +010022{
23 return ctr->value;
24}
25
Harald Weltebd598e32011-08-16 23:26:52 +020026/*! \brief Reset current value of counter to 0 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020027static inline void osmo_counter_reset(struct osmo_counter *ctr)
Harald Welteec8b4502010-02-20 20:34:29 +010028{
29 ctr->value = 0;
30}
31
Harald Weltebd598e32011-08-16 23:26:52 +020032/*! \brief Allocate a new counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020033struct osmo_counter *osmo_counter_alloc(const char *name);
Harald Weltebd598e32011-08-16 23:26:52 +020034
35/*! \brief Free the specified counter
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010036 * \param[in] ctr Counter
Harald Weltebd598e32011-08-16 23:26:52 +020037 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020038void osmo_counter_free(struct osmo_counter *ctr);
Harald Welteec8b4502010-02-20 20:34:29 +010039
Harald Weltebd598e32011-08-16 23:26:52 +020040/*! \brief Iteate over all counters
41 * \param[in] handle_counter Call-back function
42 * \param[in] data Private dtata handed through to \a handle_counter
43 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020044int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
Harald Welteec8b4502010-02-20 20:34:29 +010045
Harald Weltebd598e32011-08-16 23:26:52 +020046/*! \brief Resolve counter by human-readable name
47 * \param[in] name human-readable name of counter
48 * \returns pointer to counter (\ref osmo_counter) or NULL otherwise
49 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020050struct osmo_counter *osmo_counter_get_by_name(const char *name);