diff mbox series

[2/2] trace-cmd: Add ftrace options with fgraph retval option

Message ID 20240415154921.4998-3-jianfeng.w.wang@oracle.com (mailing list archive)
State New
Headers show
Series trace-cmd ftrace: support function retval feature in function_graph | expand

Commit Message

Jianfeng Wang April 15, 2024, 3:49 p.m. UTC
Added internal options for ftrace, and included a fgraph:retval
option that will print the function names at the function exit.
When the option is set and the function_graph retval feature is
supported by the kernel, each function's return value will be
printed as '(ret=retval)'.

Signed-off-by: Jianfeng Wang <jianfeng.w.wang@oracle.com>
---
 lib/trace-cmd/trace-ftrace.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-ftrace.c b/lib/trace-cmd/trace-ftrace.c
index cb05d88c..fecc3d69 100644
--- a/lib/trace-cmd/trace-ftrace.c
+++ b/lib/trace-cmd/trace-ftrace.c
@@ -23,6 +23,12 @@  struct tep_plugin_option trace_ftrace_options[] = {
 		.description =
 		"Show the depth of each entry",
 	},
+	{
+		.name = "retval",
+		.plugin_alias = "fgraph",
+		.description =
+		"Print function retval at function exit in function graph",
+	},
 	{
 		.name = NULL,
 	}
@@ -30,6 +36,7 @@  struct tep_plugin_option trace_ftrace_options[] = {
 
 static struct tep_plugin_option *fgraph_tail = &trace_ftrace_options[0];
 static struct tep_plugin_option *fgraph_depth = &trace_ftrace_options[1];
+static struct tep_plugin_option *fgraph_retval = &trace_ftrace_options[2];
 
 static int find_ret_event(struct tracecmd_ftrace *finfo, struct tep_handle *pevent)
 {
@@ -232,7 +239,7 @@  print_graph_entry_leaf(struct trace_seq *s,
 		ret = trace_seq_printf(s, " (%lld)", depth);
 
 	/* Return Value */
-	if (ret && fgraph_retval_supported)
+	if (ret && fgraph_retval->set && fgraph_retval_supported)
 		ret = trace_seq_printf(s, " (ret=%lld)", retval);
 
 	return ret;
@@ -378,7 +385,7 @@  fgraph_ret_handler(struct trace_seq *s, struct tep_record *record,
 		trace_seq_printf(s, " (%lld)", depth);
 
 	/* Return Value */
-	if (fgraph_retval_supported)
+	if (fgraph_retval->set && fgraph_retval_supported)
 		trace_seq_printf(s, " (ret=%lld)", retval);
 
 	return 0;