blob: 7b677cb147cc33d7df34fefc91efdbdac68adb86 [file] [log] [blame]
Harald Welte216338c2017-10-15 19:46:19 +02001#pragma once
2
Daniel Willmann0a1259b2019-04-29 13:09:14 +02003#include <osmocom/core/defs.h>
4
Harald Welte216338c2017-10-15 19:46:19 +02005/*! \file counter.h
6 * Common routines regarding counter handling */
7
Harald Welte17bbaa32017-10-15 20:02:07 +02008/*! Structure representing a single counter */
Harald Welte216338c2017-10-15 19:46:19 +02009struct osmo_counter {
10 struct llist_head list; /*!< internal list head */
11 const char *name; /*!< human-readable name */
12 const char *description; /*!< humn-readable description */
13 unsigned long value; /*!< current value */
14 unsigned long previous; /*!< previous value */
15};
16
Harald Welte17bbaa32017-10-15 20:02:07 +020017/*! Decrement given counter by one
18 * \param[in] ctr Counter that's to be decremented */
Daniel Willmann0a1259b2019-04-29 13:09:14 +020019OSMO_DEPRECATED("Implement as osmo_stat_item instead")
Harald Welte216338c2017-10-15 19:46:19 +020020static inline void osmo_counter_dec(struct osmo_counter *ctr)
21{
22 ctr->value--;
23}
24
Harald Welte17bbaa32017-10-15 20:02:07 +020025/*! Increment counter by one.
26 * \param[in] Counter that's to be incremented */
Daniel Willmann0a1259b2019-04-29 13:09:14 +020027OSMO_DEPRECATED("Implement as osmo_stat_item instead")
Harald Welte216338c2017-10-15 19:46:19 +020028static inline void osmo_counter_inc(struct osmo_counter *ctr)
29{
30 ctr->value++;
31}
32
33/*! Get current value of counter */
Neels Hofmeyr137efc92021-09-29 15:22:28 +020034OSMO_DEPRECATED_OUTSIDE("Implement as osmo_stat_item instead")
Harald Welte216338c2017-10-15 19:46:19 +020035static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
36{
37 return ctr->value;
38}
39
40/*! Reset current value of counter to 0 */
Daniel Willmann0a1259b2019-04-29 13:09:14 +020041OSMO_DEPRECATED("Implement as osmo_stat_item instead")
Harald Welte216338c2017-10-15 19:46:19 +020042static inline void osmo_counter_reset(struct osmo_counter *ctr)
43{
44 ctr->value = 0;
45}
46
Daniel Willmann0a1259b2019-04-29 13:09:14 +020047struct osmo_counter *osmo_counter_alloc(const char *name)
48 OSMO_DEPRECATED("Implement as osmo_stat_item instead");
Harald Welte216338c2017-10-15 19:46:19 +020049
Daniel Willmann0a1259b2019-04-29 13:09:14 +020050void osmo_counter_free(struct osmo_counter *ctr)
51 OSMO_DEPRECATED("Implement as osmo_stat_item instead");
Harald Welte216338c2017-10-15 19:46:19 +020052
Harald Welte216338c2017-10-15 19:46:19 +020053int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
54
Harald Weltee61d4592022-11-03 11:05:58 +010055int osmo_counters_count(void);
Alexander Couzens18ba26c2017-12-05 16:06:27 +010056
Harald Welte216338c2017-10-15 19:46:19 +020057struct osmo_counter *osmo_counter_get_by_name(const char *name);
58
Harald Welte216338c2017-10-15 19:46:19 +020059int osmo_counter_difference(struct osmo_counter *ctr);