Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60f1d5e3 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt
Browse files

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@devbox



Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 546fece4
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -189,16 +189,13 @@ And for string fields they are:

==, !=, ~

The glob (~) only accepts a wild card character (*) at the start and or
end of the string. For example:
The glob (~) accepts a wild card character (*,?) and character classes
([). For example:

  prev_comm ~ "*sh"
  prev_comm ~ "sh*"
  prev_comm ~ "*sh*"

But does not allow for it to be within the string:

  prev_comm ~ "ba*sh"   <-- is invalid
  prev_comm ~ "ba*sh"

5.2 Setting filters
-------------------
+3 −6
Original line number Diff line number Diff line
@@ -2218,16 +2218,13 @@ hrtimer_interrupt
sys_nanosleep


Perhaps this is not enough. The filters also allow simple wild
cards. Only the following are currently available
Perhaps this is not enough. The filters also allow glob(7) matching.

  <match>*  - will match functions that begin with <match>
  *<match>  - will match functions that end with <match>
  *<match>* - will match functions that have <match> in it

These are the only wild cards which are supported.

  <match>*<match> will not work.
  <match1>*<match2> - will match functions that begin with
                      <match1> and end with <match2>

Note: It is better to use quotes to enclose the wild cards,
      otherwise the shell may expand the parameters into names
+2 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ config FTRACE_NMI_ENTER

config EVENT_TRACING
	select CONTEXT_SWITCH_TRACER
        select GLOB
	bool

config CONTEXT_SWITCH_TRACER
@@ -133,6 +134,7 @@ config FUNCTION_TRACER
	select KALLSYMS
	select GENERIC_TRACER
	select CONTEXT_SWITCH_TRACER
        select GLOB
	help
	  Enable the kernel to trace every kernel function. This is done
	  by using a compiler feature to insert a small, 5-byte No-Operation
+4 −0
Original line number Diff line number Diff line
@@ -3511,6 +3511,10 @@ static int ftrace_match(char *str, struct ftrace_glob *g)
		    memcmp(str + slen - g->len, g->search, g->len) == 0)
			matched = 1;
		break;
	case MATCH_GLOB:
		if (glob_match(g->search, str))
			matched = 1;
		break;
	}

	return matched;
+1 −1
Original line number Diff line number Diff line
@@ -4065,7 +4065,7 @@ static const char readme_msg[] =
	"\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"
	"\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      Format: :mod:<module-name>\n"
	"\t     example: echo :mod:ext3 > set_ftrace_filter\n"
Loading