blob: 04816c166f19a9b3639a9e0069469991e1ee09d1 [file] [log] [blame]
Harald Welteec8b4502010-02-20 20:34:29 +01001#ifndef _STATISTICS_H
2#define _STATISTICS_H
3
Harald Weltebd598e32011-08-16 23:26:52 +02004/*! \file statistics.h
5 * \brief Common routines regarding statistics */
6
7/*! structure representing a single counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +02008struct osmo_counter {
Harald Weltebd598e32011-08-16 23:26:52 +02009 struct llist_head list; /*!< \brief internal list head */
10 const char *name; /*!< \brief human-readable name */
11 const char *description; /*!< \brief humn-readable description */
12 unsigned long value; /*!< \brief current value */
Harald Welteec8b4502010-02-20 20:34:29 +010013};
14
Harald Weltebd598e32011-08-16 23:26:52 +020015/*! \brief Increment counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020016static inline void osmo_counter_inc(struct osmo_counter *ctr)
Harald Welteec8b4502010-02-20 20:34:29 +010017{
18 ctr->value++;
19}
20
Harald Weltebd598e32011-08-16 23:26:52 +020021/*! \brief Get current value of counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020022static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
Harald Welteec8b4502010-02-20 20:34:29 +010023{
24 return ctr->value;
25}
26
Harald Weltebd598e32011-08-16 23:26:52 +020027/*! \brief Reset current value of counter to 0 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020028static inline void osmo_counter_reset(struct osmo_counter *ctr)
Harald Welteec8b4502010-02-20 20:34:29 +010029{
30 ctr->value = 0;
31}
32
Harald Weltebd598e32011-08-16 23:26:52 +020033/*! \brief Allocate a new counter */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020034struct osmo_counter *osmo_counter_alloc(const char *name);
Harald Weltebd598e32011-08-16 23:26:52 +020035
36/*! \brief Free the specified counter
37 * \param[ctr] Counter
38 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020039void osmo_counter_free(struct osmo_counter *ctr);
Harald Welteec8b4502010-02-20 20:34:29 +010040
Harald Weltebd598e32011-08-16 23:26:52 +020041/*! \brief Iteate over all counters
42 * \param[in] handle_counter Call-back function
43 * \param[in] data Private dtata handed through to \a handle_counter
44 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020045int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
Harald Welteec8b4502010-02-20 20:34:29 +010046
Harald Weltebd598e32011-08-16 23:26:52 +020047/*! \brief Resolve counter by human-readable name
48 * \param[in] name human-readable name of counter
49 * \returns pointer to counter (\ref osmo_counter) or NULL otherwise
50 */
Pablo Neira Ayuso220abab2011-05-07 12:43:04 +020051struct osmo_counter *osmo_counter_get_by_name(const char *name);
Daniel Willmann334c8e12011-04-08 10:46:19 +020052
Harald Welteec8b4502010-02-20 20:34:29 +010053#endif /* _STATISTICS_H */