cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / iostat_parser.rl
blobdaf888e0572f510060eab5f1db797136dadb6773
1 /*
2  * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3  * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4  */
5 #include "cmogstored.h"
7 %%{
8         machine iostat_parser;
9         eor = '\n' @ { iostat->dev_tip = 0; };
10         ignored_line := ( (any-'\n')* eor ) @ {
11                 if (iostat->ready) {
12                         iostat->ready = false;
13                         mog_iostat_commit();
14                 }
15                 fgoto main;
16         };
18         # Linux device mapper: dm-N
19         device_name = ([a-zA-Z0-9/\-]+){1,71} $ {
20                         if (iostat->dev_tip < (sizeof(iostat->dev)-1))
21                                 iostat->dev[iostat->dev_tip++] = fc;
22                         };
23         utilization = ([0-9\.]+){1,7} > { iostat->util_tip = 0; }
24                  $ {
25                         if (iostat->util_tip < (sizeof(iostat->util)-1))
26                                 iostat->util[iostat->util_tip++] = fc;
27                 };
28         lws = (' '|'\t');
29         stats = lws*
30                 (
31                         device_name
32                         lws+
33                 )
35                 # Skip the middle section for now, some folks may use
36                 # await/svctm here.  Not sure how standardized those
37                 # fields are on non-Linux platforms...
38                 (any - '\n')*
39                 lws+
41                 utilization
42                 lws*
43                 eor > {
44                         mog_iostat_line_done(iostat);
45                         iostat->ready = true;
46                 };
47         main := (stats $! { fhold; fgoto ignored_line; })+;
48 }%%
50 %% write data;
52 void mog_iostat_init(struct mog_iostat *iostat)
54         int cs;
55         struct mog_queue *queue = iostat->queue;
57         memset(iostat, 0, sizeof(struct mog_iostat));
58         %% write init;
59         iostat->cs = cs;
60         iostat->queue = queue;
63 enum mog_parser_state
64 mog_iostat_parse(struct mog_iostat *iostat, char *buf, size_t len)
66         char *p, *pe, *eof = NULL;
67         int cs = iostat->cs;
69         if (cs == iostat_parser_first_final)
70                 return MOG_PARSER_DONE;
72         p = buf;
73         pe = buf + len;
75         %% write exec;
77         iostat->cs = cs;
79         if (cs == iostat_parser_error)
80                 return MOG_PARSER_ERROR;
82         assert(p <= pe && "buffer overflow after iostat parse");
84         if (cs == iostat_parser_first_final)
85                 return MOG_PARSER_DONE;
87         return MOG_PARSER_CONTINUE;