On 4/15/24 8:49 AM, Jianfeng Wang wrote: > 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@xxxxxxxxxx> > --- > lib/trace-cmd/trace-ftrace.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > 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; Kindly ask for reviews on this patchset :) Here, I include a more detailed effect of this patchset. * Record process The trace-cmd record process is not changed. # trace-cmd record -p function_graph -P 4331 trace-cmd can communicate with the kernel to get the actual funcgraph_exit event format. If the kernel supports ftrace-retval, then trace-cmd will use the updated event format that has "retval" field. * Report process By default, trace-cmd won't print each function's retval. # trace-cmd report However, if one wants to turn it on and the kernel supports the feature, do the following (through fgraph plugin options): # trace-cmd report -O fgraph:depth -O fgraph:tailprint -O fgraph:retval The output looks like this: <idle>-0 [012] d.... 361.071503: funcgraph_entry: | switch_mm_irqs_off() { (0) <idle>-0 [012] d.... 361.071507: funcgraph_entry: 0.491 us | load_new_mm_cr3(); (1) (ret=0) <idle>-0 [012] d.... 361.071508: funcgraph_entry: 0.251 us | switch_ldt(); (1) (ret=0) <idle>-0 [012] d.... 361.071508: funcgraph_exit: 5.901 us | } /* switch_mm_irqs_off */ (0) (ret=0) Each function's return value will be printed at the function's return point.