linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr
@ 2025-06-13 11:40 Changbin Du
  2025-07-22 10:03 ` duchangbin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Changbin Du @ 2025-06-13 11:40 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel,
	Changbin Du

This change adds support for new funcgraph tracer options funcgraph-args,
funcgraph-retval, funcgraph-retval-hex and funcgraph-retaddr.

The new added options are:
  - args       : Show function arguments.
  - retval     : Show function return value.
  - retval-hex : Show function return value in hexadecimal format.
  - retaddr    : Show function return address.

 # ./perf ftrace -G vfs_write --graph-opts retval,retaddr
 # tracer: function_graph
 #
 # CPU  DURATION                  FUNCTION CALLS
 # |     |   |                     |   |   |   |
 5)               |  mutex_unlock() { /* <-rb_simple_write+0xda/0x150 */
 5)   0.188 us    |    local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cf90e */
 5)               |    rt_mutex_slowunlock() { /* <-rb_simple_write+0xda/0x150 */
 5)               |      _raw_spin_lock_irqsave() { /* <-rt_mutex_slowunlock+0x4f/0x200 */
 5)   0.123 us    |        preempt_count_add(); /* <-_raw_spin_lock_irqsave+0x23/0x90 ret=0x0 */
 5)   0.128 us    |        local_clock(); /* <-__lock_acquire.isra.0+0x17a/0x740 ret=0x3bf2a3cfc8b */
 5)   0.086 us    |        do_raw_spin_trylock(); /* <-_raw_spin_lock_irqsave+0x4a/0x90 ret=0x1 */
 5)   0.845 us    |      } /* _raw_spin_lock_irqsave ret=0x292 */
 5)               |      _raw_spin_unlock_irqrestore() { /* <-rt_mutex_slowunlock+0x191/0x200 */
 5)   0.097 us    |        local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cff1f */
 5)   0.086 us    |        do_raw_spin_unlock(); /* <-_raw_spin_unlock_irqrestore+0x23/0x60 ret=0x1 */
 5)   0.104 us    |        preempt_count_sub(); /* <-_raw_spin_unlock_irqrestore+0x35/0x60 ret=0x0 */
 5)   0.726 us    |      } /* _raw_spin_unlock_irqrestore ret=0x80000000 */
 5)   1.881 us    |    } /* rt_mutex_slowunlock ret=0x0 */
 5)   2.931 us    |  } /* mutex_unlock ret=0x0 */

Signed-off-by: Changbin Du <changbin.du@huawei.com>
---
 tools/perf/Documentation/perf-ftrace.txt |  4 ++
 tools/perf/builtin-ftrace.c              | 60 +++++++++++++++++++++++-
 tools/perf/util/ftrace.h                 |  4 ++
 3 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index b77f58c4d2fd..4b21a755132f 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -123,6 +123,10 @@ OPTIONS for 'perf ftrace trace'
 --graph-opts::
 	List of options allowed to set:
 
+	  - args         - Show function arguments.
+	  - retval       - Show function return value.
+	  - retval-hex   - Show function return value in hexadecimal format.
+	  - retaddr      - Show function return address.
 	  - nosleep-time - Measure on-CPU time only for function_graph tracer.
 	  - noirqs       - Ignore functions that happen inside interrupt.
 	  - verbose      - Show process names, PIDs, timestamps, etc.
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index bba36ebc2aa7..f7cf1dd7b64b 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -301,6 +301,10 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
 	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("funcgraph-args", "0");
+	write_tracing_option_file("funcgraph-retval", "0");
+	write_tracing_option_file("funcgraph-retval-hex", "0");
+	write_tracing_option_file("funcgraph-retaddr", "0");
 	write_tracing_option_file("latency-format", "0");
 	write_tracing_option_file("irq-info", "0");
 }
@@ -542,6 +546,41 @@ static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
 	return 0;
 }
 
+static int set_tracing_funcgraph_args(struct perf_ftrace *ftrace)
+{
+	if (ftrace->graph_args) {
+		if (write_tracing_option_file("funcgraph-args", "1") < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static int set_tracing_funcgraph_retval(struct perf_ftrace *ftrace)
+{
+	if (ftrace->graph_retval || ftrace->graph_retval_hex) {
+		if (write_tracing_option_file("funcgraph-retval", "1") < 0)
+			return -1;
+	}
+
+	if (ftrace->graph_retval_hex) {
+		if (write_tracing_option_file("funcgraph-retval-hex", "1") < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static int set_tracing_funcgraph_retaddr(struct perf_ftrace *ftrace)
+{
+	if (ftrace->graph_retaddr) {
+		if (write_tracing_option_file("funcgraph-retaddr", "1") < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
 static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
 {
 	if (!ftrace->graph_noirqs)
@@ -642,6 +681,21 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
 		return -1;
 	}
 
+	if (set_tracing_funcgraph_args(ftrace) < 0) {
+		pr_err("failed to set tracing option funcgraph-args\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_retaddr(ftrace) < 0) {
+		pr_err("failed to set tracing option funcgraph-retaddr\n");
+		return -1;
+	}
+
 	if (set_tracing_funcgraph_irqs(ftrace) < 0) {
 		pr_err("failed to set tracing option funcgraph-irqs\n");
 		return -1;
@@ -1607,6 +1661,10 @@ 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 = "args",		.value_ptr = &ftrace->graph_args },
+		{ .name = "retval",		.value_ptr = &ftrace->graph_retval },
+		{ .name = "retval-hex",		.value_ptr = &ftrace->graph_retval_hex },
+		{ .name = "retaddr",		.value_ptr = &ftrace->graph_retaddr },
 		{ .name = "nosleep-time",	.value_ptr = &ftrace->graph_nosleep_time },
 		{ .name = "noirqs",		.value_ptr = &ftrace->graph_noirqs },
 		{ .name = "verbose",		.value_ptr = &ftrace->graph_verbose },
@@ -1699,7 +1757,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: args,retval,retval-hex,retaddr,nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>",
 		     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 a9bc47da83a5..782c33227e92 100644
--- a/tools/perf/util/ftrace.h
+++ b/tools/perf/util/ftrace.h
@@ -29,6 +29,10 @@ struct perf_ftrace {
 	int			graph_depth;
 	int			func_stack_trace;
 	int			func_irq_info;
+	int			graph_args;
+	int			graph_retval;
+	int			graph_retval_hex;
+	int			graph_retaddr;
 	int			graph_nosleep_time;
 	int			graph_noirqs;
 	int			graph_verbose;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr
  2025-06-13 11:40 [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr Changbin Du
@ 2025-07-22 10:03 ` duchangbin
  2025-07-23  0:53   ` Namhyung Kim
  2025-07-22 15:10 ` Ian Rogers
  2025-07-23 17:30 ` Namhyung Kim
  2 siblings, 1 reply; 5+ messages in thread
From: duchangbin @ 2025-07-22 10:03 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org

Kindly ping.

On Fri, Jun 13, 2025 at 07:40:47PM +0800, Changbin Du wrote:
> This change adds support for new funcgraph tracer options funcgraph-args,
> funcgraph-retval, funcgraph-retval-hex and funcgraph-retaddr.
> 
> The new added options are:
>   - args       : Show function arguments.
>   - retval     : Show function return value.
>   - retval-hex : Show function return value in hexadecimal format.
>   - retaddr    : Show function return address.
> 
>  # ./perf ftrace -G vfs_write --graph-opts retval,retaddr
>  # tracer: function_graph
>  #
>  # CPU  DURATION                  FUNCTION CALLS
>  # |     |   |                     |   |   |   |
>  5)               |  mutex_unlock() { /* <-rb_simple_write+0xda/0x150 */
>  5)   0.188 us    |    local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cf90e */
>  5)               |    rt_mutex_slowunlock() { /* <-rb_simple_write+0xda/0x150 */
>  5)               |      _raw_spin_lock_irqsave() { /* <-rt_mutex_slowunlock+0x4f/0x200 */
>  5)   0.123 us    |        preempt_count_add(); /* <-_raw_spin_lock_irqsave+0x23/0x90 ret=0x0 */
>  5)   0.128 us    |        local_clock(); /* <-__lock_acquire.isra.0+0x17a/0x740 ret=0x3bf2a3cfc8b */
>  5)   0.086 us    |        do_raw_spin_trylock(); /* <-_raw_spin_lock_irqsave+0x4a/0x90 ret=0x1 */
>  5)   0.845 us    |      } /* _raw_spin_lock_irqsave ret=0x292 */
>  5)               |      _raw_spin_unlock_irqrestore() { /* <-rt_mutex_slowunlock+0x191/0x200 */
>  5)   0.097 us    |        local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cff1f */
>  5)   0.086 us    |        do_raw_spin_unlock(); /* <-_raw_spin_unlock_irqrestore+0x23/0x60 ret=0x1 */
>  5)   0.104 us    |        preempt_count_sub(); /* <-_raw_spin_unlock_irqrestore+0x35/0x60 ret=0x0 */
>  5)   0.726 us    |      } /* _raw_spin_unlock_irqrestore ret=0x80000000 */
>  5)   1.881 us    |    } /* rt_mutex_slowunlock ret=0x0 */
>  5)   2.931 us    |  } /* mutex_unlock ret=0x0 */
> 
> Signed-off-by: Changbin Du <changbin.du@huawei.com>
> ---
>  tools/perf/Documentation/perf-ftrace.txt |  4 ++
>  tools/perf/builtin-ftrace.c              | 60 +++++++++++++++++++++++-
>  tools/perf/util/ftrace.h                 |  4 ++
>  3 files changed, 67 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
> index b77f58c4d2fd..4b21a755132f 100644
> --- a/tools/perf/Documentation/perf-ftrace.txt
> +++ b/tools/perf/Documentation/perf-ftrace.txt
> @@ -123,6 +123,10 @@ OPTIONS for 'perf ftrace trace'
>  --graph-opts::
>  	List of options allowed to set:
>  
> +	  - args         - Show function arguments.
> +	  - retval       - Show function return value.
> +	  - retval-hex   - Show function return value in hexadecimal format.
> +	  - retaddr      - Show function return address.
>  	  - nosleep-time - Measure on-CPU time only for function_graph tracer.
>  	  - noirqs       - Ignore functions that happen inside interrupt.
>  	  - verbose      - Show process names, PIDs, timestamps, etc.
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index bba36ebc2aa7..f7cf1dd7b64b 100644
> --- a/tools/perf/builtin-ftrace.c
> +++ b/tools/perf/builtin-ftrace.c
> @@ -301,6 +301,10 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
>  	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("funcgraph-args", "0");
> +	write_tracing_option_file("funcgraph-retval", "0");
> +	write_tracing_option_file("funcgraph-retval-hex", "0");
> +	write_tracing_option_file("funcgraph-retaddr", "0");
>  	write_tracing_option_file("latency-format", "0");
>  	write_tracing_option_file("irq-info", "0");
>  }
> @@ -542,6 +546,41 @@ static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
>  	return 0;
>  }
>  
> +static int set_tracing_funcgraph_args(struct perf_ftrace *ftrace)
> +{
> +	if (ftrace->graph_args) {
> +		if (write_tracing_option_file("funcgraph-args", "1") < 0)
> +			return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +static int set_tracing_funcgraph_retval(struct perf_ftrace *ftrace)
> +{
> +	if (ftrace->graph_retval || ftrace->graph_retval_hex) {
> +		if (write_tracing_option_file("funcgraph-retval", "1") < 0)
> +			return -1;
> +	}
> +
> +	if (ftrace->graph_retval_hex) {
> +		if (write_tracing_option_file("funcgraph-retval-hex", "1") < 0)
> +			return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +static int set_tracing_funcgraph_retaddr(struct perf_ftrace *ftrace)
> +{
> +	if (ftrace->graph_retaddr) {
> +		if (write_tracing_option_file("funcgraph-retaddr", "1") < 0)
> +			return -1;
> +	}
> +
> +	return 0;
> +}
> +
>  static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
>  {
>  	if (!ftrace->graph_noirqs)
> @@ -642,6 +681,21 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
>  		return -1;
>  	}
>  
> +	if (set_tracing_funcgraph_args(ftrace) < 0) {
> +		pr_err("failed to set tracing option funcgraph-args\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_retaddr(ftrace) < 0) {
> +		pr_err("failed to set tracing option funcgraph-retaddr\n");
> +		return -1;
> +	}
> +
>  	if (set_tracing_funcgraph_irqs(ftrace) < 0) {
>  		pr_err("failed to set tracing option funcgraph-irqs\n");
>  		return -1;
> @@ -1607,6 +1661,10 @@ 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 = "args",		.value_ptr = &ftrace->graph_args },
> +		{ .name = "retval",		.value_ptr = &ftrace->graph_retval },
> +		{ .name = "retval-hex",		.value_ptr = &ftrace->graph_retval_hex },
> +		{ .name = "retaddr",		.value_ptr = &ftrace->graph_retaddr },
>  		{ .name = "nosleep-time",	.value_ptr = &ftrace->graph_nosleep_time },
>  		{ .name = "noirqs",		.value_ptr = &ftrace->graph_noirqs },
>  		{ .name = "verbose",		.value_ptr = &ftrace->graph_verbose },
> @@ -1699,7 +1757,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: args,retval,retval-hex,retaddr,nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>",
>  		     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 a9bc47da83a5..782c33227e92 100644
> --- a/tools/perf/util/ftrace.h
> +++ b/tools/perf/util/ftrace.h
> @@ -29,6 +29,10 @@ struct perf_ftrace {
>  	int			graph_depth;
>  	int			func_stack_trace;
>  	int			func_irq_info;
> +	int			graph_args;
> +	int			graph_retval;
> +	int			graph_retval_hex;
> +	int			graph_retaddr;
>  	int			graph_nosleep_time;
>  	int			graph_noirqs;
>  	int			graph_verbose;
> -- 
> 2.43.0
> 

-- 
Cheers,
Changbin Du

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr
  2025-06-13 11:40 [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr Changbin Du
  2025-07-22 10:03 ` duchangbin
