Commit 86cfebc3 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(dump_stats): Updated to cope with the introduction of enum value_type.

(ind): Changed sign of the "offset" argument, since it is a bad
	idea to store a negative number in an "unsigned int".  All
	callers updated.
(update_one_stat): Fixed the call to check_stat when DEBUG_STATS
	is true.
(check_one_stat): If a rounding error occurs, log which enum
	value_type that is responsible.
parent 52414a93
......@@ -83,12 +83,15 @@ static const int factors[] = {
FACT_3,
};
static int
check_stat(enum stat_type st,
const char *when);
static int
ind(unsigned long sec,
unsigned int offset)
{
int ret = (sec + offset) % HISTORY_LENGTH;
int ret = (sec - offset) % HISTORY_LENGTH;
assert(ret >= 0);
assert(ret < HISTORY_LENGTH);
return ret;
......@@ -97,32 +100,38 @@ ind(unsigned long sec,
#ifdef DEBUG_STATS
static void
dump_stats(struct avg_status *s)
dump_stats(struct avg_status s[NUM_STAT][NUM_VT])
{
int st;
enum stat_type st;
enum value_type vt;
int i;
fprintf(stderr, "START DUMP\n");
for (st = 0; st < NUM_STAT; st++)
for (vt = 0; vt < NUM_VT; vt++)
{
fprintf(stderr, "stats for type %d: when=%ld:%ld value=%ld acc=%f\n",
st, (long)s[st].when.tv_sec, (long)s[st].when.tv_usec,
s[st].value, s[st].acc);
fprintf(stderr, " indices:");
fprintf(stderr, " ():0:%d", ind(s[st].when.tv_sec, 0));
for (i = 0; i < N_FACTS; i++)
fprintf(stderr, " %d:%d:%d", i, factors[i], ind(s[st].when.tv_sec,
-factors[i]));
fprintf(stderr, "\n avenrun:");
for (i = 0; i < N_FACTS; i++)
fprintf(stderr, " %f", s[st].avenrun[i]);
fprintf(stderr, "\n updates:");
for (i = 0; i < N_FACTS; i++)
fprintf(stderr, " %ld", s[st].updates[i]);
fprintf(stderr, "\n history:");
for (i = 0; i < HISTORY_LENGTH; i++)
fprintf(stderr, " %f", s[st].avg_history[i]);
fprintf(stderr, "\n");
fprintf(stderr, "value_type %d:\n", (int)vt);
for (st = 0; st < NUM_STAT; st++)
{
fprintf(stderr, "stat_type %d: when=%ld:%ld value=%ld acc=%f\n",
(int)st,
(long)s[st][vt].when.tv_sec, (long)s[st][vt].when.tv_usec,
s[st][vt].value, s[st][vt].acc);
fprintf(stderr, " indices:");
fprintf(stderr, " ():0:%d", ind(s[st][vt].when.tv_sec, 0));
for (i = 0; i < N_FACTS; i++)
fprintf(stderr, " %d:%d:%d", i, factors[i],
ind(s[st][vt].when.tv_sec, factors[i]));
fprintf(stderr, "\n avenrun:");
for (i = 0; i < N_FACTS; i++)
fprintf(stderr, " %f", s[st][vt].avenrun[i]);
fprintf(stderr, "\n updates:");
for (i = 0; i < N_FACTS; i++)
fprintf(stderr, " %ld", s[st][vt].updates[i]);
fprintf(stderr, "\n history:");
for (i = 0; i < HISTORY_LENGTH; i++)
fprintf(stderr, " %f", s[st][vt].avg_history[i]);
fprintf(stderr, "\n");
}
}
}
#endif
......@@ -168,7 +177,7 @@ update_history(struct avg_status *s,
{
for (i = 0; i < N_FACTS; i++)
s->avenrun[i] += (value - s->avg_history[ind(s->when.tv_sec,
-factors[i])])
factors[i])])
/ (double)factors[i];
s->avg_history[ind(s->when.tv_sec, 0)] = value;
}
......@@ -255,7 +264,7 @@ update_one_stat(enum stat_type st,
s->value = 0;
}
#ifdef DEBUG_STATS
if (check_stat("update_stat") > 0)
if (check_stat(st, "update_stat") > 0)
{
kom_log("This was caused by an update of delta=%ld for type %d\n",
delta, st);
......@@ -306,7 +315,7 @@ check_one_stat(enum stat_type st,
acc = 0;
for (i = 0; i < factors[f]; i++)
{
val = s->avg_history[ind(s->when.tv_sec, -i-1)];
val = s->avg_history[ind(s->when.tv_sec, i+1)];
assert(val >= 0);
acc += val;
}
......@@ -318,9 +327,9 @@ check_one_stat(enum stat_type st,
|| (acc >= 1e-6 && err / acc > 0.01))
{
kom_log("Accumulated rounding errors fixed (%s) after"
" %ld updates (type=%d, f=%d, factor=%d): %f => %f\n",
" %ld updates (st=%d, vt=%d, f=%d, factor=%d): %f => %f\n",
when,
s->updates[f], st, f, factors[f], s->avenrun[f], acc);
s->updates[f], st, vt, f, factors[f], s->avenrun[f], acc);
s->avenrun[f] = acc;
s->updates[f] = 0;
changes++;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment