-
Notifications
You must be signed in to change notification settings - Fork 2
/
bolo-slabinfo.c
134 lines (117 loc) · 3.3 KB
/
bolo-slabinfo.c
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
128
129
130
131
132
133
134
#include "bolo.h"
#include <getopt.h>
#include <time.h>
int
do_slabinfo(int argc, char **argv)
{
struct tslab slab;
const char *path;
int i, j, k, rc, fd;
int tcells, nvalid;
double full, bitsper;
char unit;
{
int idx = 0;
char c, *shorts = "hD";
struct option longs[] = {
{"help", no_argument, 0, 'h'},
{"debug", no_argument, 0, 'D'},
{0, 0, 0, 0},
};
while ((c = getopt_long(argc, argv, shorts, longs, &idx)) >= 0) {
switch (c) {
case 'h':
printf("USAGE: %s slabinfo [--debug] /path/to/slab ...\n\n", argv[0]);
printf("OPTIONS:\n\n");
printf(" -h, --help Show this help screen.\n\n");
printf(" -D, --debug Enable debugging mode.\n"
" (mostly useful only to bolo devs).\n\n");
return 0;
case 'D':
debugto(fileno(stderr));
break;
}
}
}
if (argc < optind+2) {
fprintf(stderr, "USAGE: %s slabinfo [--debug] /path/to/slab ...\n\n", argv[0]);
return 1;
}
for (i = optind+1; i < argc; i++) {
path = argv[i];
fd = open(path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "failed to open %s: %s\n", path, error(errno));
continue;
}
memset(&slab, 0, sizeof(slab));
rc = tslab_map(&slab, fd);
if (rc != 0) {
fprintf(stderr, "failed to map %s: %s\n", path, error(errno));
continue;
}
tcells = nvalid = 0;
for (j = 0; j < TBLOCKS_PER_TSLAB; j++) {
if (!slab.blocks[j].valid)
break;
nvalid++;
}
fprintf(stdout, "%s:\n", path);
fprintf(stdout, "slab %lu (%#016lx) %dk %d/%d blocks present\n",
slab.number, slab.number, slab.block_size / 1024, nvalid, TBLOCKS_PER_TSLAB);
for (j = 0; j < TBLOCKS_PER_TSLAB; j++) {
uint32_t span, tmp;
char date[64];
struct tm tm;
time_t ts;
unsigned d, h, m, s, ms;
if (!slab.blocks[j].valid)
break;
tcells += slab.blocks[j].cells;
full = 100.0 * slab.blocks[j].cells / TCELLS_PER_TBLOCK;
unit = 'b';
bitsper = (TBLOCK_SIZE * 8.0) / slab.blocks[j].cells;
if (bitsper > 1024.0) {
bitsper /= 1024.0;
unit = 'k';
}
span = 0;
for (k = 0; k < slab.blocks[j].cells; k++) {
tmp = tblock_read32(slab.blocks+j, 32 + k * 12);
if (tmp > span)
span = tmp;
}
ms = span % 1000; span /= 1000;
s = span % 60; span /= 60;
m = span % 60; span /= 60;
h = span % 24; span /= 24;
d = span;
ts = (time_t)(slab.blocks[j].base / 1000);
if (!localtime_r(&ts, &tm))
strcpy(date, "xxx, xx xx xxxx xx:xx:xx+xxxx");
else
strftime(date, 64, "%a, %d %b %Y %H:%M:%S%z", &tm);
fprintf(stdout, " @%lu (%#016lx) ts %lu [%s] % 6i measurements;"
" %6.2lf%% full, spanning %2ud %02u:%02u:%02u.%04u;"
" %7.2lf%c/measurement\n",
slab.blocks[j].number, slab.blocks[j].number,
slab.blocks[j].base, date,
slab.blocks[j].cells,
full, d, h, m, s, ms,
bitsper, unit);
}
/* totals */
full = 100.0 * tcells / (TCELLS_PER_TBLOCK * nvalid);
unit = 'b';
bitsper = (nvalid * TBLOCK_SIZE * 8.0) / tcells;
if (bitsper > 1024.0) {
bitsper /= 1024.0;
unit = 'k';
}
fprintf(stdout, " total %i measurements (%6.2lf%% full)\n", tcells, full);
fprintf(stdout, " average %0.2lf%c/measurement\n", bitsper, unit);
if (tslab_unmap(&slab) != 0)
fprintf(stderr, "failed to unmap %s...\n", path);
}
return 0;
}