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
| | /*
* Copyright (C) 2012-2015 all contributors <cmogstored-public@bogomips.org>
* License: GPLv3 or later (see COPYING for details)
*/
#include "cmogstored.h"
%%{
machine iostat_parser;
eor = '\n' @ { iostat->dev_tip = 0; };
ignored_line := ( (any-'\n')* eor ) @ {
if (iostat->ready) {
iostat->ready = false;
mog_iostat_commit();
}
fgoto main;
};
# Linux device mapper: dm-N
device_name = ([a-zA-Z0-9/\-]+){1,71} $ {
if (iostat->dev_tip < (sizeof(iostat->dev)-1))
iostat->dev[iostat->dev_tip++] = fc;
};
utilization = ([0-9\.]+){1,7} > { iostat->util_tip = 0; }
$ {
if (iostat->util_tip < (sizeof(iostat->util)-1))
iostat->util[iostat->util_tip++] = fc;
};
lws = (' '|'\t');
stats = lws*
(
device_name
lws+
)
# Skip the middle section for now, some folks may use
# await/svctm here. Not sure how standardized those
# fields are on non-Linux platforms...
(any - '\n')*
lws+
utilization
lws*
eor > {
mog_iostat_line_done(iostat);
iostat->ready = true;
};
main := (stats $! { fhold; fgoto ignored_line; })+;
}%%
%% write data;
void mog_iostat_init(struct mog_iostat *iostat)
{
int cs;
struct mog_queue *queue = iostat->queue;
memset(iostat, 0, sizeof(struct mog_iostat));
%% write init;
iostat->cs = cs;
iostat->queue = queue;
}
enum mog_parser_state
mog_iostat_parse(struct mog_iostat *iostat, char *buf, size_t len)
{
char *p, *pe, *eof = NULL;
int cs = iostat->cs;
if (cs == iostat_parser_first_final)
return MOG_PARSER_DONE;
p = buf;
pe = buf + len;
%% write exec;
iostat->cs = cs;
if (cs == iostat_parser_error)
return MOG_PARSER_ERROR;
assert(p <= pe && "buffer overflow after iostat parse");
if (cs == iostat_parser_first_final)
return MOG_PARSER_DONE;
return MOG_PARSER_CONTINUE;
}
|