forked from TACCProjects/tacc_stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdc.c
129 lines (108 loc) · 3.5 KB
/
mdc.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
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include "stats.h"
#include "trace.h"
#include "string1.h"
#include "lustre_obd_to_mnt.h"
#define MDC_DIR_PATH "/proc/fs/lustre/mdc"
#define KEYS \
X(ldlm_cancel, "E", ""), \
X(mds_close, "E", ""), \
X(mds_getattr, "E", ""), \
X(mds_getattr_lock, "E", ""), \
X(mds_getxattr, "E", ""), \
X(mds_readpage, "E", ""), \
X(mds_statfs, "E", ""), \
X(mds_sync, "E", ""), \
X(reqs, "E", ""), \
X(wait, "E,U=us", "")
static void collect_mdc_fs(struct stats *stats, const char *d_name)
{
char *path = NULL;
FILE *file = NULL;
char file_buf[4096];
char *line_buf = NULL;
size_t line_buf_size = 0;
if (asprintf(&path, "%s/%s/stats", MDC_DIR_PATH, d_name) < 0) {
ERROR("cannot create path: %m\n");
goto out;
}
file = fopen(path, "r");
if (file == NULL) {
ERROR("cannot open `%s': %m\n", path);
goto out;
}
setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));
// $ cat /proc/fs/lustre/mdc/work-MDT0000-mdc-ffff8104435c8c00/stats
// snapshot_time 1315505833.280916 secs.usecs
// req_waittime 1885503 samples [usec] 32 4826358 908745020 670751020176306
// req_active 1885503 samples [reqs] 1 357 2176198 17811836
// mds_getattr 231 samples [usec] 50 5735 45029 60616599
// mds_close 312481 samples [usec] 38 356200 47378914 142563767708
// mds_readpage 12187 samples [usec] 80 16719 3185676 4923626688
// mds_connect 1 samples [usec] 302 302 302 91204
// mds_getstatus 1 samples [usec] 273 273 273 74529
// mds_statfs 30 samples [usec] 130 444 7765 2137505
// mds_sync 262 samples [usec] 3042 4826358 33767303 73003166559545
// mds_quotactl 6030 samples [usec] 466 1667578 23448377 4610731893889
// ldlm_cancel 169832 samples [usec] 32 8257 25752413 4873947759
// obd_ping 112820 samples [usec] 40 1543848 548167082 592878039802964
/* Skip snapshot. */
getline(&line_buf, &line_buf_size, file);
while (getline(&line_buf, &line_buf_size, file) >= 0) {
char *line = line_buf;
char *key = wsep(&line);
if (key == NULL || line == NULL)
continue;
unsigned long long count = 0, sum = 0;
if (sscanf(line, "%llu samples %*s %*u %*u %llu", &count, &sum) != 2)
continue;
if (strcmp(key, "req_waittime") == 0) {
stats_set(stats, "reqs", count);
stats_set(stats, "wait", sum);
} else {
stats_set(stats, key, count);
}
}
out:
free(line_buf);
if (file != NULL)
fclose(file);
free(path);
}
static void collect_mdc(struct stats_type *type)
{
const char *mdc_dir_path = MDC_DIR_PATH;
DIR *mdc_dir = NULL;
mdc_dir = opendir(mdc_dir_path);
if (mdc_dir == NULL) {
ERROR("cannot open `%s': %m\n", mdc_dir_path);
goto out;
}
struct dirent *de;
while ((de = readdir(mdc_dir)) != NULL) {
struct stats *stats = NULL;
const char *mnt;
if (de->d_type != DT_DIR || *de->d_name == '.')
continue;
mnt = lustre_obd_to_mnt(de->d_name);
if (mnt == NULL)
continue;
TRACE("d_name `%s', mnt `%s'\n", de->d_name, mnt);
stats = get_current_stats(type, mnt);
if (stats == NULL)
continue;
collect_mdc_fs(stats, de->d_name);
}
out:
if (mdc_dir != NULL)
closedir(mdc_dir);
}
struct stats_type mdc_stats_type = {
.st_name = "mdc",
.st_collect = &collect_mdc,
#define X SCHEMA_DEF
.st_schema_def = JOIN(KEYS),
#undef X
};