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