libosmocore  0.9.6-9.20170220git32ee5af8.fc29
Osmocom core library
statistics.h
Go to the documentation of this file.
1 #pragma once
2 
7 struct osmo_counter {
8  struct llist_head list;
9  const char *name;
10  const char *description;
11  unsigned long value;
12  unsigned long previous;
13 };
14 
16 static inline void osmo_counter_dec(struct osmo_counter *ctr)
17 {
18  ctr->value--;
19 }
20 
22 static inline void osmo_counter_inc(struct osmo_counter *ctr)
23 {
24  ctr->value++;
25 }
26 
28 static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
29 {
30  return ctr->value;
31 }
32 
34 static inline void osmo_counter_reset(struct osmo_counter *ctr)
35 {
36  ctr->value = 0;
37 }
38 
40 struct osmo_counter *osmo_counter_alloc(const char *name);
41 
45 void osmo_counter_free(struct osmo_counter *ctr);
46 
51 int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
52 
57 struct osmo_counter *osmo_counter_get_by_name(const char *name);
58 
60 int osmo_counter_difference(struct osmo_counter *ctr);
static void osmo_counter_reset(struct osmo_counter *ctr)
Reset current value of counter to 0.
Definition: statistics.h:34
static void osmo_counter_inc(struct osmo_counter *ctr)
Increment counter.
Definition: statistics.h:22
const char * name
human-readable name
Definition: statistics.h:9
const char * description
humn-readable description
Definition: statistics.h:10
(double) linked list header structure
Definition: linuxlist.h:47
struct osmo_counter * osmo_counter_get_by_name(const char *name)
Resolve counter by human-readable name.
Definition: statistics.c:67
static void osmo_counter_dec(struct osmo_counter *ctr)
Decrement counter.
Definition: statistics.h:16
unsigned long previous
previous value
Definition: statistics.h:12
int osmo_counters_for_each(int(*handle_counter)(struct osmo_counter *, void *), void *data)
Iterate over all counters.
Definition: statistics.c:52
Definition: statistics.h:7
void osmo_counter_free(struct osmo_counter *ctr)
Free the specified counter.
Definition: statistics.c:46
static unsigned long osmo_counter_get(struct osmo_counter *ctr)
Get current value of counter.
Definition: statistics.h:28
struct llist_head list
internal list head
Definition: statistics.h:8
struct osmo_counter * osmo_counter_alloc(const char *name)
Allocate a new counter.
Definition: statistics.c:33
unsigned long value
current value
Definition: statistics.h:11
int osmo_counter_difference(struct osmo_counter *ctr)
Return the counter difference since the last call to this function.
Definition: statistics.c:78