[PATCH perf-tools-next v3 4/5] perf ftrace: Support omitting execution duration in function graph tracer

From: Aaron Tomlin

Date: Sun Oct 11 2026 - 20:31:49 EST


The Linux kernel's function graph tracer displays the execution duration
of completed functions by default via the funcgraph-duration trace
option. Whilst informative, in scenarios where the user is solely
interested in the call graph topology, call flow sequence, or inlined
hierarchy, the duration column can add visual clutter and widen each
trace line.

Introduce support for omitting function duration by exposing the
noduration sub-option under --graph-opts. Consistent with the existing
nosleep-time and noirqs sub-options, it accepts an optional value, so
noduration=0 explicitly retains the duration column; when specified
more than once, the last occurrence takes effect. When enabled, perf
ftrace configures the kernel's tracing instance option
funcgraph-duration to 0, and restores it to 1 upon resetting tracing
options.

Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>
---
tools/perf/Documentation/perf-ftrace.txt | 1 +
tools/perf/builtin-ftrace.c | 28 +++++++++++++++++++++++-
tools/perf/tests/ftrace.c | 25 +++++++++++++++++----
tools/perf/util/ftrace.c | 15 +++++++++----
tools/perf/util/ftrace.h | 1 +
5 files changed, 61 insertions(+), 9 deletions(-)

diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 86306caf569b..a584583936bb 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -128,6 +128,7 @@ OPTIONS for 'perf ftrace trace'
- retaddr - Show function return address.
- nosleep-time - Measure on-CPU time only for function_graph tracer.
- noirqs - Ignore functions that happen inside interrupt.
+ - noduration - Do not print function duration.
- verbose - Show process names, PIDs, timestamps, etc.
- thresh=<n> - Setup trace duration threshold in microseconds.
- depth=<n> - Set max depth for function graph tracer to follow.
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 504007064e24..926726c5d9a8 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -299,6 +299,7 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
write_tracing_option_file("func_stack_trace", "0");
write_tracing_option_file("sleep-time", "1");
write_tracing_option_file("funcgraph-irqs", "1");
+ write_tracing_option_file("funcgraph-duration", "1");
write_tracing_option_file("funcgraph-proc", "0");
write_tracing_option_file("funcgraph-abstime", "0");
write_tracing_option_file("funcgraph-tail", "0");
@@ -598,6 +599,26 @@ static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
return 0;
}

+/**
+ * set_tracing_funcgraph_duration - Set funcgraph-duration tracing option
+ * @ftrace: Perf ftrace context
+ *
+ * Configure the kernel's funcgraph-duration tracing option based on the
+ * ftrace->graph_noduration flag.
+ *
+ * Return: 0 on success, or a negative error code on failure.
+ */
+static int set_tracing_funcgraph_duration(struct perf_ftrace *ftrace)
+{
+ if (!ftrace->graph_noduration)
+ return 0;
+
+ if (write_tracing_option_file("funcgraph-duration", "0") < 0)
+ return -1;
+
+ return 0;
+}
+
static int set_tracing_funcgraph_verbose(struct perf_ftrace *ftrace)
{
if (!ftrace->graph_verbose)
@@ -707,6 +728,11 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
return -1;
}

