a big error has been sitting in e-cpu for... years... DONT assume HZ is 100. :)

SVN revision: 8096
This commit is contained in:
Carsten Haitzler 2003-12-11 21:45:59 +00:00
parent ee786e20c9
commit 6818a3841f
1 changed files with 21 additions and 21 deletions

View File

@ -16,6 +16,7 @@
int cpus = 0;
double *prev_val = NULL;
double *prev_val_nice = NULL;
double *prev_val_total = NULL;
int *load_val = NULL;
Window win;
RGB_buf buf;
@ -238,35 +239,33 @@ cb_timer(void *data)
for (i = 0; i < cpus; i++)
{
char sUserCPU[64];
char sNiceCPU[64];
double val, val2, val_nice, val2_nice;
char sNiceCPU[64];
char sSystemCPU[64];
char sTotalCPU[64];
double val, val2, val_nice, val2_nice, val_total;
fgets(s, 255, f);
sscanf(s, "%*s %s %s %*s %*s", sUserCPU, sNiceCPU);
sscanf(s, "%*s %s %s %s %s",
sUserCPU, sNiceCPU, sSystemCPU, sTotalCPU);
val = atof(sUserCPU);
val_nice = atof(sNiceCPU);
val_total = atof(sTotalCPU);
val2 = val - prev_val[i];
val2 = 100 * (val - prev_val[i]) / (val_total - prev_val_total[i]);
if (val2 > 100) val2 = 100;
val2_nice = 100 * (val_nice - prev_val_nice[i]) / (val_total - prev_val_total[i]);
if (val2_nice > 100) val2_nice = 100;
prev_val[i] = val;
val2 *= 10;
if (val2 > 100)
val2 = 100;
val2_nice = val_nice - prev_val_nice[i];
prev_val_nice[i] = val_nice;
val2_nice *= 10;
if (val2_nice > 100)
val2_nice = 100;
if (include_nice)
load_val[i] = val2 + val2_nice;
else
load_val[i] = val2;
if (load_val[i] > 100)
load_val[i] = 100;
prev_val_nice[i] = val_nice;
prev_val_total[i] = val_total;
if (include_nice) load_val[i] = val2 + val2_nice;
else load_val[i] = val2;
if (load_val[i] > 100) load_val[i] = 100;
}
fclose(f);
}
@ -451,6 +450,7 @@ main(int argc, char **argv)
load_val = malloc(sizeof(int) * cpus);
prev_val = malloc(sizeof(double) * cpus);
prev_val_nice = malloc(sizeof(double) * cpus);
prev_val_total = malloc(sizeof(double) * cpus);
Epplet_Init("E-Cpu", "0.1", "Enlightenment CPU Epplet",
3, 3, argc, argv, 0);