Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 2 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 3 | /*! \file statistics.h |
| 4 | * \brief Common routines regarding statistics */ |
| 5 | |
| 6 | /*! structure representing a single counter */ |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 7 | struct osmo_counter { |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 8 | 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 Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 12 | }; |
| 13 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 14 | /*! \brief Increment counter */ |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 15 | static inline void osmo_counter_inc(struct osmo_counter *ctr) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 16 | { |
| 17 | ctr->value++; |
| 18 | } |
| 19 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 20 | /*! \brief Get current value of counter */ |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 21 | static inline unsigned long osmo_counter_get(struct osmo_counter *ctr) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 22 | { |
| 23 | return ctr->value; |
| 24 | } |
| 25 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 26 | /*! \brief Reset current value of counter to 0 */ |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 27 | static inline void osmo_counter_reset(struct osmo_counter *ctr) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 28 | { |
| 29 | ctr->value = 0; |
| 30 | } |
| 31 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 32 | /*! \brief Allocate a new counter */ |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 33 | struct osmo_counter *osmo_counter_alloc(const char *name); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 34 | |
| 35 | /*! \brief Free the specified counter |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 36 | * \param[in] ctr Counter |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 37 | */ |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 38 | void osmo_counter_free(struct osmo_counter *ctr); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 39 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 40 | /*! \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 Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 44 | int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 45 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 46 | /*! \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 Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 50 | struct osmo_counter *osmo_counter_get_by_name(const char *name); |