@ 2025-07-22 15:10 ` Ian Rogers
  2025-07-23 17:30 ` Namhyung Kim
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2025-07-22 15:10 UTC (permalink / raw)
  To: Changbin Du
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel

On Fri, Jun 13, 2025 at 4:41 AM Changbin Du <changbin.du@huawei.com> wrote:
>
> This change adds support for new funcgraph tracer options funcgraph-args,
> funcgraph-retval, funcgraph-retval-hex and funcgraph-retaddr.
>
> The new added options are:
>   - args       : Show function arguments.
>   - retval     : Show function return value.
>   - retval-hex : Show function return value in hexadecimal format.
>   - retaddr    : Show function return address.
>
>  # ./perf ftrace -G vfs_write --graph-opts retval,retaddr
>  # tracer: function_graph
>  #
>  # CPU  DURATION                  FUNCTION CALLS
>  # |     |   |                     |   |   |   |
>  5)               |  mutex_unlock() { /* <-rb_simple_write+0xda/0x150 */
>  5)   0.188 us    |    local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cf90e */
>  5)               |    rt_mutex_slowunlock() { /* <-rb_simple_write+0xda/0x150 */
>  5)               |      _raw_spin_lock_irqsave() { /* <-rt_mutex_slowunlock+0x4f/0x200 */
>  5)   0.123 us    |        preempt_count_add(); /* <-_raw_spin_lock_irqsave+0x23/0x90 ret=0x0 */
>  5)   0.128 us    |        local_clock(); /* <-__lock_acquire.isra.0+0x17a/0x740 ret=0x3bf2a3cfc8b */
>  5)   0.086 us    |        do_raw_spin_trylock(); /* <-_raw_spin_lock_irqsave+0x4a/0x90 ret=0x1 */
>  5)   0.845 us    |      } /* _raw_spin_lock_irqsave ret=0x292 */
>  5)               |      _raw_spin_unlock_irqrestore() { /* <-rt_mutex_slowunlock+0x191/0x200 */
>  5)   0.097 us    |        local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cff1f */
>  5)   0.086 us    |        do_raw_spin_unlock(); /* <-_raw_spin_unlock_irqrestore+0x23/0x60 ret=0x1 */
>  5)   0.104 us    |        preempt_count_sub(); /* <-_raw_spin_unlock_irqrestore+0x35/0x60 ret=0x0 */
>  5)   0.726 us    |      } /* _raw_spin_unlock_irqrestore ret=0x80000000 */
>  5)   1.881 us    |    } /* rt_mutex_slowunlock ret=0x0 */
>  5)   2.931 us    |  } /* mutex_unlock ret=0x0 */
>
> Signed-off-by: Changbin Du <changbin.du@huawei.com>

