summaryrefslogtreecommitdiff
path: root/multiload/src/autoscaler.c
diff options
context:
space:
mode:
Diffstat (limited to 'multiload/src/autoscaler.c')
-rw-r--r--multiload/src/autoscaler.c28
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;