6 #include <sys/socket.h>
7 #include <sys/sysctl.h>
9 #include <sys/dkstat.h>
11 #include <machine/apmvar.h>
12 #include <sys/ioctl.h>
13 #include <uvm/uvm_param.h>
14 #include <uvm/uvm_extern.h>
28 void (*statfn[])(int) =
41 static struct nlist nl[] = {
55 if(getloadavg(l, 3) < 0)
57 Bprint(&bout, "load =%d 1000\n", (int)(l[0]*1000.0));
64 struct apm_power_info ai;
67 fd = open("/dev/apm", OREAD);
71 if(ioctl(fd, APM_IOC_GETPOWER, &ai) < 0)
74 if(ai.battery_life <= 100)
75 Bprint(&bout, "battery =%d 100\n", ai.battery_life);
82 char buf[_POSIX2_LINE_MAX];
86 kvm = kvm_openfiles(nil, nil, nil, O_RDONLY, buf);
88 fprint(2, "kvm open error\n%s", buf);
91 if(kvm_nlist(kvm, nl) < 0 || nl[0].n_type == 0){
105 kread(ulong addr, char *buf, int size)
107 if(kvm_read(kvm, addr, buf, size) != size){
108 memset(buf, 0, size);
117 ulong out, in, outb, inb, err;
118 static ulong ifnetaddr;
121 struct ifnet_head ifnethead;
128 ifnetaddr = nl[0].n_value;
133 if(kread(ifnetaddr, (char*)&ifnethead, sizeof ifnethead) < 0)
136 out = in = outb = inb = err = 0;
137 addr = (ulong)TAILQ_FIRST(&ifnethead);
139 if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0
140 || kread((ulong)ifnet.if_xname, name, 16) < 0)
143 addr = (ulong)TAILQ_NEXT(&ifnet, if_list);
144 out += ifnet.if_opackets;
145 in += ifnet.if_ipackets;
146 outb += ifnet.if_obytes;
147 inb += ifnet.if_ibytes;
148 err += ifnet.if_oerrors+ifnet.if_ierrors;
150 Bprint(&bout, "etherin %lud 1000\n", in);
151 Bprint(&bout, "etherout %lud 1000\n", out);
152 Bprint(&bout, "etherinb %lud 1000000\n", inb);
153 Bprint(&bout, "etheroutb %lud 1000000\n", outb);
154 Bprint(&bout, "ethererr %lud 1000\n", err);
155 Bprint(&bout, "ether %lud 1000\n", in+out);
156 Bprint(&bout, "etherb %lud 1000000\n", inb+outb);
164 struct clockinfo *ci;
170 mib[1] = KERN_CLOCKRATE;
172 sysctl(mib, 2, (char *)&x, &l, nil, 0);
177 ci = (struct clockinfo*)x;
184 mib[1] = KERN_CPTIME;
186 sysctl(mib, 2, (char *)&x, &l, nil, 0);
187 if (l < 5*sizeof(ulong))
191 Bprint(&bout, "user %lud %d\n", x[CP_USER]+x[CP_NICE], stathz);
192 Bprint(&bout, "sys %lud %d\n", x[CP_SYS], stathz);
193 Bprint(&bout, "cpu %lud %d\n", x[CP_USER]+x[CP_NICE]+x[CP_SYS], stathz);
194 Bprint(&bout, "idle %lud %d\n", x[CP_IDLE], stathz);
208 sysctl(mib, 2, &vm, &l, nil, 0);
213 pgsize = vm.pagesize;
215 Bprint(&bout, "mem =%lud %lud\n", vm.active*pgsize, vm.npages*pgsize);
216 Bprint(&bout, "context %lud 1000\n", vm.swtch);
217 Bprint(&bout, "syscall %lud 1000\n", vm.syscalls);
218 Bprint(&bout, "intr %lud 1000\n", vm.intrs+vm.traps);
219 Bprint(&bout, "fault %lud 1000\n", vm.faults);
221 Bprint(&bout, "fork %ud 1000\n", vm.forks);
222 Bprint(&bout, "swap =%lud %lud\n", vm.swpginuse*pgsize, vm.swpages*pgsize);