From: Sebastian Harl Date: Wed, 2 Apr 2014 10:37:10 +0000 (+0200) Subject: store: Calculate and store each objects update interval. X-Git-Tag: sysdb-0.1.0~153 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2f08ce28937ba7755da12aa47a4a520ad39694a8;p=sysdb.git store: Calculate and store each objects update interval. The interval is calculated as the moving average of the incoming update intervals. This should also work fine for out-of-order updates or updates from multiple sources. --- diff --git a/src/core/store-private.h b/src/core/store-private.h index abd94c2..a5bf026 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -46,6 +46,7 @@ struct sdb_store_base { /* common meta information */ sdb_time_t last_update; + sdb_time_t interval; /* moving average */ sdb_store_base_t *parent; }; #define STORE_BASE(obj) ((sdb_store_base_t *)(obj)) @@ -81,6 +82,7 @@ enum { /* shortcuts for accessing the sdb_store_obj_t attributes * of inheriting objects */ #define _last_update super.last_update +#define _interval super.interval #ifdef __cplusplus } /* extern "C" */ diff --git a/src/core/store.c b/src/core/store.c index b2fb0f6..6420190 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -67,6 +67,7 @@ store_base_init(sdb_object_t *obj, va_list ap) sobj->type = va_arg(ap, int); sobj->last_update = va_arg(ap, sdb_time_t); + sobj->interval = 0; sobj->parent = NULL; return 0; } /* store_base_init */ @@ -292,7 +293,13 @@ store_obj(int parent_type, const char *parent_name, status = 1; } else { + sdb_time_t interval = last_update - old->last_update; old->last_update = last_update; + if (old->interval) + old->interval = (sdb_time_t)((0.9 * (double)old->interval) + + (0.1 * interval)); + else + old->interval = interval; } if (updated_obj)