bugfix: 1. readmach:a wasn't big enough causing readings of 4 billion odd syscalls -- negative numbers were being generated. 2. (marginal) use log10(nproc) to get the # of digits print("%d", nproc). enhancement: chop a fqdn down to hostname; useful for "stats -lsef `{echo $sysname} tyty.coraid.com" Reference: /n/sources/patch/applied/statssyscall Date: Thu Mar 13 14:58:16 CET 2008 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/stats.c Thu Mar 13 14:53:19 2008 +++ /sys/src/cmd/stats.c Thu Mar 13 14:53:17 2008 @@ -54,6 +54,7 @@ struct Machine { char *name; + char *shortname; int remote; int statsfd; int swapfd; @@ -67,6 +68,7 @@ ulong devsysstat[10]; ulong prevsysstat[10]; int nproc; + int lgproc; ulong netetherstats[8]; ulong prevetherstats[8]; ulong batterystats[2]; @@ -594,6 +596,28 @@ return readnums(m, nelem(m->devswap), a, 0); } +char* +shortname(char *s) +{ + char *p, *e; + + p = estrdup(s); + e = strchr(p, '.'); + if(e) + *e = 0; + return p; +} + +int +ilog10(long j) +{ + int i; + + for(i = 0; j >= 10; i++) + j /= 10; + return i; +} + int initmach(Machine *m, char *name) { @@ -607,6 +631,7 @@ else p = name; m->name = estrdup(p); + m->shortname = shortname(p); m->remote = (strcmp(p, mysysname) != 0); if(m->remote == 0) strcpy(mpt, ""); @@ -643,6 +668,7 @@ m->nproc = n; }else m->nproc = 1; + m->lgproc = ilog10(m->nproc); snprint(buf, sizeof buf, "%s/net/ether0/stats", mpt); m->etherfd = open(buf, OREAD); @@ -719,7 +745,7 @@ readmach(Machine *m, int init) { int n, i; - ulong a[8]; + ulong a[nelem(m->devsysstat)]; char buf[32]; if(m->remote && (m->disable || setjmp(catchalarm))){ @@ -733,6 +759,8 @@ if (strcmp(m->name, buf) != 0){ free(m->name); m->name = estrdup(buf); + free(m->shortname); + m->shortname = shortname(buf); if(display != nil) /* else we're still initializing */ eresized(0); } @@ -1084,13 +1112,13 @@ draw(screen, Rect(x-1, starty-1, x, screen->r.max.y), display->black, nil, ZP); j = dx/stringwidth(mediumfont, "0"); n = mach[i].nproc; - if(n>1 && j>=1+3+(n>10)+(n>100)){ /* first char of name + (n) */ - j -= 3+(n>10)+(n>100); + if(n>1 && j>=1+3+mach[i].lgproc){ /* first char of name + (n) */ + j -= 3+mach[i].lgproc; if(j <= 0) j = 1; - snprint(buf, sizeof buf, "%.*s(%d)", j, mach[i].name, n); + snprint(buf, sizeof buf, "%.*s(%d)", j, mach[i].shortname, n); }else - snprint(buf, sizeof buf, "%.*s", j, mach[i].name); + snprint(buf, sizeof buf, "%.*s", j, mach[i].shortname); string(screen, Pt(x+Labspace, screen->r.min.y + Labspace), display->black, ZP, mediumfont, buf); } @@ -1361,8 +1389,6 @@ parity = 1-parity; for(i=0; i 1000000) - v = 1000000; /* cap absurd values */ graph[i].update(&graph[i], v, vmax); } flushimage(display, 1);