From: Krzysztof Piecuch <piec...@kpiecuch.pl>

Adding overrun, retval, retval-hex and tail options to set
off-by-default funcgraph features.

Add nocpu, nooverhead, noduration options to turn off funcgraph
features which are on by default.

Signed-off-by: Krzysztof Piecuch <piec...@kpiecuch.pl>
---
 Documentation/trace/ftrace.rst           |   5 +-
 tools/perf/Documentation/perf-ftrace.txt |  16 +++
 tools/perf/builtin-ftrace.c              | 118 ++++++++++++++++++++++-
 tools/perf/util/ftrace.h                 |   7 ++
 4 files changed, 142 insertions(+), 4 deletions(-)

diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst
index 7e7b8ec17934..9a608a59dce6 100644
--- a/Documentation/trace/ftrace.rst
+++ b/Documentation/trace/ftrace.rst
@@ -1384,9 +1384,8 @@ Options for function_graph tracer:
        of each process displayed at every line.
 
   funcgraph-duration
-       At the end of each function (the return)
-       the duration of the amount of time in the
-       function is displayed in microseconds.
+       At the end (return) of each function the duration
+       of the function is displayed in microseconds.
 
   funcgraph-abstime
        When set, the timestamp is displayed at each line.
diff --git a/tools/perf/Documentation/perf-ftrace.txt 
b/tools/perf/Documentation/perf-ftrace.txt
index d780b93fcf87..0cf7b3301478 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -121,6 +121,22 @@ OPTIONS for 'perf ftrace trace'
        List of options allowed to set:
 
          - nosleep-time - Measure on-CPU time only for function_graph tracer.
+         - overrun      - Show number of lost events due to overwriting when
+       the buffer was full.
+         - nocpu        - Don't show the CPU which the process was running on.
+         - nooverhead   - Do not print the appropriate delay sign next to
+       long-running functions (' ' for sub-10us, '+' for sub-100us, '!' for
+       sub-1ms, '#' for sub-10ms, '*' for sub-100ms and '@' for sub-1s, '$'
+       for sub-1s runtime).
+         - noduration   - Don't show function the end of each function (the
+       return) the duration of the amount of time in the function is
+       displayed in microseconds.
+         - retval       - Print function's return value on exit. Error codes
+       are printed as signed decimals, other return values are printed as
+       hexadecimals.
+         - retval-hex   - Print all return values in hexadecimal format.
+         - tail         - Print the returning name of function next to
+       closing brackets.
          - noirqs       - Ignore functions that happen inside interrupt.
          - verbose      - Show process names, PIDs, timestamps, etc.
          - thresh=<n>   - Setup trace duration threshold in microseconds.
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index eb30c8eca488..1c58fa744758 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -225,9 +225,16 @@ static void reset_tracing_options(struct perf_ftrace 
*ftrace __maybe_unused)
        write_tracing_option_file("function-fork", "0");
        write_tracing_option_file("func_stack_trace", "0");
        write_tracing_option_file("sleep-time", "1");
+       write_tracing_option_file("funcgraph-overrun", "0");
+       write_tracing_option_file("funcgraph-cpu", "1");
+       write_tracing_option_file("funcgraph-overhead", "1");
+       write_tracing_option_file("funcgraph-duration", "1");
        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-retval", "0");
+       write_tracing_option_file("funcgraph-retval-hex", "0");
+       write_tracing_option_file("funcgraph-tail", "0");
        write_tracing_option_file("latency-format", "0");
        write_tracing_option_file("irq-info", "0");
 }
@@ -425,6 +432,42 @@ static int set_tracing_trace_inherit(struct perf_ftrace 
*ftrace)
        return 0;
 }
 
+static int set_tracing_funcgraph_overrun(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_overrun == 0)
+               return 0;
+       if (write_tracing_option_file("funcgraph-overrun", "1") < 0)
+               return -1;
+       return 0;
+}
+
+static int set_tracing_funcgraph_nocpu(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_nocpu == 0)
+               return 0;
+       if (write_tracing_option_file("funcgraph-cpu", "0") < 0)
+               return -1;
+       return 0;
+}
+
+static int set_tracing_funcgraph_nooverhead(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_nooverhead == 0)
+               return 0;
+       if (write_tracing_option_file("funcgraph-overhead", "0") < 0)
+               return -1;
+       return 0;
+}
+
+static int set_tracing_funcgraph_noduration(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_noduration == 0)
+               return 0;
+       if (write_tracing_option_file("funcgraph-duration", "0") < 0)
+               return -1;
+       return 0;
+}
+
 static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
 {
        if (!ftrace->graph_nosleep_time)
@@ -464,6 +507,37 @@ static int set_tracing_funcgraph_verbose(struct 
perf_ftrace *ftrace)
        return 0;
 }
 
