mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
tracing/filters: Unify the regex parsing helpers
The filter code has stolen the regex parsing function from ftrace to get the regex support. We have duplicated this code, so factorize it in the filter area and make it generally available, as the filter code is the most suited to host this feature. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Tom Zanussi <tzanussi@gmail.com> Cc: Li Zefan <lizf@cn.fujitsu.com>
This commit is contained in:
parent
1889d20922
commit
3f6fe06dbf
3 changed files with 23 additions and 70 deletions
|
@ -1655,60 +1655,6 @@ ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
|
||||||
MATCH_FULL,
|
|
||||||
MATCH_FRONT_ONLY,
|
|
||||||
MATCH_MIDDLE_ONLY,
|
|
||||||
MATCH_END_ONLY,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (static function - no need for kernel doc)
|
|
||||||
*
|
|
||||||
* Pass in a buffer containing a glob and this function will
|
|
||||||
* set search to point to the search part of the buffer and
|
|
||||||
* return the type of search it is (see enum above).
|
|
||||||
* This does modify buff.
|
|
||||||
*
|
|
||||||
* Returns enum type.
|
|
||||||
* search returns the pointer to use for comparison.
|
|
||||||
* not returns 1 if buff started with a '!'
|
|
||||||
* 0 otherwise.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
ftrace_setup_glob(char *buff, int len, char **search, int *not)
|
|
||||||
{
|
|
||||||
int type = MATCH_FULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (buff[0] == '!') {
|
|
||||||
*not = 1;
|
|
||||||
buff++;
|
|
||||||
len--;
|
|
||||||
} else
|
|
||||||
*not = 0;
|
|
||||||
|
|
||||||
*search = buff;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
if (buff[i] == '*') {
|
|
||||||
if (!i) {
|
|
||||||
*search = buff + 1;
|
|
||||||
type = MATCH_END_ONLY;
|
|
||||||
} else {
|
|
||||||
if (type == MATCH_END_ONLY)
|
|
||||||
type = MATCH_MIDDLE_ONLY;
|
|
||||||
else
|
|
||||||
type = MATCH_FRONT_ONLY;
|
|
||||||
buff[i] = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ftrace_match(char *str, char *regex, int len, int type)
|
static int ftrace_match(char *str, char *regex, int len, int type)
|
||||||
{
|
{
|
||||||
int matched = 0;
|
int matched = 0;
|
||||||
|
@ -1757,7 +1703,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
|
||||||
int not;
|
int not;
|
||||||
|
|
||||||
flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
|
flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
|
||||||
type = ftrace_setup_glob(buff, len, &search, ¬);
|
type = filter_parse_regex(buff, len, &search, ¬);
|
||||||
|
|
||||||
search_len = strlen(search);
|
search_len = strlen(search);
|
||||||
|
|
||||||
|
@ -1825,7 +1771,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(buff)) {
|
if (strlen(buff)) {
|
||||||
type = ftrace_setup_glob(buff, strlen(buff), &search, ¬);
|
type = filter_parse_regex(buff, strlen(buff), &search, ¬);
|
||||||
search_len = strlen(search);
|
search_len = strlen(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1990,7 +1936,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *search;
|
char *search;
|
||||||
|
|
||||||
type = ftrace_setup_glob(glob, strlen(glob), &search, ¬);
|
type = filter_parse_regex(glob, strlen(glob), &search, ¬);
|
||||||
len = strlen(search);
|
len = strlen(search);
|
||||||
|
|
||||||
/* we do not support '!' for function probes */
|
/* we do not support '!' for function probes */
|
||||||
|
@ -2067,7 +2013,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
|
||||||
else if (glob) {
|
else if (glob) {
|
||||||
int not;
|
int not;
|
||||||
|
|
||||||
type = ftrace_setup_glob(glob, strlen(glob), &search, ¬);
|
type = filter_parse_regex(glob, strlen(glob), &search, ¬);
|
||||||
len = strlen(search);
|
len = strlen(search);
|
||||||
|
|
||||||
/* we do not support '!' for function probes */
|
/* we do not support '!' for function probes */
|
||||||
|
@ -2520,7 +2466,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
/* decode regex */
|
/* decode regex */
|
||||||
type = ftrace_setup_glob(buffer, strlen(buffer), &search, ¬);
|
type = filter_parse_regex(buffer, strlen(buffer), &search, ¬);
|
||||||
if (not)
|
if (not)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
|
@ -709,6 +709,13 @@ typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
|
||||||
|
|
||||||
typedef int (*regex_match_func)(char *str, struct regex *r, int len);
|
typedef int (*regex_match_func)(char *str, struct regex *r, int len);
|
||||||
|
|
||||||
|
enum regex_type {
|
||||||
|
MATCH_FULL,
|
||||||
|
MATCH_FRONT_ONLY,
|
||||||
|
MATCH_MIDDLE_ONLY,
|
||||||
|
MATCH_END_ONLY,
|
||||||
|
};
|
||||||
|
|
||||||
struct regex {
|
struct regex {
|
||||||
char pattern[MAX_FILTER_STR_VAL];
|
char pattern[MAX_FILTER_STR_VAL];
|
||||||
int len;
|
int len;
|
||||||
|
@ -727,6 +734,8 @@ struct filter_pred {
|
||||||
int pop_n;
|
int pop_n;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern enum regex_type
|
||||||
|
filter_parse_regex(char *buff, int len, char **search, int *not);
|
||||||
extern void print_event_filter(struct ftrace_event_call *call,
|
extern void print_event_filter(struct ftrace_event_call *call,
|
||||||
struct trace_seq *s);
|
struct trace_seq *s);
|
||||||
extern int apply_event_filter(struct ftrace_event_call *call,
|
extern int apply_event_filter(struct ftrace_event_call *call,
|
||||||
|
|
|
@ -279,15 +279,14 @@ static int regex_match_end(char *str, struct regex *r, int len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum regex_type {
|
/**
|
||||||
MATCH_FULL,
|
* filter_parse_regex - parse a basic regex
|
||||||
MATCH_FRONT_ONLY,
|
* @buff: the raw regex
|
||||||
MATCH_MIDDLE_ONLY,
|
* @len: length of the regex
|
||||||
MATCH_END_ONLY,
|
* @search: will point to the beginning of the string to compare
|
||||||
};
|
* @not: tell whether the match will have to be inverted
|
||||||
|
*
|
||||||
/*
|
* This passes in a buffer containing a regex and this function will
|
||||||
* Pass in a buffer containing a regex and this function will
|
|
||||||
* set search to point to the search part of the buffer and
|
* set search to point to the search part of the buffer and
|
||||||
* return the type of search it is (see enum above).
|
* return the type of search it is (see enum above).
|
||||||
* This does modify buff.
|
* This does modify buff.
|
||||||
|
@ -297,8 +296,7 @@ enum regex_type {
|
||||||
* not returns 1 if buff started with a '!'
|
* not returns 1 if buff started with a '!'
|
||||||
* 0 otherwise.
|
* 0 otherwise.
|
||||||
*/
|
*/
|
||||||
static enum regex_type
|
enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
|
||||||
filter_parse_regex(char *buff, int len, char **search, int *not)
|
|
||||||
{
|
{
|
||||||
int type = MATCH_FULL;
|
int type = MATCH_FULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
Loading…
Reference in a new issue