aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/venti/srv/clumpstats.c
blob: d2cfe251c3d6697bf886d734761bd964d92e23cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "stdinc.h"
#include "dat.h"
#include "fns.h"

int	count[VtMaxLumpSize][VtMaxType];
Config conf;

enum
{
	ClumpChunks	= 32*1024
};

static int
readarenainfo(Arena *arena)
{
	ClumpInfo *ci, *cis;
	u32int clump;
	int i, n, ok;

	if(arena->memstats.clumps)
		fprint(2, "reading directory for arena=%s with %d entries\n", arena->name, arena->memstats.clumps);

	cis = MKN(ClumpInfo, ClumpChunks);
	ok = 0;
	for(clump = 0; clump < arena->memstats.clumps; clump += n){
		n = ClumpChunks;

		if(n > arena->memstats.clumps - clump)
			n = arena->memstats.clumps - clump;

		if((i=readclumpinfos(arena, clump, cis, n)) != n){
			seterr(EOk, "arena directory read failed %d not %d: %r", i, n);
			ok = -1;
			break;
		}

		for(i = 0; i < n; i++){
			ci = &cis[i];
			if(ci->type >= VtMaxType || ci->uncsize >= VtMaxLumpSize) {
				fprint(2, "bad clump: %d: type = %d: size = %d\n", clump+i, ci->type, ci->uncsize);
				continue;
			}
			count[ci->uncsize][ci->type]++;
		}
	}
	free(cis);
	if(ok < 0)
		return TWID32;
	return clump;
}

static void
clumpstats(Index *ix)
{
	int ok;
	ulong clumps, n;
	int i, j, t;

	ok = 0;
	clumps = 0;
	for(i = 0; i < ix->narenas; i++){
		n = readarenainfo(ix->arenas[i]);
		if(n == TWID32){
			ok = -1;
			break;
		}
		clumps += n;
	}

	if(ok < 0)
		return;

	print("clumps = %ld\n", clumps);
	for(i=0; i<VtMaxLumpSize; i++) {
		t = 0;
		for(j=0; j<VtMaxType; j++)
			t += count[i][j];
		if(t == 0)
			continue;
		print("%d\t%d", i, t);
		for(j=0; j<VtMaxType; j++)
			print("\t%d", count[i][j]);
		print("\n");
	}
}


void
usage(void)
{
	fprint(2, "usage: clumpstats [-B blockcachesize] config\n");
	threadexitsall(0);
}

void
threadmain(int argc, char *argv[])
{
	u32int bcmem;

	bcmem = 0;

	ARGBEGIN{
	case 'B':
		bcmem = unittoull(ARGF());
		break;
	default:
		usage();
		break;
	}ARGEND

	readonly = 1;

	if(argc != 1)
		usage();

	if(initventi(argv[0], &conf) < 0)
		sysfatal("can't init venti: %r");

	if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
		bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
	if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
	initdcache(bcmem);

	clumpstats(mainindex);
	
	threadexitsall(0);
}