+static int set_tracing_funcgraph_retval(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_retval == 0)
+               return 0;
+       if (write_tracing_option_file("funcgraph-retval", "1") < 0)
+               return -1;
+       return 0;
+}
+
+static int set_tracing_funcgraph_retval_hex(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_retval_hex == 0)
+               return 0;
+       if (ftrace->graph_retval == 0) {
+               ftrace->graph_retval = 1;
+               set_tracing_funcgraph_retval(ftrace);
+       }
+       if (write_tracing_option_file("funcgraph-retval-hex", "1") < 0)
+               return -1;
+       return 0;
+}
+
+static int set_tracing_funcgraph_tail(struct perf_ftrace *ftrace)
+{
+       if (ftrace->graph_tail == 0)
+               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;
@@ -525,11 +599,46 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
                return -1;
        }
 
+       if (set_tracing_funcgraph_overrun(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-overrun\n");
+               return -1;
+       }
+
+       if (set_tracing_funcgraph_nocpu(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-nocpu\n");
+               return -1;
+       }
+
+       if (set_tracing_funcgraph_nooverhead(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-nooverhead\n");
+               return -1;
+       }
+
+       if (set_tracing_funcgraph_noduration(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-noduration\n");
+               return -1;
+       }
+
        if (set_tracing_funcgraph_irqs(ftrace) < 0) {
                pr_err("failed to set tracing option funcgraph-irqs\n");
                return -1;
        }
 
+       if (set_tracing_funcgraph_retval(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-retval\n");
+               return -1;
+       }
+
+       if (set_tracing_funcgraph_retval_hex(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-retval-hex\n");
+               return -1;
+       }
+
+       if (set_tracing_funcgraph_tail(ftrace) < 0) {
+               pr_err("failed to set tracing option funcgraph-retval-hex\n");
+               return -1;
+       }
+
        if (set_tracing_funcgraph_verbose(ftrace) < 0) {
                pr_err("failed to set tracing option 
funcgraph-proc/funcgraph-abstime\n");
                return -1;
@@ -1094,11 +1203,18 @@ static int parse_graph_tracer_opts(const struct option 
*opt,
        int ret;
        struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
        struct sublevel_option graph_tracer_opts[] = {
+               { .name = "overrun",            .value_ptr = 
&ftrace->graph_overrun },
+               { .name = "nocpu",              .value_ptr = 
&ftrace->graph_nocpu },
+               { .name = "nooverhead", .value_ptr = &ftrace->graph_nooverhead 
},
+               { .name = "noduration", .value_ptr = &ftrace->graph_noduration 
},
                { .name = "nosleep-time",       .value_ptr = 
&ftrace->graph_nosleep_time },
                { .name = "noirqs",             .value_ptr = 
&ftrace->graph_noirqs },
                { .name = "verbose",            .value_ptr = 
&ftrace->graph_verbose },
                { .name = "thresh",             .value_ptr = 
&ftrace->graph_thresh },
                { .name = "depth",              .value_ptr = 
&ftrace->graph_depth },
+               { .name = "retval-hex", .value_ptr = &ftrace->graph_retval_hex 
},
+               { .name = "retval",             .value_ptr = 
&ftrace->graph_retval },
+               { .name = "tail",               .value_ptr = 
&ftrace->graph_tail },
                { .name = NULL, }
        };
 
@@ -1160,7 +1276,7 @@ int cmd_ftrace(int argc, const char **argv)
        OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
                     "Set nograph filter on given functions", 
parse_filter_func),
        OPT_CALLBACK(0, "graph-opts", &ftrace, "options",
-                    "Graph tracer options, available options: 
nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>",
+                    "Graph tracer options, available options: 
overrun,nocpu,nooverhead,noduration,nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>,retval,retval-hex,tail",
                     parse_graph_tracer_opts),
        OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
                     "Size of per cpu buffer, needs to use a B, K, M or G 
suffix.", parse_buffer_size),
diff --git a/tools/perf/util/ftrace.h b/tools/perf/util/ftrace.h
index 558efcb98d25..a94b92389cb8 100644
--- a/tools/perf/util/ftrace.h
+++ b/tools/perf/util/ftrace.h
@@ -18,7 +18,14 @@ struct perf_ftrace {
        unsigned long           percpu_buffer_size;
        bool                    inherit;
        bool                    use_nsec;
+       int                     graph_overrun;
+       int                     graph_nocpu;
+       int                     graph_nooverhead;
+       int                     graph_noduration;
        int                     graph_depth;
+       int                     graph_retval;
+       int                     graph_retval_hex;
+       int                     graph_tail;
        int                     func_stack_trace;
        int                     func_irq_info;
        int                     graph_nosleep_time;
-- 
2.44.0



Reply via email to