2 #include "../port/lib.h"
6 #include "../port/error.h"
9 #define LRES 3 /* log of PC resolution */
10 #define SZ 4 /* sizeof of count cell; well known as 4 */
27 ".", {Kprofdirqid, 0, QTDIR}, 0, DMDIR|0550,
28 "kpdata", {Kprofdataqid}, 0, 0600,
29 "kpctl", {Kprofctlqid}, 0, 0600,
33 _kproftimer(uintptr pc)
35 extern void spldone(void);
40 * if the pc is coming out of spllo or splx,
41 * use the pc saved when we went splhi.
43 if(pc>=(uintptr)spllo && pc<=(uintptr)spldone)
46 kprof.buf[0] += TK2MS(1);
47 if(kprof.minpc<=pc && pc<kprof.maxpc){
50 kprof.buf[pc] += TK2MS(1);
52 kprof.buf[1] += TK2MS(1);
58 if(SZ != sizeof kprof.buf[0])
60 kproftimer = _kproftimer;
64 kprofattach(char *spec)
68 /* allocate when first used */
70 kprof.maxpc = (uintptr)etext;
71 kprof.nbuf = (kprof.maxpc-kprof.minpc) >> LRES;
74 kprof.buf = xalloc(n);
78 kproftab[1].length = n;
79 return devattach('K', spec);
83 kprofwalk(Chan *c, Chan *nc, char **name, int nname)
85 return devwalk(c, nc, name, nname, kproftab, nelem(kproftab), devgen);
89 kprofstat(Chan *c, uchar *db, int n)
91 return devstat(c, db, n, kproftab, nelem(kproftab), devgen);
95 kprofopen(Chan *c, int omode)
97 if(c->qid.type == QTDIR){
101 c->mode = openmode(omode);
113 kprofread(Chan *c, void *va, long n, vlong off)
120 switch((int)c->qid.path){
122 return devdirread(c, va, n, kproftab, nelem(kproftab), devgen);
137 bp = kprof.buf + offset/SZ;
155 kprofwrite(Chan *c, void *a, long n, vlong)
157 switch((int)(c->qid.path)){
159 if(strncmp(a, "startclr", 8) == 0){
160 memset((char *)kprof.buf, 0, kprof.nbuf*SZ);
162 }else if(strncmp(a, "start", 5) == 0)
164 else if(strncmp(a, "stop", 4) == 0)