7 /* keep in sync with dat.h:/NStat */
8 Statdesc statdesc[NStat] =
13 { "rpc reads failed", },
14 { "rpc read bytes", },
16 { "rpc read cached", },
17 { "rpc read cached time", },
18 { "rpc read uncached", },
19 { "rpc read uncached time "},
22 { "rpc writes new", },
23 { "rpc writes old", },
24 { "rpc writes failed", },
25 { "rpc write bytes", },
26 { "rpc write time", },
27 { "rpc write new time", },
28 { "rpc write old time", },
30 { "lump cache hits", },
31 { "lump cache misses", },
32 { "lump cache reads", },
33 { "lump cache writes", },
34 { "lump cache size", },
35 { "lump cache stall", },
36 { "lump cache read time", },
38 { "disk cache hits", },
39 { "disk cache misses", },
40 { "disk cache lookups", },
41 { "disk cache reads", },
42 { "disk cache writes", },
43 { "disk cache dirty", },
44 { "disk cache size", },
45 { "disk cache flushes", },
46 { "disk cache stalls", },
47 { "disk cache lookup time", },
49 { "disk block stalls", },
52 { "index cache hits", },
53 { "index cache misses", },
54 { "index cache reads", },
55 { "index cache writes", },
56 { "index cache fills", },
57 { "index cache prefetches", },
58 { "index cache dirty", },
59 { "index cache size", },
60 { "index cache flushes", },
61 { "index cache stalls", },
62 { "index cache read time", },
64 { "bloom filter hits", },
65 { "bloom filter misses", },
66 { "bloom filter false misses", },
67 { "bloom filter lookups", },
68 { "bloom filter ones", },
69 { "bloom filter bits", },
70 { "bloom filter lookup time", },
72 { "arena block reads", },
73 { "arena block read bytes", },
74 { "arena block writes", },
75 { "arena block write bytes", },
77 { "isect block reads", },
78 { "isect block read bytes", },
79 { "isect block writes", },
80 { "isect block write bytes", },
83 { "sum read bytes", },
100 stathist[stattime%nstathist] = stats;
110 stathist = MKNZ(Stats, nstathist);
111 vtproc(statsproc, nil);
115 setstat(int index, long val)
118 stats.n[index] = val;
123 addstat(int index, int inc)
128 stats.n[index] += inc;
133 addstat2(int index, int inc, int index1, int inc1)
138 stats.n[index] += inc;
139 stats.n[index1] += inc1;
149 binstats(long (*fn)(Stats *s0, Stats *s1, void *arg), void *arg,
150 long t0, long t1, Statbin *bin, int nbin)
153 int i, j, lo, hi, m, oj;
159 /* negative times mean relative to now. */
164 /* ten minute range if none given */
167 if(0) fprint(2, "stats %ld-%ld\n", t0, t1);
169 /* binary search to find t0-1 or close */
171 hi = stattime+nstathist;
174 if(stathist[m%nstathist].now >= t0)
179 xt0 = stathist[lo%nstathist].now;
180 if(0) fprint(2, "bsearch found %ld\n", xt0);
183 memset(bin, 0, nbin*sizeof bin[0]);
187 hi = stattime+nstathist;
190 for(i=0; i<nbin; i++){
192 te = t0 + (t1-t0)*i/nbin;
194 memset(b, 0, sizeof *b);
197 for(; j<hi && stathist[j%nstathist].now<te; j++){
198 v = fn(&stathist[(j-1)%nstathist], &stathist[j%nstathist], arg);
199 if(b->nsamp==0 || v < b->min)
201 if(b->nsamp==0 || v > b->max)
206 if(0) fprint(2, "bin%d: %ld to %ld; %d to %d - %d samples\n", i, t, te, oj, j, b->nsamp);
208 b->avg = tot / b->nsamp;
209 if(b->nsamp==0 && i>0)