提交 60f1d5e3 编写于 作者: M Masami Hiramatsu 提交者: Steven Rostedt

ftrace: Support full glob matching

Use glob_match() to support flexible glob wildcards (*,?)
and character classes ([) for ftrace.
Since the full glob matching is slower than the current
partial matching routines(*pat, pat*, *pat*), this leaves
those routines and just add MATCH_GLOB for complex glob
expression.

e.g.
----
[root@localhost tracing]# echo 'sched*group' > set_ftrace_filter
[root@localhost tracing]# cat set_ftrace_filter
sched_free_group
sched_change_group
sched_create_group
sched_online_group
sched_destroy_group
sched_offline_group
[root@localhost tracing]# echo '[Ss]y[Ss]_*' > set_ftrace_filter
[root@localhost tracing]# head set_ftrace_filter
sys_arch_prctl
sys_rt_sigreturn
sys_ioperm
SyS_iopl
sys_modify_ldt
SyS_mmap
SyS_set_thread_area
SyS_get_thread_area
SyS_set_tid_address
sys_fork
----

Link: http://lkml.kernel.org/r/147566869501.29136.6462645009894738056.stgit@devboxAcked-by: NNamhyung Kim <namhyung@kernel.org>
Signed-off-by: NMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: NSteven Rostedt <rostedt@goodmis.org>
上级 546fece4
...@@ -189,16 +189,13 @@ And for string fields they are: ...@@ -189,16 +189,13 @@ And for string fields they are:
==, !=, ~ ==, !=, ~
The glob (~) only accepts a wild card character (*) at the start and or The glob (~) accepts a wild card character (*,?) and character classes
end of the string. For example: ([). For example:
prev_comm ~ "*sh" prev_comm ~ "*sh"
prev_comm ~ "sh*" prev_comm ~ "sh*"
prev_comm ~ "*sh*" prev_comm ~ "*sh*"
prev_comm ~ "ba*sh"
But does not allow for it to be within the string:
prev_comm ~ "ba*sh" <-- is invalid
5.2 Setting filters 5.2 Setting filters
------------------- -------------------
......
...@@ -2218,16 +2218,13 @@ hrtimer_interrupt ...@@ -2218,16 +2218,13 @@ hrtimer_interrupt
sys_nanosleep sys_nanosleep
Perhaps this is not enough. The filters also allow simple wild Perhaps this is not enough. The filters also allow glob(7) matching.
cards. Only the following are currently available
<match>* - will match functions that begin with <match> <match>* - will match functions that begin with <match>
*<match> - will match functions that end with <match> *<match> - will match functions that end with <match>
*<match>* - will match functions that have <match> in it *<match>* - will match functions that have <match> in it
<match1>*<match2> - will match functions that begin with
These are the only wild cards which are supported. <match1> and end with <match2>
<match>*<match> will not work.
Note: It is better to use quotes to enclose the wild cards, Note: It is better to use quotes to enclose the wild cards,
otherwise the shell may expand the parameters into names otherwise the shell may expand the parameters into names
......
...@@ -70,6 +70,7 @@ config FTRACE_NMI_ENTER ...@@ -70,6 +70,7 @@ config FTRACE_NMI_ENTER
config EVENT_TRACING config EVENT_TRACING
select CONTEXT_SWITCH_TRACER select CONTEXT_SWITCH_TRACER
select GLOB
bool bool
config CONTEXT_SWITCH_TRACER config CONTEXT_SWITCH_TRACER
...@@ -133,6 +134,7 @@ config FUNCTION_TRACER ...@@ -133,6 +134,7 @@ config FUNCTION_TRACER
select KALLSYMS select KALLSYMS
select GENERIC_TRACER select GENERIC_TRACER
select CONTEXT_SWITCH_TRACER select CONTEXT_SWITCH_TRACER
select GLOB
help help
Enable the kernel to trace every kernel function. This is done Enable the kernel to trace every kernel function. This is done
by using a compiler feature to insert a small, 5-byte No-Operation by using a compiler feature to insert a small, 5-byte No-Operation
......
...@@ -3511,6 +3511,10 @@ static int ftrace_match(char *str, struct ftrace_glob *g) ...@@ -3511,6 +3511,10 @@ static int ftrace_match(char *str, struct ftrace_glob *g)
memcmp(str + slen - g->len, g->search, g->len) == 0) memcmp(str + slen - g->len, g->search, g->len) == 0)
matched = 1; matched = 1;
break; break;
case MATCH_GLOB:
if (glob_match(g->search, str))
matched = 1;
break;
} }
return matched; return matched;
......
...@@ -4065,7 +4065,7 @@ static const char readme_msg[] = ...@@ -4065,7 +4065,7 @@ static const char readme_msg[] =
"\n available_filter_functions - list of functions that can be filtered on\n" "\n available_filter_functions - list of functions that can be filtered on\n"
" set_ftrace_filter\t- echo function name in here to only trace these\n" " set_ftrace_filter\t- echo function name in here to only trace these\n"
"\t\t\t functions\n" "\t\t\t functions\n"
"\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" "\t accepts: func_full_name or glob-matching-pattern\n"
"\t modules: Can select a group via module\n" "\t modules: Can select a group via module\n"
"\t Format: :mod:<module-name>\n" "\t Format: :mod:<module-name>\n"
"\t example: echo :mod:ext3 > set_ftrace_filter\n" "\t example: echo :mod:ext3 > set_ftrace_filter\n"
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/trace_events.h> #include <linux/trace_events.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/trace_seq.h> #include <linux/trace_seq.h>
#include <linux/glob.h>
#ifdef CONFIG_FTRACE_SYSCALLS #ifdef CONFIG_FTRACE_SYSCALLS
#include <asm/unistd.h> /* For NR_SYSCALLS */ #include <asm/unistd.h> /* For NR_SYSCALLS */
...@@ -1257,6 +1258,7 @@ enum regex_type { ...@@ -1257,6 +1258,7 @@ enum regex_type {
MATCH_FRONT_ONLY, MATCH_FRONT_ONLY,
MATCH_MIDDLE_ONLY, MATCH_MIDDLE_ONLY,
MATCH_END_ONLY, MATCH_END_ONLY,
MATCH_GLOB,
}; };
struct regex { struct regex {
......
...@@ -344,6 +344,12 @@ static int regex_match_end(char *str, struct regex *r, int len) ...@@ -344,6 +344,12 @@ static int regex_match_end(char *str, struct regex *r, int len)
return 0; return 0;
} }
static int regex_match_glob(char *str, struct regex *r, int len __maybe_unused)
{
if (glob_match(r->pattern, str))
return 1;
return 0;
}
/** /**
* filter_parse_regex - parse a basic regex * filter_parse_regex - parse a basic regex
* @buff: the raw regex * @buff: the raw regex
...@@ -380,14 +386,20 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not) ...@@ -380,14 +386,20 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
if (!i) { if (!i) {
*search = buff + 1; *search = buff + 1;
type = MATCH_END_ONLY; type = MATCH_END_ONLY;
} else { } else if (i == len - 1) {
if (type == MATCH_END_ONLY) if (type == MATCH_END_ONLY)
type = MATCH_MIDDLE_ONLY; type = MATCH_MIDDLE_ONLY;
else else
type = MATCH_FRONT_ONLY; type = MATCH_FRONT_ONLY;
buff[i] = 0; buff[i] = 0;
break; break;
} else { /* pattern continues, use full glob */
type = MATCH_GLOB;
break;
} }
} else if (strchr("[?\\", buff[i])) {
type = MATCH_GLOB;
break;
} }
} }
...@@ -420,6 +432,9 @@ static void filter_build_regex(struct filter_pred *pred) ...@@ -420,6 +432,9 @@ static void filter_build_regex(struct filter_pred *pred)
case MATCH_END_ONLY: case MATCH_END_ONLY:
r->match = regex_match_end; r->match = regex_match_end;
break; break;
case MATCH_GLOB:
r->match = regex_match_glob;
break;
} }
pred->not ^= not; pred->not ^= not;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册