tclumpstats.c - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
tclumpstats.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; inarenas + 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 }