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
|
#include <dirent.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "cmds.h"
#include "libbcachefs.h"
#include "libbcachefs/sb-counters.h"
static const u8 counters_to_stable_map[] = {
#define x(n, id, ...) [BCH_COUNTER_##n] = BCH_COUNTER_STABLE_##n,
BCH_PERSISTENT_COUNTERS()
#undef x
};
static struct bch_ioctl_query_counters *read_counters(struct bchfs_handle fs)
{
struct bch_ioctl_query_counters *ret =
kzalloc(sizeof(*ret) + sizeof(ret->d[0]) * BCH_COUNTER_NR, GFP_KERNEL);
ret->nr = BCH_COUNTER_NR;
xioctl(fs.ioctl_fd, BCH_IOCTL_QUERY_COUNTERS, ret);
return ret;
}
static void fs_top(const char *path, bool human_readable)
{
struct bchfs_handle fs = bcache_fs_open(path);
struct bch_ioctl_query_counters *start = read_counters(fs);
struct bch_ioctl_query_counters *curr = read_counters(fs);
struct bch_ioctl_query_counters *prev = NULL;
while (true) {
sleep(1);
kfree(prev);
prev = curr;
curr = read_counters(fs);
printf("\033[2J");
printf("\033[H");
printf("%-40s %8s %12s\n", "", "2s", "total");
for (unsigned i = 0; i < BCH_COUNTER_NR; i++) {
unsigned stable = counters_to_stable_map[i];
u64 v1 = stable < curr->nr
? curr->d[stable] - prev->d[stable]
: 0;
u64 v2 = stable < curr->nr
? curr->d[stable] - start->d[stable]
: 0;
if (!v2)
continue;
printf("%-40s %8llu %12llu\n",
bch2_counter_names[i],
v1, v2);
}
}
bcache_fs_close(fs);
}
static void fs_top_usage(void)
{
puts("bcachefs fs top - display runtime perfomance info\n"
"Usage: bcachefs fs top [OPTION]... <mountpoint>\n"
"\n"
"Options:\n"
" -h, --human-readable Human readable units\n"
" -H, --help Display this help and exit\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
}
int cmd_fs_top(int argc, char *argv[])
{
static const struct option longopts[] = {
{ "help", no_argument, NULL, 'H' },
{ "human-readable", no_argument, NULL, 'h' },
{ NULL }
};
bool human_readable = false;
int opt;
while ((opt = getopt_long(argc, argv, "Hh",
longopts, NULL)) != -1)
switch (opt) {
case 'h':
human_readable = true;
break;
case 'H':
fs_top_usage();
exit(EXIT_SUCCESS);
default:
fs_top_usage();
exit(EXIT_FAILURE);
}
args_shift(optind);
fs_top(arg_pop() ?: ".", human_readable) ;
return 0;
}
|