stats: make more stats work in Linux

http://codereview.appspot.com/96084
This commit is contained in:
Fazlul Shahriar 2009-08-08 16:45:27 -04:00
parent 0e9f3966da
commit 3c6ab1854e
3 changed files with 77 additions and 7 deletions

View file

@ -105,6 +105,11 @@ number of system calls per second.
number of valid pages on the swap device. number of valid pages on the swap device.
The swap is displayed as a The swap is displayed as a
fraction of the number of swap pages configured by the machine. fraction of the number of swap pages configured by the machine.
.TP
.B "8 802.11b
display the signal strength detected by the 802.11b wireless ether card; the value
is usually below 50% unless the receiver is in the same room as the transmitter, so
a midrange value represents a strong signal.
.PD .PD
.PP .PP
The graphs are plotted with time on the horizontal axis. The graphs are plotted with time on the horizontal axis.

View file

@ -8,6 +8,8 @@ void xloadavg(int);
void xmeminfo(int); void xmeminfo(int);
void xnet(int); void xnet(int);
void xstat(int); void xstat(int);
void xvmstat(int);
void xwireless(int);
void (*statfn[])(int) = void (*statfn[])(int) =
{ {
@ -16,6 +18,8 @@ void (*statfn[])(int) =
xmeminfo, xmeminfo,
xnet, xnet,
xstat, xstat,
xvmstat,
xwireless,
0 0
}; };
@ -77,6 +81,7 @@ xmeminfo(int first)
int i; int i;
vlong tot, used; vlong tot, used;
vlong mtot, mfree; vlong mtot, mfree;
vlong stot, sfree;
static int fd = -1; static int fd = -1;
if(first){ if(first){
@ -86,6 +91,9 @@ xmeminfo(int first)
readfile(fd); readfile(fd);
mtot = 0; mtot = 0;
stot = 0;
mfree = 0;
sfree = 0;
for(i=0; i<nline; i++){ for(i=0; i<nline; i++){
tokens(i); tokens(i);
if(ntok < 3) if(ntok < 3)
@ -98,11 +106,22 @@ xmeminfo(int first)
Bprint(&bout, "swap =%lld %lld\n", used/1024, tot/1024); Bprint(&bout, "swap =%lld %lld\n", used/1024, tot/1024);
else if(strcmp(tok[0], "MemTotal:") == 0) else if(strcmp(tok[0], "MemTotal:") == 0)
mtot = atoll(tok[1]); /* kb */ mtot = atoll(tok[1]); /* kb */
else if(strcmp(tok[0], "MemFree:") == 0){ else if(strcmp(tok[0], "MemFree:") == 0)
mfree = atoll(tok[1]); mfree += atoll(tok[1]);
else if(strcmp(tok[0], "Buffers:") == 0)
mfree += atoll(tok[1]);
else if(strcmp(tok[0], "Cached:") == 0){
mfree += atoll(tok[1]);
if(mtot < mfree) if(mtot < mfree)
continue; continue;
Bprint(&bout, "mem =%lld %lld\n", mtot-mfree, mtot); Bprint(&bout, "mem =%lld %lld\n", mtot-mfree, mtot);
}else if(strcmp(tok[0], "SwapTotal:") == 0)
stot = atoll(tok[1]); /* kb */
else if(strcmp(tok[0], "SwapFree:") == 0){
sfree = atoll(tok[1]);
if(stot < sfree)
continue;
Bprint(&bout, "swap =%lld %lld\n", stot-sfree, stot);
} }
} }
} }
@ -135,7 +154,7 @@ xnet(int first)
tokens(i); tokens(i);
if(ntok < 8+8) if(ntok < 8+8)
continue; continue;
if(strncmp(tok[0], "eth", 3) != 0) if(strncmp(tok[0], "eth", 3) != 0 && strncmp(tok[0], "wlan", 4) != 0)
continue; continue;
inb = atoll(tok[1]); inb = atoll(tok[1]);
oub = atoll(tok[9]); oub = atoll(tok[9]);
@ -182,7 +201,7 @@ xstat(int first)
Bprint(&bout, "user %lld 100\n", atoll(tok[1])); Bprint(&bout, "user %lld 100\n", atoll(tok[1]));
Bprint(&bout, "sys %lld 100\n", atoll(tok[3])); Bprint(&bout, "sys %lld 100\n", atoll(tok[3]));
Bprint(&bout, "cpu %lld 100\n", atoll(tok[1])+atoll(tok[3])); Bprint(&bout, "cpu %lld 100\n", atoll(tok[1])+atoll(tok[3]));
Bprint(&bout, "idle %lld\n", atoll(tok[4])); Bprint(&bout, "idle %lld 100\n", atoll(tok[4]));
} }
/* /*
if(strcmp(tok[0], "page") == 0 && ntok >= 3){ if(strcmp(tok[0], "page") == 0 && ntok >= 3){
@ -197,11 +216,52 @@ xstat(int first)
} }
*/ */
if(strcmp(tok[0], "intr") == 0) if(strcmp(tok[0], "intr") == 0)
Bprint(&bout, "interrupt %lld 1000\n", atoll(tok[1])); Bprint(&bout, "intr %lld 1000\n", atoll(tok[1]));
if(strcmp(tok[0], "ctxt") == 0) if(strcmp(tok[0], "ctxt") == 0)
Bprint(&bout, "context %lld 1000\n", atoll(tok[1])); Bprint(&bout, "context %lld 10000\n", atoll(tok[1]));
if(strcmp(tok[0], "processes") == 0) if(strcmp(tok[0], "processes") == 0)
Bprint(&bout, "fork %lld 1000\n", atoll(tok[1])); Bprint(&bout, "fork %lld 1000\n", atoll(tok[1]));
} }
} }
void
xvmstat(int first)
{
static int fd = -1;
int i;
if(first){
fd = open("/proc/vmstat", OREAD);
return;
}
readfile(fd);
for(i=0; i<nline; i++){
tokens(i);
if(ntok < 2)
continue;
if(strcmp(tok[0], "pgfault") == 0)
Bprint(&bout, "fault %lld 100000\n", atoll(tok[1]));
}
}
void
xwireless(int first)
{
static int fd = -1;
int i;
if(first){
fd = open("/proc/net/wireless", OREAD);
return;
}
readfile(fd);
for(i=0; i<nline; i++){
tokens(i);
if(ntok < 3)
continue;
if(strcmp(tok[0], "wlan0:") == 0)
Bprint(&bout, "802.11 =%lld 100\n", atoll(tok[2]));
}
}

View file

@ -28,6 +28,7 @@ enum
enum enum
{ {
V80211,
Vbattery, Vbattery,
Vcontext, Vcontext,
Vcpu, Vcpu,
@ -51,6 +52,7 @@ enum
char* char*
labels[Nvalue] = labels[Nvalue] =
{ {
"802.11",
"battery", "battery",
"context", "context",
"cpu", "cpu",
@ -109,7 +111,7 @@ Machine *mach;
Font *mediumfont; Font *mediumfont;
char *fontname; char *fontname;
char *mysysname; char *mysysname;
char argchars[] = "bcCeEfiIlmnsw"; char argchars[] = "8bcCeEfiIlmnsw";
int pids[1024]; int pids[1024];
int parity; /* toggled to avoid patterns in textured background */ int parity; /* toggled to avoid patterns in textured background */
int nmach; int nmach;
@ -748,6 +750,9 @@ threadmain(int argc, char *argv[])
default: default:
fprint(2, "stats: internal error: unknown arg %c\n", args[i]); fprint(2, "stats: internal error: unknown arg %c\n", args[i]);
usage(); usage();
case '8':
addgraph(V80211);
break;
case 'b': case 'b':
addgraph(Vbattery); addgraph(Vbattery);
break; break;