Loading...
Searching...
No Matches
counter.h File Reference

Common routines regarding counter handling. More...

`#include <osmocom/core/defs.h>`

Go to the source code of this file.

## Data Structures

struct | osmo_counter
| Structure representing a single counter. More...

## Functions

static void | osmo_counter_dec (struct osmo_counter *ctr)
| Decrement given counter by one.
static void | osmo_counter_inc (struct osmo_counter *ctr)
| Increment counter by one.
static unsigned long | osmo_counter_get (struct osmo_counter *ctr)
| Get current value of counter.
static void | osmo_counter_reset (struct osmo_counter *ctr)
| Reset current value of counter to 0.
struct osmo_counter * | osmo_counter_alloc (const char *name) OSMO_DEPRECATED("Implement as osmo_stat_item instead")
| Allocate a new counter with given name.
void | osmo_counter_free (struct osmo_counter *ctr) OSMO_DEPRECATED("Implement as osmo_stat_item instead")
| Release/Destroy a given counter.
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.
int | osmo_counters_count (void)
| Counts the registered counter.
struct osmo_counter * | osmo_counter_get_by_name (const char *name)
| Find a counter by its name.
int | osmo_counter_difference (struct osmo_counter *ctr)
| Compute difference between current and previous counter value.

## Detailed Description

Common routines regarding counter handling.

## Function Documentation

## 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] | name | Human-readable string name for the counter

Returns
  Allocated counter on success; NULL on error

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

## osmo_counter_dec()

static void osmo_counter_dec | ( | struct osmo_counter * | ctr | ) |

inline static

Decrement given counter by one.

Parameters

  [in] | ctr | Counter that's to be decremented

## osmo_counter_difference()

int osmo_counter_difference | ( | struct osmo_counter * | ctr | ) |

Compute difference between current and previous counter value.

Parameters

  [in] | ctr | Counter 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] | ctr | Counter to be destroyed

References osmo_counter::list, and llist_del().

## osmo_counter_get()

static unsigned long osmo_counter_get | ( | struct osmo_counter * | ctr | ) |

inline static

Get current value of counter.

## osmo_counter_get_by_name()

struct osmo_counter * osmo_counter_get_by_name | ( | const char * | name | ) |

Find a counter by its name.

Parameters

  [in] | name | Name used to look-up/search counter

Returns
  Counter on success; NULL if not found

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

## osmo_counter_inc()

static void osmo_counter_inc | ( | struct osmo_counter * | ctr | ) |

inline static

Increment counter by one.

Parameters

  [in] | Counter | that's to be incremented

## osmo_counter_reset()

static void osmo_counter_reset | ( | struct osmo_counter * | ctr | ) |

inline static

Reset current value of counter to 0.

## 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_counter | Call-back to be called for each counter; aborts if rc < 0
  [in] | data | Opaque data passed through to handle_counter function

Returns
  0 if all handle_counter calls successfull; negative on error

References data, osmo_counter::list, and llist_for_each_entry.

Referenced by osmo_stats_report().