add image statistics to /dev/debug make /dev/debug big enough to do useful stuff Reference: /n/atom/patch/applied/imagestats Date: Thu Jun 12 04:37:41 CES 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/port/portfns.h Thu Jun 12 04:37:08 2014 +++ /sys/src/nix/port/portfns.h Thu Jun 12 04:37:10 2014 @@ -126,6 +126,7 @@ Block* iallocb(int); void iallocsummary(void); void ilock(Lock*); +char* imagestats(char*, char*); int incref(Ref*); void initimage(void); void interruptsummary(void); --- /sys/src/nix/port/image.c Thu Jun 12 04:37:12 2014 +++ /sys/src/nix/port/image.c Thu Jun 12 04:37:14 2014 @@ -18,11 +18,24 @@ } imagealloc; static struct { - int calls; /* times imagereclaim was called */ + int attachimage; /* number of attach images */ + int found; /* number of images found */ + int reclaims; /* times imagereclaim was called */ uvlong ticks; /* total time in the main loop */ uvlong maxt; /* longest time in main loop */ } irstats; +char* +imagestats(char *p, char *e) +{ + p = seprint(p, e, "image reclaims: %d\n", irstats.reclaims); + p = seprint(p, e, "image µs: %lld\n", fastticks2us(irstats.ticks)); + p = seprint(p, e, "image max µs: %lld\n", fastticks2us(irstats.maxt)); + p = seprint(p, e, "image attachimage: %d\n", irstats.attachimage); + p = seprint(p, e, "image found: %d\n", irstats.found); + return p; +} + /* * imagealloc and i must be locked. */ @@ -104,10 +117,9 @@ uint sz; uvlong ticks0, ticks; - irstats.calls++; - /* Somebody is already cleaning the page cache */ if(!canqlock(&imagealloc.ireclaim)) return 0; + irstats.reclaims++; ticks0 = fastticks(nil); sz = pagereclaim(); @@ -127,6 +139,7 @@ Image *i, **l; lock(&imagealloc); + irstats.attachimage++; /* * Search the image cache for remains of the text from a previous @@ -139,6 +152,7 @@ eqqid(c->mqid, i->mqid) && c->mchan == i->mchan && c->dev->dc == i->dc) { + irstats.found++; goto found; } unlock(i); --- /sys/src/nix/port/devcons.c Thu Jun 12 04:37:18 2014 +++ /sys/src/nix/port/devcons.c Thu Jun 12 04:37:19 2014 @@ -822,8 +822,8 @@ { ulong l; Mach *mp; - char *b, *bp, ch, *s, *e, tmp[512]; - int i, k, id, send; + char *b, *bp, ch, *s, *p, *e, tmp[512]; + int i, k, id, send, r; long offset; extern int schedsteals; @@ -1031,16 +1031,27 @@ return n; case Qdebug: - e = tmp + sizeof tmp; - s = seprint(tmp, e, "steal %d\n", schedsteals); - s = seprint(s, e, "locks %llud\n", lockstats.locks); - s = seprint(s, e, "glare %llud\n", lockstats.glare); - s = seprint(s, e, "inglare %llud\n", lockstats.inglare); - s = seprint(s, e, "qlock %llud\n", qlockstats.qlock); - s = seprint(s, e, "qlockq %llud\n", qlockstats.qlockq); - qiostats(s, e); - return readstr(offset, buf, n, tmp); - break; + s = malloc(READSTR); + if(s == nil) + error(Enomem); + if(waserror()){ + free(s); + nexterror(); + } + p = s; + e = s +READSTR; + p = seprint(p, e, "steal %d\n", schedsteals); + p = seprint(p, e, "locks %llud\n", lockstats.locks); + p = seprint(p, e, "glare %llud\n", lockstats.glare); + p = seprint(p, e, "inglare %llud\n", lockstats.inglare); + p = seprint(p, e, "qlock %llud\n", qlockstats.qlock); + p = seprint(p, e, "qlockq %llud\n", qlockstats.qlockq); + p = imagestats(p, e); + qiostats(p, e); + r = readstr(offset, buf, n, s); + poperror(); + free(s); + return r; default: print("consread %#llux\n", c->qid.path); error(Egreg);