#include #include #include #include "dat.h" void xapm(int); void xloadavg(int); void xmeminfo(int); void xnet(int); void xstat(int); void xvmstat(int); void xwireless(int); void (*statfn[])(int) = { xapm, xloadavg, xmeminfo, xnet, xstat, xvmstat, xwireless, 0 }; void xapm(int first) { static int fd = -1; int curr = -1; if(first){ fd = open("/sys/class/power_supply/BAT0/capacity", OREAD); return; } if(fd == -1) return; readfile(fd); tokens(0); curr = atoi(tok[0]); if(curr != -1) Bprint(&bout, "battery =%d 100\n", curr); } void xloadavg(int first) { static int fd = -1; if(first){ fd = open("/proc/loadavg", OREAD); return; } readfile(fd); tokens(0); if(ntok >= 1) Bprint(&bout, "load =%d 1000\n", (int)(atof(tok[0])*1000)); } void xmeminfo(int first) { int i; vlong tot, used; vlong mtot, mfree; vlong stot, sfree; static int fd = -1; if(first){ fd = open("/proc/meminfo", OREAD); return; } readfile(fd); mtot = 0; stot = 0; mfree = 0; sfree = 0; for(i=0; i= 5){ Bprint(&bout, "user %lld 100\n", atoll(tok[1])); Bprint(&bout, "sys %lld 100\n", atoll(tok[3])); Bprint(&bout, "cpu %lld 100\n", atoll(tok[1])+atoll(tok[3])); Bprint(&bout, "idle %lld 100\n", atoll(tok[4])); } /* if(strcmp(tok[0], "page") == 0 && ntok >= 3){ Bprint(&bout, "pagein %lld 500\n", atoll(tok[1])); Bprint(&bout, "pageout %lld 500\n", atoll(tok[2])); Bprint(&bout, "page %lld 1000\n", atoll(tok[1])+atoll(tok[2])); } if(strcmp(tok[0], "swap") == 0 && ntok >= 3){ Bprint(&bout, "swapin %lld 500\n", atoll(tok[1])); Bprint(&bout, "swapout %lld 500\n", atoll(tok[2])); Bprint(&bout, "swap %lld 1000\n", atoll(tok[1])+atoll(tok[2])); } */ if(strcmp(tok[0], "intr") == 0) Bprint(&bout, "intr %lld 1000\n", atoll(tok[1])); if(strcmp(tok[0], "ctxt") == 0) Bprint(&bout, "context %lld 10000\n", atoll(tok[1])); if(strcmp(tok[0], "processes") == 0) 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