stats: handle /dev/sysstat 32bit overflow in delta calculation

the numbers from /dev/sysstat overflow on 32bit, so have
to do subtraction modulo 2^32 as we calculate with 64bit
integers.

thanks mischief for reporting this.
This commit is contained in:
cinap_lenrek 2014-09-20 18:06:59 +02:00
parent 19a8f66eec
commit 2604bc3603

View file

@ -353,6 +353,10 @@ datapoint(Graph *g, int x, uvlong v, uvlong vmax)
y = (y+2.)/3.; y = (y+2.)/3.;
} }
} }
if(y >= 1.)
y = 1;
if(y <= 0.)
y = 0;
p.y = g->r.max.y - Dy(g->r)*y - Dot; p.y = g->r.max.y - Dy(g->r)*y - Dot;
if(p.y < g->r.min.y) if(p.y < g->r.min.y)
p.y = g->r.min.y; p.y = g->r.min.y;
@ -830,7 +834,7 @@ swapval(Machine *m, uvlong *v, uvlong *vmax, int)
void void
contextval(Machine *m, uvlong *v, uvlong *vmax, int init) contextval(Machine *m, uvlong *v, uvlong *vmax, int init)
{ {
*v = m->devsysstat[Context]-m->prevsysstat[Context]; *v = (m->devsysstat[Context]-m->prevsysstat[Context])&0xffffffff;
*vmax = sleeptime*m->nproc; *vmax = sleeptime*m->nproc;
if(init) if(init)
*vmax = sleeptime; *vmax = sleeptime;
@ -842,7 +846,7 @@ contextval(Machine *m, uvlong *v, uvlong *vmax, int init)
void void
intrval(Machine *m, uvlong *v, uvlong *vmax, int init) intrval(Machine *m, uvlong *v, uvlong *vmax, int init)
{ {
*v = m->devsysstat[Interrupt]-m->prevsysstat[Interrupt]; *v = (m->devsysstat[Interrupt]-m->prevsysstat[Interrupt])&0xffffffff;
*vmax = sleeptime*m->nproc*10; *vmax = sleeptime*m->nproc*10;
if(init) if(init)
*vmax = sleeptime*10; *vmax = sleeptime*10;
@ -851,7 +855,7 @@ intrval(Machine *m, uvlong *v, uvlong *vmax, int init)
void void
syscallval(Machine *m, uvlong *v, uvlong *vmax, int init) syscallval(Machine *m, uvlong *v, uvlong *vmax, int init)
{ {
*v = m->devsysstat[Syscall]-m->prevsysstat[Syscall]; *v = (m->devsysstat[Syscall]-m->prevsysstat[Syscall])&0xffffffff;
*vmax = sleeptime*m->nproc; *vmax = sleeptime*m->nproc;
if(init) if(init)
*vmax = sleeptime; *vmax = sleeptime;
@ -860,7 +864,7 @@ syscallval(Machine *m, uvlong *v, uvlong *vmax, int init)
void void
faultval(Machine *m, uvlong *v, uvlong *vmax, int init) faultval(Machine *m, uvlong *v, uvlong *vmax, int init)
{ {
*v = m->devsysstat[Fault]-m->prevsysstat[Fault]; *v = (m->devsysstat[Fault]-m->prevsysstat[Fault])&0xffffffff;
*vmax = sleeptime*m->nproc; *vmax = sleeptime*m->nproc;
if(init) if(init)
*vmax = sleeptime; *vmax = sleeptime;
@ -869,7 +873,7 @@ faultval(Machine *m, uvlong *v, uvlong *vmax, int init)
void void
tlbmissval(Machine *m, uvlong *v, uvlong *vmax, int init) tlbmissval(Machine *m, uvlong *v, uvlong *vmax, int init)
{ {
*v = m->devsysstat[TLBfault]-m->prevsysstat[TLBfault]; *v = (m->devsysstat[TLBfault]-m->prevsysstat[TLBfault])&0xffffffff;
*vmax = (sleeptime/1000)*10*m->nproc; *vmax = (sleeptime/1000)*10*m->nproc;
if(init) if(init)
*vmax = (sleeptime/1000)*10; *vmax = (sleeptime/1000)*10;
@ -878,7 +882,7 @@ tlbmissval(Machine *m, uvlong *v, uvlong *vmax, int init)
void void
tlbpurgeval(Machine *m, uvlong *v, uvlong *vmax, int init) tlbpurgeval(Machine *m, uvlong *v, uvlong *vmax, int init)
{ {
*v = m->devsysstat[TLBpurge]-m->prevsysstat[TLBpurge]; *v = (m->devsysstat[TLBpurge]-m->prevsysstat[TLBpurge])&0xffffffff;
*vmax = (sleeptime/1000)*10*m->nproc; *vmax = (sleeptime/1000)*10*m->nproc;
if(init) if(init)
*vmax = (sleeptime/1000)*10; *vmax = (sleeptime/1000)*10;