Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 1 | #ifndef _STATISTICS_H |
| 2 | #define _STATISTICS_H |
| 3 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 4 | struct osmo_counter { |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 5 | struct llist_head list; |
| 6 | const char *name; |
| 7 | const char *description; |
| 8 | unsigned long value; |
| 9 | }; |
| 10 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 11 | static inline void osmo_counter_inc(struct osmo_counter *ctr) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 12 | { |
| 13 | ctr->value++; |
| 14 | } |
| 15 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 16 | static inline unsigned long osmo_counter_get(struct osmo_counter *ctr) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 17 | { |
| 18 | return ctr->value; |
| 19 | } |
| 20 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 21 | static inline void osmo_counter_reset(struct osmo_counter *ctr) |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 22 | { |
| 23 | ctr->value = 0; |
| 24 | } |
| 25 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 26 | struct osmo_counter *osmo_counter_alloc(const char *name); |
| 27 | void osmo_counter_free(struct osmo_counter *ctr); |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 28 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 29 | 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] | 30 | |
Pablo Neira Ayuso | 220abab | 2011-05-07 12:43:04 +0200 | [diff] [blame] | 31 | struct osmo_counter *osmo_counter_get_by_name(const char *name); |
Daniel Willmann | 334c8e1 | 2011-04-08 10:46:19 +0200 | [diff] [blame] | 32 | |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 33 | #endif /* _STATISTICS_H */ |