perf ftrace: Add 'tail' option to --graph-opts
authorNamhyung Kim <namhyung@kernel.org>
Mon, 29 Jul 2024 00:41:24 +0000 (17:41 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 31 Jul 2024 19:58:18 +0000 (16:58 -0300)
The 'graph-tail' option is to print function name as a comment at the end.
This is useful when a large function is mixed with other functions
(possibly from different CPUs).

For example,

  $ sudo perf ftrace -- perf stat true
  ...
   1)               |    get_unused_fd_flags() {
   1)               |      alloc_fd() {
   1)   0.178 us    |        _raw_spin_lock();
   1)   0.187 us    |        expand_files();
   1)   0.169 us    |        _raw_spin_unlock();
   1)   1.211 us    |      }
   1)   1.503 us    |    }

  $ sudo perf ftrace --graph-opts tail -- perf stat true
  ...
   1)               |    get_unused_fd_flags() {
   1)               |      alloc_fd() {
   1)   0.099 us    |        _raw_spin_lock();
   1)   0.083 us    |        expand_files();
   1)   0.081 us    |        _raw_spin_unlock();
   1)   0.601 us    |      } /* alloc_fd */
   1)   0.751 us    |    } /* get_unused_fd_flags */

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Changbin Du <changbin.du@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lore.kernel.org/lkml/20240729004127.238611-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-ftrace.txt
tools/perf/builtin-ftrace.c
tools/perf/util/ftrace.h

index d780b93fcf87131b7267092c53f52a155b613a0e..7ea1645a13cf88d8f3f840f9b918a6ccc5bd89cc 100644 (file)
@@ -125,6 +125,7 @@ OPTIONS for 'perf ftrace trace'
          - verbose      - Show process names, PIDs, timestamps, etc.
          - thresh=<n>   - Setup trace duration threshold in microseconds.
          - depth=<n>    - Set max depth for function graph tracer to follow.
+         - tail         - Print function name at the end.
 
 
 OPTIONS for 'perf ftrace latency'
index eb30c8eca48878482d9e9682165330a161a6f3f8..33c52ebda2fd5b51a66f6b5a25d8fe323fe32925 100644 (file)
@@ -228,6 +228,7 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
        write_tracing_option_file("funcgraph-irqs", "1");
        write_tracing_option_file("funcgraph-proc", "0");
        write_tracing_option_file("funcgraph-abstime", "0");
+       write_tracing_option_file("funcgraph-tail", "0");
        write_tracing_option_file("latency-format", "0");
        write_tracing_option_file("irq-info", "0");
 }
@@ -464,6 +465,17 @@ static int set_tracing_funcgraph_verbose(struct perf_ftrace *ftrace)
        return 0;
 }
 
+static int set_tracing_funcgraph_tail(struct perf_ftrace *ftrace)
+{
+       if (!ftrace->graph_tail)
+               return 0;
+
+       if (write_tracing_option_file("funcgraph-tail", "1") < 0)
+               return -1;
+
+       return 0;
+}
+
 static int set_tracing_thresh(struct perf_ftrace *ftrace)
 {
        int ret;
@@ -540,6 +552,11 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
                return -1;
        }
 
+       if (set_tracing_funcgraph_tail(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-tail\n");
+               return -1;
+       }
+
        return 0;
 }
 
@@ -1099,6 +1116,7 @@ static int parse_graph_tracer_opts(const struct option *opt,
                { .name = "verbose",            .value_ptr = &ftrace->graph_verbose },
                { .name = "thresh",             .value_ptr = &ftrace->graph_thresh },
                { .name = "depth",              .value_ptr = &ftrace->graph_depth },
+               { .name = "tail",               .value_ptr = &ftrace->graph_tail },
                { .name = NULL, }
        };
 
index 558efcb98d2546a818183e4c0b518e4a9f39078c..2515e841c64c4f574d8a9b02e9e9bdfe4e2fb74e 100644 (file)
@@ -25,6 +25,7 @@ struct perf_ftrace {
        int                     graph_noirqs;
        int                     graph_verbose;
        int                     graph_thresh;
+       int                     graph_tail;
 };
 
 struct filter_entry {