statistics.h
Go to the documentation of this file.
#pragma once
struct osmo_counter {
struct llist_head list;
const char *name;
const char *description;
unsigned long value;
unsigned long previous;
};
static inline void osmo_counter_inc(struct osmo_counter *ctr)
{
ctr->value++;
}
static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
{
return ctr->value;
}
static inline void osmo_counter_reset(struct osmo_counter *ctr)
{
ctr->value = 0;
}
struct osmo_counter *osmo_counter_alloc(const char *name);
void osmo_counter_free(struct osmo_counter *ctr);
int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
struct osmo_counter *osmo_counter_get_by_name(const char *name);
int osmo_counter_difference(struct osmo_counter *ctr);
osmo_counter_reset
static void osmo_counter_reset(struct osmo_counter *ctr)
Reset current value of counter to 0.
Definition: statistics.h:28
osmo_counter_inc
static void osmo_counter_inc(struct osmo_counter *ctr)
Increment counter.
Definition: statistics.h:16
osmo_counter::name
const char * name
human-readable name
Definition: statistics.h:9
osmo_counter::description
const char * description
humn-readable description
Definition: statistics.h:10
llist_head
Definition: linuxlist.h:42
osmo_counter_get_by_name
struct osmo_counter * osmo_counter_get_by_name(const char *name)
Resolve counter by human-readable name.
Definition: statistics.c:67
osmo_counter::previous
unsigned long previous
previous value
Definition: statistics.h:12
osmo_counters_for_each
int osmo_counters_for_each(int(*handle_counter)(struct osmo_counter *, void *), void *data)
Iterate over all counters.
Definition: statistics.c:52
osmo_counter
Definition: statistics.h:7
osmo_counter_free
void osmo_counter_free(struct osmo_counter *ctr)
Free the specified counter.
Definition: statistics.c:46
osmo_counter_get
static unsigned long osmo_counter_get(struct osmo_counter *ctr)
Get current value of counter.
Definition: statistics.h:22
osmo_counter::list
struct llist_head list
internal list head
Definition: statistics.h:8
osmo_counter_alloc
struct osmo_counter * osmo_counter_alloc(const char *name)
Allocate a new counter.
Definition: statistics.c:33
osmo_counter::value
unsigned long value
current value
Definition: statistics.h:11
osmo_counter_difference
int osmo_counter_difference(struct osmo_counter *ctr)
Return the counter difference since the last call to this function.
Definition: statistics.c:78