libosmocore 1.9.0.197-fb8cd
Osmocom core library
counter.c File Reference

utility routines for keeping some statistics. More...

#include <string.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/counter.h>

Functions

static LLIST_HEAD (counters)
 
struct osmo_counterosmo_counter_alloc (const char *name)
 Allocate a new counter with given name. More...
 
void osmo_counter_free (struct osmo_counter *ctr)
 Release/Destroy a given counter. More...
 
int osmo_counters_for_each (int(*handle_counter)(struct osmo_counter *, void *), void *data)
 Iterate over all counters; call handle_cunter call-back for each. More...
 
int osmo_counters_count (void)
 Counts the registered counter. More...
 
struct osmo_counterosmo_counter_get_by_name (const char *name)
 Find a counter by its name. More...
 
int osmo_counter_difference (struct osmo_counter *ctr)
 Compute difference between current and previous counter value. More...
 

Variables

void * tall_ctr_ctx
 Global talloc context for all osmo_counter allocations. More...
 

Detailed Description

utility routines for keeping some statistics.

Function Documentation

◆ LLIST_HEAD()

static LLIST_HEAD ( counters  )
static

◆ osmo_counter_alloc()

struct osmo_counter * osmo_counter_alloc ( const char *  name)

Allocate a new counter with given name.

Allocates from tall_ctr_ctx

Parameters
[in]nameHuman-readable string name for the counter
Returns
Allocated counter on success; NULL on error

References osmo_counter::list, llist_add_tail(), name, osmo_counter::name, and tall_ctr_ctx.

◆ osmo_counter_difference()

int osmo_counter_difference ( struct osmo_counter ctr)

Compute difference between current and previous counter value.

Parameters
[in]ctrCounter of which the difference is to be computed
Returns
Delta value between current counter and previous counter. Please note that the actual counter values are unsigned long, while the difference is computed as signed integer!

References osmo_counter::previous, and osmo_counter::value.

Referenced by handle_counter().

◆ osmo_counter_free()

void osmo_counter_free ( struct osmo_counter ctr)

Release/Destroy a given counter.

Parameters
[in]ctrCounter to be destroyed

References osmo_counter::list, and llist_del().

◆ osmo_counter_get_by_name()

struct osmo_counter * osmo_counter_get_by_name ( const char *  name)

Find a counter by its name.

Parameters
[in]nameName used to look-up/search counter
Returns
Counter on success; NULL if not found

References list, llist_for_each_entry, name, and osmo_counter::name.

◆ osmo_counters_count()

int osmo_counters_count ( void  )

Counts the registered counter.

Returns
amount of counters

References llist_count().

◆ osmo_counters_for_each()

int osmo_counters_for_each ( int(*)(struct osmo_counter *, void *)  handle_counter,
void *  data 
)

Iterate over all counters; call handle_cunter call-back for each.

Parameters
[in]handle_counterCall-back to be called for each counter; aborts if rc < 0
[in]dataOpaque data passed through to handle_counter function
Returns
0 if all handle_counter calls successfull; negative on error

References data, handle_counter(), list, and llist_for_each_entry.

Referenced by osmo_stats_report().

Variable Documentation

◆ tall_ctr_ctx

void* tall_ctr_ctx

Global talloc context for all osmo_counter allocations.

Referenced by osmo_counter_alloc().