I tried testing but lacked the kernel features. It built and I checked the code:

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/Documentation/perf-ftrace.txt |  4 ++
>  tools/perf/builtin-ftrace.c              | 60 +++++++++++++++++++++++-
>  tools/perf/util/ftrace.h                 |  4 ++
>  3 files changed, 67 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
> index b77f58c4d2fd..4b21a755132f 100644
> --- a/tools/perf/Documentation/perf-ftrace.txt
> +++ b/tools/perf/Documentation/perf-ftrace.txt
> @@ -123,6 +123,10 @@ OPTIONS for 'perf ftrace trace'
>  --graph-opts::
>         List of options allowed to set:
>
> +         - args         - Show function arguments.
> +         - retval       - Show function return value.
> +         - retval-hex   - Show function return value in hexadecimal format.
> +         - retaddr      - Show function return address.
>           - nosleep-time - Measure on-CPU time only for function_graph tracer.
>           - noirqs       - Ignore functions that happen inside interrupt.
>           - verbose      - Show process names, PIDs, timestamps, etc.
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index bba36ebc2aa7..f7cf1dd7b64b 100644
> --- a/tools/perf/builtin-ftrace.c
> +++ b/tools/perf/builtin-ftrace.c
> @@ -301,6 +301,10 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
>         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("funcgraph-args", "0");
> +       write_tracing_option_file("funcgraph-retval", "0");
> +       write_tracing_option_file("funcgraph-retval-hex", "0");
> +       write_tracing_option_file("funcgraph-retaddr", "0");
>         write_tracing_option_file("latency-format", "0");
>         write_tracing_option_file("irq-info", "0");
>  }
> @@ -542,6 +546,41 @@ static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
>         return 0;
>  }
>
> +static int set_tracing_funcgraph_args(struct perf_ftrace *ftrace)
> +{
> +       if (ftrace->graph_args) {
> +               if (write_tracing_option_file("funcgraph-args", "1") < 0)
> +                       return -1;
> +       }
> +
> +       return 0;
> +}
> +
> +static int set_tracing_funcgraph_retval(struct perf_ftrace *ftrace)
> +{
> +       if (ftrace->graph_retval || ftrace->graph_retval_hex) {
> +               if (write_tracing_option_file("funcgraph-retval", "1") < 0)
> +                       return -1;
> +       }
> +
> +       if (ftrace->graph_retval_hex) {
> +               if (write_tracing_option_file("funcgraph-retval-hex", "1") < 0)
> +                       return -1;
> +       }
> +
> +       return 0;
> +}
> +
> +static int set_tracing_funcgraph_retaddr(struct perf_ftrace *ftrace)
> +{
> +       if (ftrace->graph_retaddr) {
> +               if (write_tracing_option_file("funcgraph-retaddr", "1") < 0)
> +                       return -1;
> +       }
> +
> +       return 0;
> +}
> +
>  static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
>  {
>         if (!ftrace->graph_noirqs)
> @@ -642,6 +681,21 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
>                 return -1;
>         }
>
> +       if (set_tracing_funcgraph_args(ftrace) < 0) {
> +               pr_err("failed to set tracing option funcgraph-args\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_retaddr(ftrace) < 0) {
> +               pr_err("failed to set tracing option funcgraph-retaddr\n");
> +               return -1;
> +       }
> +
>         if (set_tracing_funcgraph_irqs(ftrace) < 0) {
>                 pr_err("failed to set tracing option funcgraph-irqs\n");
>                 return -1;
> @@ -1607,6 +1661,10 @@ 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 = "args",               .value_ptr = &ftrace->graph_args },
> +               { .name = "retval",             .value_ptr = &ftrace->graph_retval },
> +               { .name = "retval-hex",         .value_ptr = &ftrace->graph_retval_hex },
> +               { .name = "retaddr",            .value_ptr = &ftrace->graph_retaddr },
>                 { .name = "nosleep-time",       .value_ptr = &ftrace->graph_nosleep_time },
>                 { .name = "noirqs",             .value_ptr = &ftrace->graph_noirqs },
>                 { .name = "verbose",            .value_ptr = &ftrace->graph_verbose },
> @@ -1699,7 +1757,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: args,retval,retval-hex,retaddr,nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>",
>                      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 a9bc47da83a5..782c33227e92 100644
> --- a/tools/perf/util/ftrace.h
> +++ b/tools/perf/util/ftrace.h
> @@ -29,6 +29,10 @@ struct perf_ftrace {
>         int                     graph_depth;
>         int                     func_stack_trace;
>         int                     func_irq_info;
> +       int                     graph_args;
> +       int                     graph_retval;
> +       int                     graph_retval_hex;
> +       int                     graph_retaddr;
>         int                     graph_nosleep_time;
>         int                     graph_noirqs;
>         int                     graph_verbose;
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr
  2025-07-22 10:03 ` duchangbin
@ 2025-07-23  0:53   ` Namhyung Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2025-07-23  0:53 UTC (permalink / raw)
  To: duchangbin
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org

Hello,

On Tue, Jul 22, 2025 at 10:03:58AM +0000, duchangbin wrote:
> Kindly ping.

Sorry for the delay, processing now...

Thanks,
Namhyung

> 
> On Fri, Jun 13, 2025 at 07:40:47PM +0800, Changbin Du wrote:
> > This change adds support for new funcgraph tracer options funcgraph-args,
> > funcgraph-retval, funcgraph-retval-hex and funcgraph-retaddr.
> > 
> > The new added options are:
> >   - args       : Show function arguments.
> >   - retval     : Show function return value.
> >   - retval-hex : Show function return value in hexadecimal format.
> >   - retaddr    : Show function return address.
> > 
> >  # ./perf ftrace -G vfs_write --graph-opts retval,retaddr
> >  # tracer: function_graph
> >  #
> >  # CPU  DURATION                  FUNCTION CALLS
> >  # |     |   |                     |   |   |   |
> >  5)               |  mutex_unlock() { /* <-rb_simple_write+0xda/0x150 */
> >  5)   0.188 us    |    local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cf90e */
> >  5)               |    rt_mutex_slowunlock() { /* <-rb_simple_write+0xda/0x150 */
> >  5)               |      _raw_spin_lock_irqsave() { /* <-rt_mutex_slowunlock+0x4f/0x200 */
> >  5)   0.123 us    |        preempt_count_add(); /* <-_raw_spin_lock_irqsave+0x23/0x90 ret=0x0 */
> >  5)   0.128 us    |        local_clock(); /* <-__lock_acquire.isra.0+0x17a/0x740 ret=0x3bf2a3cfc8b */
> >  5)   0.086 us    |        do_raw_spin_trylock(); /* <-_raw_spin_lock_irqsave+0x4a/0x90 ret=0x1 */
> >  5)   0.845 us    |      } /* _raw_spin_lock_irqsave ret=0x292 */
> >  5)               |      _raw_spin_unlock_irqrestore() { /* <-rt_mutex_slowunlock+0x191/0x200 */
> >  5)   0.097 us    |        local_clock(); /* <-lock_release+0x2ad/0x440 ret=0x3bf2a3cff1f */
> >  5)   0.086 us    |        do_raw_spin_unlock(); /* <-_raw_spin_unlock_irqrestore+0x23/0x60 ret=0x1 */
> >  5)   0.104 us    |        preempt_count_sub(); /* <-_raw_spin_unlock_irqrestore+0x35/0x60 ret=0x0 */
> >  5)   0.726 us    |      } /* _raw_spin_unlock_irqrestore ret=0x80000000 */
> >  5)   1.881 us    |    } /* rt_mutex_slowunlock ret=0x0 */
> >  5)   2.931 us    |  } /* mutex_unlock ret=0x0 */
> > 
> > Signed-off-by: Changbin Du <changbin.du@huawei.com>
> > ---
> >  tools/perf/Documentation/perf-ftrace.txt |  4 ++
> >  tools/perf/builtin-ftrace.c              | 60 +++++++++++++++++++++++-
> >  tools/perf/util/ftrace.h                 |  4 ++
> >  3 files changed, 67 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
> > index b77f58c4d2fd..4b21a755132f 100644
> > --- a/tools/perf/Documentation/perf-ftrace.txt
> > +++ b/tools/perf/Documentation/perf-ftrace.txt
> > @@ -123,6 +123,10 @@ OPTIONS for 'perf ftrace trace'
> >  --graph-opts::
> >  	List of options allowed to set:
> >  
> > +	  - args         - Show function arguments.
> > +	  - retval       - Show function return value.
> > +	  - retval-hex   - Show function return value in hexadecimal format.
> > +	  - retaddr      - Show function return address.
> >  	  - nosleep-time - Measure on-CPU time only for function_graph tracer.
> >  	  - noirqs       - Ignore functions that happen inside interrupt.
> >  	  - verbose      - Show process names, PIDs, timestamps, etc.
> > diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> > index bba36ebc2aa7..f7cf1dd7b64b 100644
> > --- a/tools/perf/builtin-ftrace.c
> > +++ b/tools/perf/builtin-ftrace.c
> > @@ -301,6 +301,10 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
> >  	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("funcgraph-args", "0");
> > +	write_tracing_option_file("funcgraph-retval", "0");
> > +	write_tracing_option_file("funcgraph-retval-hex", "0");
> > +	write_tracing_option_file("funcgraph-retaddr", "0");
> >  	write_tracing_option_file("latency-format", "0");
> >  	write_tracing_option_file("irq-info", "0");
> >  }
> > @@ -542,6 +546,41 @@ static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
> >  	return 0;
> >  }
> >  
> > +static int set_tracing_funcgraph_args(struct perf_ftrace *ftrace)
> > +{
> > +	if (ftrace->graph_args) {
> > +		if (write_tracing_option_file("funcgraph-args", "1") < 0)
> > +			return -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int set_tracing_funcgraph_retval(struct perf_ftrace *ftrace)
> > +{
> > +	if (ftrace->graph_retval || ftrace->graph_retval_hex) {
> > +		if (write_tracing_option_file("funcgraph-retval", "1") < 0)
> > +			return -1;
> > +	}
> > +
> > +	if (ftrace->graph_retval_hex) {
> > +		if (write_tracing_option_file("funcgraph-retval-hex", "1") < 0)
> > +			return -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int set_tracing_funcgraph_retaddr(struct perf_ftrace *ftrace)
> > +{
> > +	if (ftrace->graph_retaddr) {
> > +		if (write_tracing_option_file("funcgraph-retaddr", "1") < 0)
> > +			return -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
> >  {
> >  	if (!ftrace->graph_noirqs)
> > @@ -642,6 +681,21 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
> >  		return -1;
> >  	}
> >  
> > +	if (set_tracing_funcgraph_args(ftrace) < 0) {
> > +		pr_err("failed to set tracing option funcgraph-args\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_retaddr(ftrace) < 0) {
> > +		pr_err("failed to set tracing option funcgraph-retaddr\n");
> > +		return -1;
> > +	}
> > +
> >  	if (set_tracing_funcgraph_irqs(ftrace) < 0) {
> >  		pr_err("failed to set tracing option funcgraph-irqs\n");
> >  		return -1;
> > @@ -1607,6 +1661,10 @@ 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 = "args",		.value_ptr = &ftrace->graph_args },
> > +		{ .name = "retval",		.value_ptr = &ftrace->graph_retval },
> > +		{ .name = "retval-hex",		.value_ptr = &ftrace->graph_retval_hex },
> > +		{ .name = "retaddr",		.value_ptr = &ftrace->graph_retaddr },
> >  		{ .name = "nosleep-time",	.value_ptr = &ftrace->graph_nosleep_time },
> >  		{ .name = "noirqs",		.value_ptr = &ftrace->graph_noirqs },
> >  		{ .name = "verbose",		.value_ptr = &ftrace->graph_verbose },
> > @@ -1699,7 +1757,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: args,retval,retval-hex,retaddr,nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>",
> >  		     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 a9bc47da83a5..782c33227e92 100644
> > --- a/tools/perf/util/ftrace.h
> > +++ b/tools/perf/util/ftrace.h
> > @@ -29,6 +29,10 @@ struct perf_ftrace {
> >  	int			graph_depth;
> >  	int			func_stack_trace;
> >  	int			func_irq_info;
> > +	int			graph_args;
> > +	int			graph_retval;
> > +	int			graph_retval_hex;
> > +	int			graph_retaddr;
> >  	int			graph_nosleep_time;
> >  	int			graph_noirqs;
> >  	int			graph_verbose;
> > -- 
> > 2.43.0
> > 
> 
> -- 
> Cheers,
> Changbin Du

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr
  2025-06-13 11:40 [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr Changbin Du
  2025-07-22 10:03 ` duchangbin
  2025-07-22 15:10 ` Ian Rogers
@ 2025-07-23 17:30 ` Namhyung Kim
  2 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2025-07-23 17:30 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Changbin Du
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel

On Fri, 13 Jun 2025 19:40:47 +0800, Changbin Du wrote:
> This change adds support for new funcgraph tracer options funcgraph-args,
> funcgraph-retval, funcgraph-retval-hex and funcgraph-retaddr.
> 
> The new added options are:
>   - args       : Show function arguments.
>   - retval     : Show function return value.
>   - retval-hex : Show function return value in hexadecimal format.
>   - retaddr    : Show function return address.
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-23 17:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 11:40 [PATCH] perf: ftrace: add graph tracer options args/retval/retval-hex/retaddr Changbin Du
2025-07-22 10:03 ` duchangbin
2025-07-23  0:53   ` Namhyung Kim
2025-07-22 15:10 ` Ian Rogers
2025-07-23 17:30 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).