mirror of https://gerrit.osmocom.org/libosmocore
core: Add difference function to osmo_counter
The osmo_counter_difference returns the counter value difference since the last call of this function with the given counter object. Sponsored-by: On-Waves ehf
This commit is contained in:
parent
c27671c109
commit
80db4ec387
|
@ -9,6 +9,7 @@ struct osmo_counter {
|
||||||
const char *name; /*!< \brief human-readable name */
|
const char *name; /*!< \brief human-readable name */
|
||||||
const char *description; /*!< \brief humn-readable description */
|
const char *description; /*!< \brief humn-readable description */
|
||||||
unsigned long value; /*!< \brief current value */
|
unsigned long value; /*!< \brief current value */
|
||||||
|
unsigned long previous; /*!< \brief previous value */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief Increment counter */
|
/*! \brief Increment counter */
|
||||||
|
@ -48,3 +49,6 @@ int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *),
|
||||||
* \returns pointer to counter (\ref osmo_counter) or NULL otherwise
|
* \returns pointer to counter (\ref osmo_counter) or NULL otherwise
|
||||||
*/
|
*/
|
||||||
struct osmo_counter *osmo_counter_get_by_name(const char *name);
|
struct osmo_counter *osmo_counter_get_by_name(const char *name);
|
||||||
|
|
||||||
|
/*! \brief Return the counter difference since the last call to this function */
|
||||||
|
int osmo_counter_difference(struct osmo_counter *ctr);
|
||||||
|
|
|
@ -74,3 +74,11 @@ struct osmo_counter *osmo_counter_get_by_name(const char *name)
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int osmo_counter_difference(struct osmo_counter *ctr)
|
||||||
|
{
|
||||||
|
int delta = ctr->value - ctr->previous;
|
||||||
|
ctr->previous = ctr->value;
|
||||||
|
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue