* [PATCH 2/4] perf ftrace: Move setup_pager before opening trace_pipe
2017-06-18 14:22 [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Namhyung Kim
@ 2017-06-18 14:23 ` Namhyung Kim
2017-06-20 9:05 ` [tip:perf/core] " tip-bot for Namhyung Kim
2017-06-18 14:23 ` [PATCH 3/4] perf ftrace: Add option for function filtering Namhyung Kim
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Namhyung Kim @ 2017-06-18 14:23 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, Peter Zijlstra, Jiri Olsa, LKML, kernel-team,
Masami Hiramatsu, Steven Rostedt, Frederic Weisbecker
The perf ftrace fails to reset tracer after finish the recording like
below:
$ sudo perf ftrace -v hello
write 'nop' to tracing/current_tracer failed: Device or resource busy
...
This is because the trace_pipe file is open in pager process. Move the
pager setup before opening the file.
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Fixes: 583359646fde ("perf ftrace: Use pager for displaying result")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-ftrace.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 966a94fa8200..982b98ee639e 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -231,6 +231,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}
+ setup_pager();
+
trace_file = get_tracing_file("trace_pipe");
if (!trace_file) {
pr_err("failed to open trace_pipe\n");
@@ -254,8 +256,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_close_fd;
}
- setup_pager();
-
perf_evlist__start_workload(ftrace->evlist);
while (!done) {
--
2.13.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [tip:perf/core] perf ftrace: Move setup_pager before opening trace_pipe
2017-06-18 14:23 ` [PATCH 2/4] perf ftrace: Move setup_pager before opening trace_pipe Namhyung Kim
@ 2017-06-20 9:05 ` tip-bot for Namhyung Kim
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Namhyung Kim @ 2017-06-20 9:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: tglx, linux-kernel, hpa, fweisbec, acme, jolsa, mhiramat, mingo,
rostedt, namhyung, peterz
Commit-ID: 29681bc5bb4326c2f9eac5dc68d8fad3e88b4bb5
Gitweb: http://git.kernel.org/tip/29681bc5bb4326c2f9eac5dc68d8fad3e88b4bb5
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Sun, 18 Jun 2017 23:23:00 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 19 Jun 2017 22:05:52 -0300
perf ftrace: Move setup_pager before opening trace_pipe
The 'perf ftrace' command fails to reset tracer after finishing
recording like below:
$ sudo perf ftrace -v hello
write 'nop' to tracing/current_tracer failed: Device or resource busy
...
This is because the trace_pipe file is open in pager process. Move the
pager setup to before opening the file.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: kernel-team@lge.com
Fixes: 583359646fde ("perf ftrace: Use pager for displaying result")
Link: http://lkml.kernel.org/r/20170618142302.25390-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-ftrace.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 966a94f..982b98e 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -231,6 +231,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}
+ setup_pager();
+
trace_file = get_tracing_file("trace_pipe");
if (!trace_file) {
pr_err("failed to open trace_pipe\n");
@@ -254,8 +256,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_close_fd;
}
- setup_pager();
-
perf_evlist__start_workload(ftrace->evlist);
while (!done) {
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] perf ftrace: Add option for function filtering
2017-06-18 14:22 [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Namhyung Kim
2017-06-18 14:23 ` [PATCH 2/4] perf ftrace: Move setup_pager before opening trace_pipe Namhyung Kim
@ 2017-06-18 14:23 ` Namhyung Kim
2017-06-20 9:06 ` [tip:perf/core] " tip-bot for Namhyung Kim
2017-06-18 14:23 ` [PATCH 4/4] perf ftrace: Add -D option for depth filter Namhyung Kim
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Namhyung Kim @ 2017-06-18 14:23 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, Peter Zijlstra, Jiri Olsa, LKML, kernel-team,
Masami Hiramatsu, Steven Rostedt, Frederic Weisbecker
The -T/--trace-funcs and -N/--notrace-funcs options are to specify
functions to enable/disable tracing dynamically.
The -G/--graph-funcs and -g/--nograph-funcs options are to set filters
for function graph tracer.
For example, to trace fault handling functions only:
$ sudo perf ftrace -T *fault hello
0) | __do_page_fault() {
0) | handle_mm_fault() {
0) 2.117 us | __handle_mm_fault();
0) 3.627 us | }
0) 7.811 us | }
0) | __do_page_fault() {
0) | handle_mm_fault() {
0) 2.014 us | __handle_mm_fault();
0) 2.424 us | }
0) 2.951 us | }
...
To trace all functions executed in __do_page_fault:
$ sudo perf ftrace -G __do_page_fault hello
3) | __do_page_fault() {
3) 0.060 us | down_read_trylock();
3) | find_vma() {
3) 0.075 us | vmacache_find();
3) 0.053 us | vmacache_update();
3) 1.246 us | }
3) | handle_mm_fault() {
3) 0.063 us | __rcu_read_lock();
3) 0.056 us | mem_cgroup_from_task();
3) 0.057 us | __rcu_read_unlock();
3) | __handle_mm_fault() {
3) | filemap_map_pages() {
3) 0.058 us | __rcu_read_lock();
3) | alloc_set_pte() {
...
But don't want to show details in handle_mm_fault:
$ sudo perf ftrace -G __do_page_fault -g handle_mm_fault hello
3) | __do_page_fault() {
3) 0.049 us | down_read_trylock();
3) | find_vma() {
3) 0.048 us | vmacache_find();
3) 0.041 us | vmacache_update();
3) 0.680 us | }
3) 0.036 us | up_read();
3) 4.547 us | } /* __do_page_fault */
...
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-ftrace.txt | 30 ++++++++
tools/perf/builtin-ftrace.c | 117 +++++++++++++++++++++++++++++--
2 files changed, 141 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 6e6a8b22c859..78d6126ca485 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -48,6 +48,36 @@ OPTIONS
Ranges of CPUs are specified with -: 0-2.
Default is to trace on all online CPUs.
+-T::
+--trace-funcs=::
+ Only trace functions given by the argument. Multiple functions
+ can be given by using this option more than once. The function
+ argument also can be a glob pattern. It will be passed to
+ 'set_ftrace_filter' in tracefs.
+
+-N::
+--notrace-funcs=::
+ Do not trace functions given by the argument. Like -T option,
+ this can be used more than once to specify multiple functions
+ (or glob patterns). It will be passed to 'set_ftrace_notrace'
+ in tracefs.
+
+-G::
+--graph-funcs=::
+ Set graph filter on the given function (or a glob pattern).
+ This is useful for the function_graph tracer only and enables
+ tracing for functions executed from the given function.
+ This can be used more than once to specify multiple functions.
+ It will be passed to 'set_graph_function' in tracefs.
+
+-g::
+--nograph-funcs=::
+ Set graph notrace filter on the given function (or a glob pattern).
+ Like -G option, this is useful for the function_graph tracer only
+ and disables tracing for function executed from the given function.
+ This can be used more than once to specify multiple functions.
+ It will be passed to 'set_graph_notrace' in tracefs.
+
SEE ALSO
--------
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 982b98ee639e..3285375ce3c2 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -28,9 +28,18 @@
#define DEFAULT_TRACER "function_graph"
struct perf_ftrace {
- struct perf_evlist *evlist;
- struct target target;
- const char *tracer;
+ struct perf_evlist *evlist;
+ struct target target;
+ const char *tracer;
+ struct list_head filters;
+ struct list_head notrace;
+ struct list_head graph_funcs;
+ struct list_head nograph_funcs;
+};
+
+struct filter_entry {
+ struct list_head list;
+ char name[];
};
static bool done;
@@ -104,6 +113,7 @@ static int append_tracing_file(const char *name, const char *val)
}
static int reset_tracing_cpu(void);
+static void reset_tracing_filters(void);
static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
{
@@ -119,6 +129,7 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
if (reset_tracing_cpu() < 0)
return -1;
+ reset_tracing_filters();
return 0;
}
@@ -184,6 +195,48 @@ static int reset_tracing_cpu(void)
return ret;
}
+static int __set_tracing_filter(const char *filter_file, struct list_head *funcs)
+{
+ struct filter_entry *pos;
+
+ list_for_each_entry(pos, funcs, list) {
+ if (append_tracing_file(filter_file, pos->name) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+static int set_tracing_filters(struct perf_ftrace *ftrace)
+{
+ int ret;
+
+ ret = __set_tracing_filter("set_ftrace_filter", &ftrace->filters);
+ if (ret < 0)
+ return ret;
+
+ ret = __set_tracing_filter("set_ftrace_notrace", &ftrace->notrace);
+ if (ret < 0)
+ return ret;
+
+ ret = __set_tracing_filter("set_graph_function", &ftrace->graph_funcs);
+ if (ret < 0)
+ return ret;
+
+ /* old kernels do not have this filter */
+ __set_tracing_filter("set_graph_notrace", &ftrace->nograph_funcs);
+
+ return ret;
+}
+
+static void reset_tracing_filters(void)
+{
+ write_tracing_file("set_ftrace_filter", " ");
+ write_tracing_file("set_ftrace_notrace", " ");
+ write_tracing_file("set_graph_function", " ");
+ write_tracing_file("set_graph_notrace", " ");
+}
+
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
{
char *trace_file;
@@ -226,6 +279,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}
+ if (set_tracing_filters(ftrace) < 0) {
+ pr_err("failed to set tracing filters\n");
+ goto out_reset;
+ }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -310,6 +368,32 @@ static int perf_ftrace_config(const char *var, const char *value, void *cb)
return -1;
}
+static int parse_filter_func(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct list_head *head = opt->value;
+ struct filter_entry *entry;
+
+ entry = malloc(sizeof(*entry) + strlen(str) + 1);
+ if (entry == NULL)
+ return -ENOMEM;
+
+ strcpy(entry->name, str);
+ list_add_tail(&entry->list, head);
+
+ return 0;
+}
+
+static void delete_filter_func(struct list_head *head)
+{
+ struct filter_entry *pos, *tmp;
+
+ list_for_each_entry_safe(pos, tmp, head, list) {
+ list_del(&pos->list);
+ free(pos);
+ }
+}
+
int cmd_ftrace(int argc, const char **argv)
{
int ret;
@@ -333,9 +417,22 @@ int cmd_ftrace(int argc, const char **argv)
"system-wide collection from all CPUs"),
OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
"list of cpus to monitor"),
+ OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func",
+ "trace given functions only", parse_filter_func),
+ OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func",
+ "do not trace given functions", parse_filter_func),
+ OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func",
+ "Set graph filter on given functions", parse_filter_func),
+ OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
+ "Set nograph filter on given functions", parse_filter_func),
OPT_END()
};
+ INIT_LIST_HEAD(&ftrace.filters);
+ INIT_LIST_HEAD(&ftrace.notrace);
+ INIT_LIST_HEAD(&ftrace.graph_funcs);
+ INIT_LIST_HEAD(&ftrace.nograph_funcs);
+
ret = perf_config(perf_ftrace_config, &ftrace);
if (ret < 0)
return -1;
@@ -351,12 +448,14 @@ int cmd_ftrace(int argc, const char **argv)
target__strerror(&ftrace.target, ret, errbuf, 512);
pr_err("%s\n", errbuf);
- return -EINVAL;
+ goto out_delete_filters;
}
ftrace.evlist = perf_evlist__new();
- if (ftrace.evlist == NULL)
- return -ENOMEM;
+ if (ftrace.evlist == NULL) {
+ ret = -ENOMEM;
+ goto out_delete_filters;
+ }
ret = perf_evlist__create_maps(ftrace.evlist, &ftrace.target);
if (ret < 0)
@@ -367,5 +466,11 @@ int cmd_ftrace(int argc, const char **argv)
out_delete_evlist:
perf_evlist__delete(ftrace.evlist);
+out_delete_filters:
+ delete_filter_func(&ftrace.filters);
+ delete_filter_func(&ftrace.notrace);
+ delete_filter_func(&ftrace.graph_funcs);
+ delete_filter_func(&ftrace.nograph_funcs);
+
return ret;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [tip:perf/core] perf ftrace: Add option for function filtering
2017-06-18 14:23 ` [PATCH 3/4] perf ftrace: Add option for function filtering Namhyung Kim
@ 2017-06-20 9:06 ` tip-bot for Namhyung Kim
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Namhyung Kim @ 2017-06-20 9:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: fweisbec, jolsa, namhyung, mingo, linux-kernel, rostedt, hpa,
acme, peterz, mhiramat, tglx
Commit-ID: 78b83e8b12b4467540ca501c7c019e9d46051957
Gitweb: http://git.kernel.org/tip/78b83e8b12b4467540ca501c7c019e9d46051957
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Sun, 18 Jun 2017 23:23:01 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 19 Jun 2017 22:05:53 -0300
perf ftrace: Add option for function filtering
The -T/--trace-funcs and -N/--notrace-funcs options are to specify
functions to enable/disable tracing dynamically.
The -G/--graph-funcs and -g/--nograph-funcs options are to set filters
for function graph tracer.
For example, to trace fault handling functions only:
$ sudo perf ftrace -T *fault hello
0) | __do_page_fault() {
0) | handle_mm_fault() {
0) 2.117 us | __handle_mm_fault();
0) 3.627 us | }
0) 7.811 us | }
0) | __do_page_fault() {
0) | handle_mm_fault() {
0) 2.014 us | __handle_mm_fault();
0) 2.424 us | }
0) 2.951 us | }
...
To trace all functions executed in __do_page_fault:
$ sudo perf ftrace -G __do_page_fault hello
2) | __do_page_fault() {
3) 0.060 us | down_read_trylock();
3) | find_vma() {
3) 0.075 us | vmacache_find();
3) 0.053 us | vmacache_update();
3) 1.246 us | }
3) | handle_mm_fault() {
3) 0.063 us | __rcu_read_lock();
3) 0.056 us | mem_cgroup_from_task();
3) 0.057 us | __rcu_read_unlock();
3) | __handle_mm_fault() {
3) | filemap_map_pages() {
3) 0.058 us | __rcu_read_lock();
3) | alloc_set_pte() {
...
But don't want to show details in handle_mm_fault:
$ sudo perf ftrace -G __do_page_fault -g handle_mm_fault hello
3) | __do_page_fault() {
3) 0.049 us | down_read_trylock();
3) | find_vma() {
3) 0.048 us | vmacache_find();
3) 0.041 us | vmacache_update();
3) 0.680 us | }
3) 0.036 us | up_read();
3) 4.547 us | } /* __do_page_fault */
...
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20170618142302.25390-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-ftrace.txt | 30 ++++++++
tools/perf/builtin-ftrace.c | 117 +++++++++++++++++++++++++++++--
2 files changed, 141 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 6e6a8b2..78d6126 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -48,6 +48,36 @@ OPTIONS
Ranges of CPUs are specified with -: 0-2.
Default is to trace on all online CPUs.
+-T::
+--trace-funcs=::
+ Only trace functions given by the argument. Multiple functions
+ can be given by using this option more than once. The function
+ argument also can be a glob pattern. It will be passed to
+ 'set_ftrace_filter' in tracefs.
+
+-N::
+--notrace-funcs=::
+ Do not trace functions given by the argument. Like -T option,
+ this can be used more than once to specify multiple functions
+ (or glob patterns). It will be passed to 'set_ftrace_notrace'
+ in tracefs.
+
+-G::
+--graph-funcs=::
+ Set graph filter on the given function (or a glob pattern).
+ This is useful for the function_graph tracer only and enables
+ tracing for functions executed from the given function.
+ This can be used more than once to specify multiple functions.
+ It will be passed to 'set_graph_function' in tracefs.
+
+-g::
+--nograph-funcs=::
+ Set graph notrace filter on the given function (or a glob pattern).
+ Like -G option, this is useful for the function_graph tracer only
+ and disables tracing for function executed from the given function.
+ This can be used more than once to specify multiple functions.
+ It will be passed to 'set_graph_notrace' in tracefs.
+
SEE ALSO
--------
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 982b98e..3285375 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -28,9 +28,18 @@
#define DEFAULT_TRACER "function_graph"
struct perf_ftrace {
- struct perf_evlist *evlist;
- struct target target;
- const char *tracer;
+ struct perf_evlist *evlist;
+ struct target target;
+ const char *tracer;
+ struct list_head filters;
+ struct list_head notrace;
+ struct list_head graph_funcs;
+ struct list_head nograph_funcs;
+};
+
+struct filter_entry {
+ struct list_head list;
+ char name[];
};
static bool done;
@@ -104,6 +113,7 @@ static int append_tracing_file(const char *name, const char *val)
}
static int reset_tracing_cpu(void);
+static void reset_tracing_filters(void);
static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
{
@@ -119,6 +129,7 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
if (reset_tracing_cpu() < 0)
return -1;
+ reset_tracing_filters();
return 0;
}
@@ -184,6 +195,48 @@ static int reset_tracing_cpu(void)
return ret;
}
+static int __set_tracing_filter(const char *filter_file, struct list_head *funcs)
+{
+ struct filter_entry *pos;
+
+ list_for_each_entry(pos, funcs, list) {
+ if (append_tracing_file(filter_file, pos->name) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+static int set_tracing_filters(struct perf_ftrace *ftrace)
+{
+ int ret;
+
+ ret = __set_tracing_filter("set_ftrace_filter", &ftrace->filters);
+ if (ret < 0)
+ return ret;
+
+ ret = __set_tracing_filter("set_ftrace_notrace", &ftrace->notrace);
+ if (ret < 0)
+ return ret;
+
+ ret = __set_tracing_filter("set_graph_function", &ftrace->graph_funcs);
+ if (ret < 0)
+ return ret;
+
+ /* old kernels do not have this filter */
+ __set_tracing_filter("set_graph_notrace", &ftrace->nograph_funcs);
+
+ return ret;
+}
+
+static void reset_tracing_filters(void)
+{
+ write_tracing_file("set_ftrace_filter", " ");
+ write_tracing_file("set_ftrace_notrace", " ");
+ write_tracing_file("set_graph_function", " ");
+ write_tracing_file("set_graph_notrace", " ");
+}
+
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
{
char *trace_file;
@@ -226,6 +279,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}
+ if (set_tracing_filters(ftrace) < 0) {
+ pr_err("failed to set tracing filters\n");
+ goto out_reset;
+ }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -310,6 +368,32 @@ static int perf_ftrace_config(const char *var, const char *value, void *cb)
return -1;
}
+static int parse_filter_func(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct list_head *head = opt->value;
+ struct filter_entry *entry;
+
+ entry = malloc(sizeof(*entry) + strlen(str) + 1);
+ if (entry == NULL)
+ return -ENOMEM;
+
+ strcpy(entry->name, str);
+ list_add_tail(&entry->list, head);
+
+ return 0;
+}
+
+static void delete_filter_func(struct list_head *head)
+{
+ struct filter_entry *pos, *tmp;
+
+ list_for_each_entry_safe(pos, tmp, head, list) {
+ list_del(&pos->list);
+ free(pos);
+ }
+}
+
int cmd_ftrace(int argc, const char **argv)
{
int ret;
@@ -333,9 +417,22 @@ int cmd_ftrace(int argc, const char **argv)
"system-wide collection from all CPUs"),
OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
"list of cpus to monitor"),
+ OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func",
+ "trace given functions only", parse_filter_func),
+ OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func",
+ "do not trace given functions", parse_filter_func),
+ OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func",
+ "Set graph filter on given functions", parse_filter_func),
+ OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
+ "Set nograph filter on given functions", parse_filter_func),
OPT_END()
};
+ INIT_LIST_HEAD(&ftrace.filters);
+ INIT_LIST_HEAD(&ftrace.notrace);
+ INIT_LIST_HEAD(&ftrace.graph_funcs);
+ INIT_LIST_HEAD(&ftrace.nograph_funcs);
+
ret = perf_config(perf_ftrace_config, &ftrace);
if (ret < 0)
return -1;
@@ -351,12 +448,14 @@ int cmd_ftrace(int argc, const char **argv)
target__strerror(&ftrace.target, ret, errbuf, 512);
pr_err("%s\n", errbuf);
- return -EINVAL;
+ goto out_delete_filters;
}
ftrace.evlist = perf_evlist__new();
- if (ftrace.evlist == NULL)
- return -ENOMEM;
+ if (ftrace.evlist == NULL) {
+ ret = -ENOMEM;
+ goto out_delete_filters;
+ }
ret = perf_evlist__create_maps(ftrace.evlist, &ftrace.target);
if (ret < 0)
@@ -367,5 +466,11 @@ int cmd_ftrace(int argc, const char **argv)
out_delete_evlist:
perf_evlist__delete(ftrace.evlist);
+out_delete_filters:
+ delete_filter_func(&ftrace.filters);
+ delete_filter_func(&ftrace.notrace);
+ delete_filter_func(&ftrace.graph_funcs);
+ delete_filter_func(&ftrace.nograph_funcs);
+
return ret;
}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] perf ftrace: Add -D option for depth filter
2017-06-18 14:22 [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Namhyung Kim
2017-06-18 14:23 ` [PATCH 2/4] perf ftrace: Move setup_pager before opening trace_pipe Namhyung Kim
2017-06-18 14:23 ` [PATCH 3/4] perf ftrace: Add option for function filtering Namhyung Kim
@ 2017-06-18 14:23 ` Namhyung Kim
2017-06-20 9:07 ` [tip:perf/core] " tip-bot for Namhyung Kim
2017-06-19 18:24 ` [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Arnaldo Carvalho de Melo
2017-06-20 9:05 ` [tip:perf/core] " tip-bot for Namhyung Kim
4 siblings, 1 reply; 9+ messages in thread
From: Namhyung Kim @ 2017-06-18 14:23 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, Peter Zijlstra, Jiri Olsa, LKML, kernel-team,
Masami Hiramatsu, Steven Rostedt, Frederic Weisbecker
The -D/--graph-depth option is to set max graph depth. The following
example traces max 2-depth of page fault handler.
$ sudo perf ftrace -G __do_page_fault -D 2 -- hello
...
0) | __do_page_fault() {
0) 0.063 us | down_read_trylock();
0) 0.251 us | find_vma();
0) 5.374 us | handle_mm_fault();
0) 0.054 us | up_read();
0) 7.463 us | }
...
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-ftrace.txt | 3 +++
tools/perf/builtin-ftrace.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 78d6126ca485..721a447f046e 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -78,6 +78,9 @@ OPTIONS
This can be used more than once to specify multiple functions.
It will be passed to 'set_graph_notrace' in tracefs.
+-D::
+--graph-depth=::
+ Set max depth for function graph tracer to follow
SEE ALSO
--------
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 3285375ce3c2..dd26c62c9893 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -35,6 +35,7 @@ struct perf_ftrace {
struct list_head notrace;
struct list_head graph_funcs;
struct list_head nograph_funcs;
+ int graph_depth;
};
struct filter_entry {
@@ -129,6 +130,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
if (reset_tracing_cpu() < 0)
return -1;
+ if (write_tracing_file("max_graph_depth", "0") < 0)
+ return -1;
+
reset_tracing_filters();
return 0;
}
@@ -237,6 +241,26 @@ static void reset_tracing_filters(void)
write_tracing_file("set_graph_notrace", " ");
}
+static int set_tracing_depth(struct perf_ftrace *ftrace)
+{
+ char buf[16];
+
+ if (ftrace->graph_depth == 0)
+ return 0;
+
+ if (ftrace->graph_depth < 0) {
+ pr_err("invalid graph depth: %d\n", ftrace->graph_depth);
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", ftrace->graph_depth);
+
+ if (write_tracing_file("max_graph_depth", buf) < 0)
+ return -1;
+
+ return 0;
+}
+
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
{
char *trace_file;
@@ -284,6 +308,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}
+ if (set_tracing_depth(ftrace) < 0) {
+ pr_err("failed to set graph depth\n");
+ goto out_reset;
+ }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -425,6 +454,8 @@ int cmd_ftrace(int argc, const char **argv)
"Set graph filter on given functions", parse_filter_func),
OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
"Set nograph filter on given functions", parse_filter_func),
+ OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth,
+ "Max depth for function graph tracer"),
OPT_END()
};
--
2.13.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [tip:perf/core] perf ftrace: Add -D option for depth filter
2017-06-18 14:23 ` [PATCH 4/4] perf ftrace: Add -D option for depth filter Namhyung Kim
@ 2017-06-20 9:07 ` tip-bot for Namhyung Kim
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Namhyung Kim @ 2017-06-20 9:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: mhiramat, fweisbec, mingo, hpa, acme, linux-kernel, peterz,
rostedt, jolsa, namhyung, tglx
Commit-ID: 1096c35aa821cc4789a64232a0e210bb87a0e5e8
Gitweb: http://git.kernel.org/tip/1096c35aa821cc4789a64232a0e210bb87a0e5e8
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Sun, 18 Jun 2017 23:23:02 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 19 Jun 2017 22:05:54 -0300
perf ftrace: Add -D option for depth filter
The -D/--graph-depth option is to set max graph depth. The following
example traces max 2-depth of page fault handler.
$ sudo perf ftrace -G __do_page_fault -D 2 -- hello
...
0) | __do_page_fault() {
0) 0.063 us | down_read_trylock();
0) 0.251 us | find_vma();
0) 5.374 us | handle_mm_fault();
0) 0.054 us | up_read();
0) 7.463 us | }
...
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20170618142302.25390-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-ftrace.txt | 3 +++
tools/perf/builtin-ftrace.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 78d6126..721a447 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -78,6 +78,9 @@ OPTIONS
This can be used more than once to specify multiple functions.
It will be passed to 'set_graph_notrace' in tracefs.
+-D::
+--graph-depth=::
+ Set max depth for function graph tracer to follow
SEE ALSO
--------
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 3285375..dd26c62 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -35,6 +35,7 @@ struct perf_ftrace {
struct list_head notrace;
struct list_head graph_funcs;
struct list_head nograph_funcs;
+ int graph_depth;
};
struct filter_entry {
@@ -129,6 +130,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
if (reset_tracing_cpu() < 0)
return -1;
+ if (write_tracing_file("max_graph_depth", "0") < 0)
+ return -1;
+
reset_tracing_filters();
return 0;
}
@@ -237,6 +241,26 @@ static void reset_tracing_filters(void)
write_tracing_file("set_graph_notrace", " ");
}
+static int set_tracing_depth(struct perf_ftrace *ftrace)
+{
+ char buf[16];
+
+ if (ftrace->graph_depth == 0)
+ return 0;
+
+ if (ftrace->graph_depth < 0) {
+ pr_err("invalid graph depth: %d\n", ftrace->graph_depth);
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", ftrace->graph_depth);
+
+ if (write_tracing_file("max_graph_depth", buf) < 0)
+ return -1;
+
+ return 0;
+}
+
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
{
char *trace_file;
@@ -284,6 +308,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}
+ if (set_tracing_depth(ftrace) < 0) {
+ pr_err("failed to set graph depth\n");
+ goto out_reset;
+ }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -425,6 +454,8 @@ int cmd_ftrace(int argc, const char **argv)
"Set graph filter on given functions", parse_filter_func),
OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
"Set nograph filter on given functions", parse_filter_func),
+ OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth,
+ "Max depth for function graph tracer"),
OPT_END()
};
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files
2017-06-18 14:22 [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Namhyung Kim
` (2 preceding siblings ...)
2017-06-18 14:23 ` [PATCH 4/4] perf ftrace: Add -D option for depth filter Namhyung Kim
@ 2017-06-19 18:24 ` Arnaldo Carvalho de Melo
2017-06-20 9:05 ` [tip:perf/core] " tip-bot for Namhyung Kim
4 siblings, 0 replies; 9+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-19 18:24 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Peter Zijlstra, Jiri Olsa, LKML, kernel-team,
Masami Hiramatsu, Steven Rostedt, Frederic Weisbecker
Em Sun, Jun 18, 2017 at 11:22:59PM +0900, Namhyung Kim escreveu:
> It'd be better for debugging to show an error message when it fails to
> setup ftrace for some reason.
Thanks a lot, tested the series, excellent ftrace subset to support in
'perf ftrace'! :-)
- Arnaldo
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/builtin-ftrace.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index 9e0b35cd0eea..966a94fa8200 100644
> --- a/tools/perf/builtin-ftrace.c
> +++ b/tools/perf/builtin-ftrace.c
> @@ -61,6 +61,7 @@ static int __write_tracing_file(const char *name, const char *val, bool append)
> int fd, ret = -1;
> ssize_t size = strlen(val);
> int flags = O_WRONLY;
> + char errbuf[512];
>
> file = get_tracing_file(name);
> if (!file) {
> @@ -75,14 +76,16 @@ static int __write_tracing_file(const char *name, const char *val, bool append)
>
> fd = open(file, flags);
> if (fd < 0) {
> - pr_debug("cannot open tracing file: %s\n", name);
> + pr_debug("cannot open tracing file: %s: %s\n",
> + name, str_error_r(errno, errbuf, sizeof(errbuf)));
> goto out;
> }
>
> if (write(fd, val, size) == size)
> ret = 0;
> else
> - pr_debug("write '%s' to tracing/%s failed\n", val, name);
> + pr_debug("write '%s' to tracing/%s failed: %s\n",
> + val, name, str_error_r(errno, errbuf, sizeof(errbuf)));
>
> close(fd);
> out:
> --
> 2.13.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [tip:perf/core] perf ftrace: Show error message when fails to set ftrace files
2017-06-18 14:22 [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Namhyung Kim
` (3 preceding siblings ...)
2017-06-19 18:24 ` [PATCH 1/4] perf ftrace: Show error message when fails to set ftrace files Arnaldo Carvalho de Melo
@ 2017-06-20 9:05 ` tip-bot for Namhyung Kim
4 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Namhyung Kim @ 2017-06-20 9:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: rostedt, linux-kernel, fweisbec, peterz, mhiramat, namhyung,
mingo, acme, hpa, tglx, jolsa
Commit-ID: e7bd9ba20a9ec7024a0566a93c22b9571a48939a
Gitweb: http://git.kernel.org/tip/e7bd9ba20a9ec7024a0566a93c22b9571a48939a
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Sun, 18 Jun 2017 23:22:59 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 19 Jun 2017 22:05:51 -0300
perf ftrace: Show error message when fails to set ftrace files
It'd be better for debugging to show an error message when it fails to
setup ftrace for some reason.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20170618142302.25390-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-ftrace.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 9e0b35c..966a94f 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -61,6 +61,7 @@ static int __write_tracing_file(const char *name, const char *val, bool append)
int fd, ret = -1;
ssize_t size = strlen(val);
int flags = O_WRONLY;
+ char errbuf[512];
file = get_tracing_file(name);
if (!file) {
@@ -75,14 +76,16 @@ static int __write_tracing_file(const char *name, const char *val, bool append)
fd = open(file, flags);
if (fd < 0) {
- pr_debug("cannot open tracing file: %s\n", name);
+ pr_debug("cannot open tracing file: %s: %s\n",
+ name, str_error_r(errno, errbuf, sizeof(errbuf)));
goto out;
}
if (write(fd, val, size) == size)
ret = 0;
else
- pr_debug("write '%s' to tracing/%s failed\n", val, name);
+ pr_debug("write '%s' to tracing/%s failed: %s\n",
+ val, name, str_error_r(errno, errbuf, sizeof(errbuf)));
close(fd);
out:
^ permalink raw reply related [flat|nested] 9+ messages in thread