0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-10 08:07:34 +00:00

Use re2c for the line splitting pluginsd.

Function get's optimized around 3x.

We should delete old code and use the re2c for
the rest of the functions, but we need to keep
the PR size as minimal as possible. Will do in
follow up PRs.
This commit is contained in:
vkalintiris 2024-11-26 12:28:32 +02:00
parent f6673d416b
commit 2b2f9d3887
5 changed files with 190 additions and 4 deletions

View file

@ -702,6 +702,7 @@ set(LIBNETDATA_FILES
src/libnetdata/json/jsmn.h
src/libnetdata/libnetdata.c
src/libnetdata/libnetdata.h
src/libnetdata/line_splitter/re2c_line_splitter.c
src/libnetdata/line_splitter/line_splitter.c
src/libnetdata/line_splitter/line_splitter.h
src/libnetdata/libnetdata.h

View file

@ -1,5 +1,8 @@
# Log
# Line splitter
The netdata log library supports debug, info, error and fatal error logging.
By default we have an access log, an error log and a collectors log.
Common code that handles line splitting into words.
The pluginsd line splitter is generated with re2c because it leads to 3x the
performance of the hand-written line splitter:
`re2c re2c_line_splitter.re.c -o re2c_line_splitter.c`

View file

@ -108,6 +108,8 @@ static inline size_t quoted_strings_splitter(char *str, char **words, size_t max
return i;
}
size_t quoted_strings_splitter_pluginsd_re2c(char *start, char **words, size_t max_words);
#define quoted_strings_splitter_whitespace(str, words, max_words) \
quoted_strings_splitter(str, words, max_words, isspace_map_whitespace)
@ -118,7 +120,7 @@ static inline size_t quoted_strings_splitter(char *str, char **words, size_t max
quoted_strings_splitter(str, words, max_words, isspace_map_config)
#define quoted_strings_splitter_pluginsd(str, words, max_words) \
quoted_strings_splitter(str, words, max_words, isspace_map_pluginsd)
quoted_strings_splitter_pluginsd_re2c(str, words, max_words)
#define quoted_strings_splitter_dyncfg_id(str, words, max_words) \
quoted_strings_splitter(str, words, max_words, isspace_dyncfg_id_map)

View file

@ -0,0 +1,125 @@
/* Generated by re2c 3.0 on Tue Nov 26 12:06:58 2024 */
#line 1 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
#line 4 "src/libnetdata/line_splitter/re2c_line_splitter.c"
#define YYMAXFILL 1
#line 1 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
#include <stddef.h>
size_t quoted_strings_splitter_pluginsd_re2c(char *start, char **words, size_t max_words)
{
size_t count = 0;
const char *YYCURSOR = start;
for (;;) {
#line 18 "src/libnetdata/line_splitter/re2c_line_splitter.c"
{
char yych;
static const unsigned char yybm[] = {
192, 208, 208, 208, 208, 208, 208, 208,
208, 224, 224, 224, 224, 224, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
224, 208, 128, 208, 208, 208, 208, 64,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 224, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
208, 208, 208, 208, 208, 208, 208, 208,
};
yych = *YYCURSOR;
if (yybm[0+yych] & 16) {
goto yy2;
}
if (yych <= 0x00) goto yy1;
if (yych <= ' ') goto yy3;
if (yych <= '"') goto yy4;
if (yych <= '\'') goto yy5;
goto yy3;
yy1:
++YYCURSOR;
#line 23 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
{
return count;
}
#line 70 "src/libnetdata/line_splitter/re2c_line_splitter.c"
yy2:
yych = *++YYCURSOR;
if (yybm[0+yych] & 16) {
goto yy2;
}
#line 35 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
{
if (count == max_words)
return count;
start[YYCURSOR - start] = '\0';
words[count++] = start;
start = (char *) ++YYCURSOR;
continue;
}
#line 86 "src/libnetdata/line_splitter/re2c_line_splitter.c"
yy3:
yych = *++YYCURSOR;
if (yybm[0+yych] & 32) {
goto yy3;
}
#line 44 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
{
start = (char *) YYCURSOR;
continue;
}
#line 97 "src/libnetdata/line_splitter/re2c_line_splitter.c"
yy4:
yych = *++YYCURSOR;
if (yybm[0+yych] & 64) {
goto yy4;
}
goto yy6;
yy5:
yych = *++YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy5;
}
yy6:
++YYCURSOR;
#line 26 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
{
if (count == max_words)
return count;
start++;
start[YYCURSOR - start - 1] = '\0';
words[count++] = start;
continue;
}
#line 121 "src/libnetdata/line_splitter/re2c_line_splitter.c"
}
#line 48 "src/libnetdata/line_splitter/re2c_line_splitter.re.c"
}
}

View file

@ -0,0 +1,55 @@
/*!max:re2c*/
#include <stddef.h>
size_t quoted_strings_splitter_pluginsd_re2c(char *start, char **words, size_t max_words)
{
size_t count = 0;
const char *YYCURSOR = start;
for (;;) {
/*!re2c
re2c:define:YYCTYPE = char;
re2c:yyfill:enable = 0;
single_quotes_word = ["] [^"]* ["];
double_quotes_word = ['] [^']* ['];
unquoted_word = [^= "'\t\n\v\f\r\x00]+;
whitespace = [= \t\n\v\f\r]+;
* {
if (count < max_words)
words[count] = NULL;
return count;
}
[\x00] {
if (count < max_words)
words[count] = NULL;
return count;
}
single_quotes_word | double_quotes_word {
if (count == max_words)
return count;
start++;
start[YYCURSOR - start - 1] = '\0';
words[count++] = start;
continue;
}
unquoted_word {
if (count == max_words)
return count;
start[YYCURSOR - start] = '\0';
words[count++] = start;
start = (char *) ++YYCURSOR;
continue;
}
whitespace {
start = (char *) YYCURSOR;
continue;
}
*/
}
}