summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/statistics.h4
-rw-r--r--src/statistics.c8
2 files changed, 12 insertions, 0 deletions
diff --git a/include/osmocom/core/statistics.h b/include/osmocom/core/statistics.h
index a9a623d3..1e472ffd 100644
--- a/include/osmocom/core/statistics.h
+++ b/include/osmocom/core/statistics.h
@@ -9,6 +9,7 @@ struct osmo_counter {
const char *name; /*!< \brief human-readable name */
const char *description; /*!< \brief humn-readable description */
unsigned long value; /*!< \brief current value */
+ unsigned long previous; /*!< \brief previous value */
};
/*! \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
*/
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);
diff --git a/src/statistics.c b/src/statistics.c
index e28541ba..ad069cea 100644
--- a/src/statistics.c
+++ b/src/statistics.c
@@ -74,3 +74,11 @@ struct osmo_counter *osmo_counter_get_by_name(const char *name)
}
return NULL;
}
+
+int osmo_counter_difference(struct osmo_counter *ctr)
+{
+ int delta = ctr->value - ctr->previous;
+ ctr->previous = ctr->value;
+
+ return delta;
+}