+ if (set_tracing_funcgraph_duration(ftrace) < 0) {
+ pr_err("failed to set tracing option funcgraph-duration\n");
+ return -1;
+ }
+
if (set_tracing_funcgraph_verbose(ftrace) < 0) {
pr_err("failed to set tracing option funcgraph-proc/funcgraph-abstime\n");
return -1;
@@ -1754,6 +1780,7 @@ static int parse_graph_tracer_opts(const struct option *opt,
{ .name = "retaddr", .value_ptr = &ftrace->graph_retaddr },
{ .name = "nosleep-time", .value_ptr = &ftrace->graph_nosleep_time },
{ .name = "noirqs", .value_ptr = &ftrace->graph_noirqs },
+ { .name = "noduration", .value_ptr = &ftrace->graph_noduration },
{ .name = "verbose", .value_ptr = &ftrace->graph_verbose },
{ .name = "thresh", .value_ptr = &ftrace->graph_thresh },
{ .name = "depth", .value_ptr = &ftrace->graph_depth },
@@ -1843,7 +1870,6 @@ 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: args,retval,retval-hex,retaddr,nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>",
"Graph tracer options, available options: args,retval,retval-hex,retaddr,nosleep-time,noirqs,noduration,verbose,thresh=<n>,depth=<n>,tail",
parse_graph_tracer_opts),
OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
diff --git a/tools/perf/tests/ftrace.c b/tools/perf/tests/ftrace.c
index e856bed00700..cb212339e666 100644
--- a/tools/perf/tests/ftrace.c
+++ b/tools/perf/tests/ftrace.c
@@ -303,20 +303,36 @@ static int test_column_layouts(void)
{
static const struct {
const char *desc;
- bool verbose;
+ bool noduration;
+ bool verbose;
const char *in;
const char *expected;
} cases[] = {
{
- "default layout", false,
+ "default layout", false, false,
" 7) | wake_up_new_task() { /* <-kernel_clone+0x160/0x510 */",
" 7) | wake_up_new_task() {\n",
},
{
- "verbose layout", true,
+ "noduration layout", true, false,
+ " 7) housekeeping_any_cpu(); /* <-ring_buffer_unlock_commit+0x1a0/0x1f0 */",
+ " 7) housekeeping_any_cpu();\n",
+ },
+ {
+ "verbose layout", false, true,
" 1234.567890 | 7) bash-1234 | | wake_up_new_task() { /* <-kernel_clone+0x160/0x510 */",
" 1234.567890 | 7) bash-1234 | | wake_up_new_task() {\n",
},
+ {
+ "verbose noduration layout", true, true,
+ " 1234.567890 | 7) bash-1234 | wake_up_new_task() { /* <-kernel_clone+0x160/0x510 */",
+ " 1234.567890 | 7) bash-1234 | wake_up_new_task() {\n",
+ },
+ {
+ "noduration context switch marker", true, false,
+ " 7) bash-1234 => sh-5678",
+ " 7) bash-1234 => sh-5678\n",
+ },
};
struct perf_ftrace ftrace;
char *out_buf = NULL;
@@ -328,7 +344,8 @@ static int test_column_layouts(void)
memset(&ftrace, 0, sizeof(ftrace));
ftrace.use_inline = true;
ftrace.filter_retaddr = true;
- ftrace.graph_verbose = cases[i].verbose;
+ ftrace.graph_noduration = cases[i].noduration;
+ ftrace.graph_verbose = cases[i].verbose;

out = open_memstream(&out_buf, &out_len);
if (!out)
diff --git a/tools/perf/util/ftrace.c b/tools/perf/util/ftrace.c
index 8737bb52921e..5cae01a28529 100644
--- a/tools/perf/util/ftrace.c
+++ b/tools/perf/util/ftrace.c
@@ -315,10 +315,12 @@ static void make_blank_prefix(const char *line, const char *pipe_char, char *buf
* [ abstime |] CPU) [ comm-pid |] [ duration |] func
*
* The abstime and comm-pid columns are only present with --graph-opts
- * verbose.
+ * verbose, whereas the duration column, and thus its '|' delimiter, is
+ * omitted with --graph-opts noduration.
*
* Return: A pointer to the last character of the context columns (the final
- * '|' delimiter). Returns NULL if @line is not a trace record.
+ * '|' delimiter, or the CPU ')' when no delimiter follows it). Returns NULL
+ * if @line is not a trace record (e.g. a header or a context switch marker).
*/
static const char *find_func_column(const struct perf_ftrace *ftrace,
const char *line, int *cpu)
@@ -346,9 +348,14 @@ static const char *find_func_column(const struct perf_ftrace *ftrace,
return NULL;
}

- p = strchr(p + 1, '|');
- if (!p)
+ if (!ftrace->graph_noduration) {
+ p = strchr(p + 1, '|');
+ if (!p)
+ return NULL;
+ } else if (strstr(p, " => ")) {
+ /* Context switch marker: " CPU) comm-pid => comm-pid" */
return NULL;
+ }

*cpu = (int)val;
return p;
diff --git a/tools/perf/util/ftrace.h b/tools/perf/util/ftrace.h
index 4140902d9de6..d202a09d112f 100644
--- a/tools/perf/util/ftrace.h
+++ b/tools/perf/util/ftrace.h
@@ -36,6 +36,7 @@ struct perf_ftrace {
int graph_retaddr;
int graph_nosleep_time;
int graph_noirqs;
+ int graph_noduration;
int graph_verbose;
int graph_thresh;
int graph_tail;
--
2.55.0