diff options
authorHarald Welte <laforge@gnumonks.org>2010-05-13 13:28:12 +0200
committerHarald Welte <laforge@gnumonks.org>2010-05-13 13:28:12 +0200
commitd2dce6df04c859e33a79685640ad0a295dcc1421 (patch)
parentcf734784b0433dfa6b77909f83cc3620e523f5d7 (diff)
[rate_ctr] always 'overflow' in next larger inetrval when interval ends
If a second ends, we add the number of events in that just-ended second to the number of events in the currently running minute. The same happens at the end of a minute: We add the number of events in that just-ended minute into the number of events of the still-running hour, etc. This gives a much more meaningful numbers and we don't end up with "12 events per second, but 0 events per minute" kind of situations anymore.
1 files changed, 6 insertions, 0 deletions
diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index e48c779..f58b5c4 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -24,6 +24,7 @@
#include <inttypes.h>
#include <string.h>
+#include <osmocore/utils.h>
#include <osmocore/linuxlist.h>
#include <osmocore/talloc.h>
#include <osmocore/timer.h>
@@ -75,6 +76,11 @@ static void interval_expired(struct rate_ctr *ctr, enum rate_ctr_intv intv)
ctr->intv[intv].rate = ctr->current - ctr->intv[intv].last;
/* save current counter for next interval */
ctr->intv[intv].last = ctr->current;
+ /* update the rate of the next bigger interval. This will
+ * be overwritten when that next larger interval expires */
+ if (intv + 1 < ARRAY_SIZE(ctr->intv))
+ ctr->intv[intv+1].rate += ctr->intv[intv].rate;
static struct timer_list rate_ctr_timer;