This is for the function graph tracer to display more info about latency.
The execution context is shown in this case.

$ sudo perf ftrace -G --latency-format
\# tracer: function_graph
\#
 1)  .... |   0.992 us    |  mutex_unlock();
 1)  .... |   1.404 us    |  __fsnotify_parent();
 1)  .... |   1.023 us    |  fsnotify();
 1)  .... |   0.335 us    |  __sb_end_write();
 1)  d... |   0.439 us    |  fpregs_assert_state_consistent();
 1)  d... |               |  do_syscall_64() {
 1)  .... |               |    __x64_sys_close() {

Signed-off-by: Changbin Du <changbin...@gmail.com>
---
 tools/perf/builtin-ftrace.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index d376b37c53fc..fd8e2f305136 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -44,6 +44,7 @@ struct perf_ftrace {
        bool                    nosleep_time;
        bool                    nofuncgraph_irqs;
        bool                    funcgraph_tail;
+       bool                    latency_format;
        bool                    long_info;
        unsigned                tracing_thresh;
        bool                    trace_children;
@@ -217,6 +218,7 @@ static void reset_tracing_options(struct perf_ftrace 
*ftrace __maybe_unused)
        write_tracing_option_file("sleep-time", "1");
        write_tracing_option_file("funcgraph-irqs", "1");
        write_tracing_option_file("funcgraph-tail", "0");
+       write_tracing_option_file("latency-format", "0");
        write_tracing_option_file("funcgraph-proc", "0");
        write_tracing_option_file("funcgraph-abstime", "0");
        write_tracing_option_file("irq-info", "0");
@@ -456,6 +458,17 @@ static int set_tracing_funcgraph_tail(struct perf_ftrace 
*ftrace)
        return 0;
 }
 
+static int set_tracing_latency_format(struct perf_ftrace *ftrace)
+{
+       if (!ftrace->latency_format)
+               return 0;
+
+       if (write_tracing_option_file("latency-format", "1") < 0)
+               return -1;
+
+       return 0;
+}
+
 static int set_tracing_trace_children(struct perf_ftrace *ftrace)
 {
        if (!ftrace->trace_children)
@@ -579,6 +592,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
                goto out_reset;
        }
 
+       if (set_tracing_latency_format(ftrace) < 0) {
+               pr_err("failed to set tracing option latency-format\n");
+               goto out_reset;
+       }
+
        if (set_tracing_trace_children(ftrace) < 0) {
                pr_err("failed to set tracing option function-fork\n");
                goto out_reset;
@@ -748,6 +766,8 @@ int cmd_ftrace(int argc, const char **argv)
                    "Ignore functions that happen inside interrupt 
(function_graph only)"),
        OPT_BOOLEAN(0, "funcgraph-tail", &ftrace.funcgraph_tail,
                    "Show function tails comment (function_graph only)"),
+       OPT_BOOLEAN(0, "latency-format", &ftrace.latency_format,
+                   "displays additional information about the latency 
(function_graph only)"),
        OPT_BOOLEAN('l', "long-info", &ftrace.long_info,
                    "Show process names, PIDs, timestamps, irq-info if 
available"),
        OPT_UINTEGER(0, "tracing-thresh", &ftrace.tracing_thresh,
-- 
2.25.1

Reply via email to