summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8f340af)
raw | patch | inline | side by side (parent: 8f340af)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 2 Apr 2014 10:37:10 +0000 (12:37 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 2 Apr 2014 10:37:10 +0000 (12:37 +0200) |
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.
intervals. This should also work fine for out-of-order updates or updates from
multiple sources.
src/core/store-private.h | patch | blob | history | |
src/core/store.c | patch | blob | history |
index abd94c22f1d40dba2e097870abfb5d47b343e9f8..a5bf0267b7e41bd598135ee28048f697ec3d93f7 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
/* 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))
/* 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 b2fb0f602837f62128e09c849b00dde84f1389c0..6420190a319b532ed0db1b2248e4aafd6ee77784 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
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 */
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)