diff options
author | rbuj <[email protected]> | 2020-12-16 21:28:46 +0100 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2020-12-17 07:29:54 -0500 |
commit | c85a5cf5f08bee3706c0a450a971bfcdd2938a0d (patch) | |
tree | 9b9a238e4b0c4ee51bca59d0d6e41cf27170e68d /multiload/src/autoscaler.c | |
parent | 99d50b247e1ec9714ff5922cea60a29d1a864ff0 (diff) | |
download | mate-applets-c85a5cf5f08bee3706c0a450a971bfcdd2938a0d.tar.bz2 mate-applets-c85a5cf5f08bee3706c0a450a971bfcdd2938a0d.tar.xz |
multiload: use guint64 as data source for graphs
Diffstat (limited to 'multiload/src/autoscaler.c')
-rw-r--r-- | multiload/src/autoscaler.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/multiload/src/autoscaler.c b/multiload/src/autoscaler.c index 735b2713..fb03533f 100644 --- a/multiload/src/autoscaler.c +++ b/multiload/src/autoscaler.c @@ -1,42 +1,44 @@ -#include <time.h> #include <glib.h> #include "autoscaler.h" /* i wish i could have used C99 initializers instead of writing this function */ -void autoscaler_init(AutoScaler *that, unsigned interval, unsigned floor) +void +autoscaler_init (AutoScaler *that, + gint64 interval, + guint64 floor) { that->update_interval = interval; that->floor = floor; that->max = 0; that->count = 0; that->last_update = 0; - that->sum = 0.0f; + that->sum = 0; that->last_average = 0.0f; } - -unsigned autoscaler_get_max(AutoScaler *that, unsigned current) +guint64 +autoscaler_get_max (AutoScaler *that, + guint64 current) { - time_t now; + gint64 now; that->sum += current; that->count++; - time(&now); + now = g_get_monotonic_time (); - if((float)difftime(now, that->last_update) > that->update_interval) + if ((now - that->last_update) > that->update_interval) { - float new_average = that->sum / that->count; + float new_average = (float) that->sum / (float) that->count; float average; - if(new_average < that->last_average) + if (new_average < that->last_average) average = ((that->last_average * 0.5f) + new_average) / 1.5f; else average = new_average; - that->max = average * 1.2f; - - that->sum = 0.0f; + that->max = (guint64) (average * 1.2f); + that->sum = 0; that->count = 0; that->last_update = now; that->last_average = average; |