perf ftrace: Show error message when fails to set ftrace files
Namhyung Kim
maintainerPATCH 1/4 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.
--- tools/perf/builtin-ftrace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-ftrace.c +5 -2
@@ -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:
Signature · 1 line
2.13.0
Namhyung Kim
maintainerPATCH 2/4 perf ftrace: Move setup_pager before opening trace_pipe
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.
--- tools/perf/builtin-ftrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-ftrace.c +2 -2
@@ -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) {
Signature · 1 line
2.13.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf ftrace: Move setup_pager before opening trace_pipe
perf ftrace: Move setup_pager before opening trace_pipe
Commit-ID: 29681bc5bb4326c2f9eac5dc68d8fad3e88b4bb5 Gitweb: http://git.kernel.org/tip/29681bc5bb4326c2f9eac5dc68d8fad3e88b4bb5 Author: Namhyung Kim <[email protected]> AuthorDate: Sun, 18 Jun 2017 23:23:00 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> 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.
--- tools/perf/builtin-ftrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-ftrace.c +2 -2
@@ -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) {
Namhyung Kim
maintainerPATCH 3/4 perf ftrace: Add option for function filtering
In reply to Namhyung KimThe -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 */
...--- tools/perf/Documentation/perf-ftrace.txt | 30 ++++++++ tools/perf/builtin-ftrace.c | 117 +++++++++++++++++++++++++++++-- 2 files changed, 141 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-ftrace.txt +30 -0
@@ -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 --------
tools/perf/builtin-ftrace.c +111 -6
176 lines not on this page · raw message
Signature · 1 line
2.13.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf ftrace: Add option for function filtering
perf ftrace: Add option for function filtering
Commit-ID: 78b83e8b12b4467540ca501c7c019e9d46051957 Gitweb: http://git.kernel.org/tip/78b83e8b12b4467540ca501c7c019e9d46051957 Author: Namhyung Kim <[email protected]> AuthorDate: Sun, 18 Jun 2017 23:23:01 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> 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 */
...--- tools/perf/Documentation/perf-ftrace.txt | 30 ++++++++ tools/perf/builtin-ftrace.c | 117 +++++++++++++++++++++++++++++-- 2 files changed, 141 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-ftrace.txt +30 -0
@@ -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 --------
tools/perf/builtin-ftrace.c +111 -6
176 lines not on this page · raw message
Namhyung Kim
maintainerPATCH 4/4 perf ftrace: Add -D option for depth filter
In reply to Namhyung KimThe -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 | }
...--- tools/perf/Documentation/perf-ftrace.txt | 3 +++ tools/perf/builtin-ftrace.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
tools/perf/Documentation/perf-ftrace.txt +3 -0
@@ -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 --------
tools/perf/builtin-ftrace.c +31 -0
@@ -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() };
Signature · 1 line
2.13.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf ftrace: Add -D option for depth filter
perf ftrace: Add -D option for depth filter
Commit-ID: 1096c35aa821cc4789a64232a0e210bb87a0e5e8 Gitweb: http://git.kernel.org/tip/1096c35aa821cc4789a64232a0e210bb87a0e5e8 Author: Namhyung Kim <[email protected]> AuthorDate: Sun, 18 Jun 2017 23:23:02 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> 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 | }
...--- tools/perf/Documentation/perf-ftrace.txt | 3 +++ tools/perf/builtin-ftrace.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
tools/perf/Documentation/perf-ftrace.txt +3 -0
@@ -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 --------
tools/perf/builtin-ftrace.c +31 -0
@@ -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() };
Arnaldo Carvalho de Melo
maintainerEm Sun, Jun 18, 2017 at 11:22:59PM +0900, Namhyung Kim escreveu:
Quoted 2 lines
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
Quoted 40 lines
Cc Steven Rostedt <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-ftrace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/perf/builtin-ftrace.c +5
-2@@ -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:Signature · 1 line
2.13.0
tip-bot for Namhyung Kim
merge botperf ftrace: Show error message when fails to set ftrace files
Commit-ID: e7bd9ba20a9ec7024a0566a93c22b9571a48939a Gitweb: http://git.kernel.org/tip/e7bd9ba20a9ec7024a0566a93c22b9571a48939a Author: Namhyung Kim <[email protected]> AuthorDate: Sun, 18 Jun 2017 23:22:59 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> 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.
--- tools/perf/builtin-ftrace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-ftrace.c +5 -2
@@ -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: