clumpstats.c (2233B)
1 #include "stdinc.h" 2 #include "dat.h" 3 #include "fns.h" 4 5 int count[VtMaxLumpSize][VtMaxType]; 6 Config conf; 7 8 enum 9 { 10 ClumpChunks = 32*1024 11 }; 12 13 static int 14 readarenainfo(Arena *arena) 15 { 16 ClumpInfo *ci, *cis; 17 u32int clump; 18 int i, n, ok; 19 20 if(arena->memstats.clumps) 21 fprint(2, "reading directory for arena=%s with %d entries\n", arena->name, arena->memstats.clumps); 22 23 cis = MKN(ClumpInfo, ClumpChunks); 24 ok = 0; 25 for(clump = 0; clump < arena->memstats.clumps; clump += n){ 26 n = ClumpChunks; 27 28 if(n > arena->memstats.clumps - clump) 29 n = arena->memstats.clumps - clump; 30 31 if((i=readclumpinfos(arena, clump, cis, n)) != n){ 32 seterr(EOk, "arena directory read failed %d not %d: %r", i, n); 33 ok = -1; 34 break; 35 } 36 37 for(i = 0; i < n; i++){ 38 ci = &cis[i]; 39 if(ci->type >= VtMaxType || ci->uncsize >= VtMaxLumpSize) { 40 fprint(2, "bad clump: %d: type = %d: size = %d\n", clump+i, ci->type, ci->uncsize); 41 continue; 42 } 43 count[ci->uncsize][ci->type]++; 44 } 45 } 46 free(cis); 47 if(ok < 0) 48 return TWID32; 49 return clump; 50 } 51 52 static void 53 clumpstats(Index *ix) 54 { 55 int ok; 56 ulong clumps, n; 57 int i, j, t; 58 59 ok = 0; 60 clumps = 0; 61 for(i = 0; i < ix->narenas; i++){ 62 n = readarenainfo(ix->arenas[i]); 63 if(n == TWID32){ 64 ok = -1; 65 break; 66 } 67 clumps += n; 68 } 69 70 if(ok < 0) 71 return; 72 73 print("clumps = %ld\n", clumps); 74 for(i=0; i<VtMaxLumpSize; i++) { 75 t = 0; 76 for(j=0; j<VtMaxType; j++) 77 t += count[i][j]; 78 if(t == 0) 79 continue; 80 print("%d\t%d", i, t); 81 for(j=0; j<VtMaxType; j++) 82 print("\t%d", count[i][j]); 83 print("\n"); 84 } 85 } 86 87 88 void 89 usage(void) 90 { 91 fprint(2, "usage: clumpstats [-B blockcachesize] config\n"); 92 threadexitsall(0); 93 } 94 95 void 96 threadmain(int argc, char *argv[]) 97 { 98 u32int bcmem; 99 100 bcmem = 0; 101 102 ARGBEGIN{ 103 case 'B': 104 bcmem = unittoull(ARGF()); 105 break; 106 default: 107 usage(); 108 break; 109 }ARGEND 110 111 readonly = 1; 112 113 if(argc != 1) 114 usage(); 115 116 if(initventi(argv[0], &conf) < 0) 117 sysfatal("can't init venti: %r"); 118 119 if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16)) 120 bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16); 121 if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem); 122 initdcache(bcmem); 123 124 clumpstats(mainindex); 125 126 threadexitsall(0); 127 }