Skip to content

Commit b1d84af

Browse files
changbinduacmel
authored andcommitted
perf ftrace: Add support for tracing option 'func_stack_trace'
This adds support to display call trace for function tracer. To do this, just specify a '--func-opts call-graph' option. Example: $ sudo perf ftrace -T vfs_read --func-opts call-graph iio-sensor-prox-855 [003] 6168.369657: vfs_read <-ksys_read iio-sensor-prox-855 [003] 6168.369677: <stack trace> => vfs_read => ksys_read => __x64_sys_read => do_syscall_64 => entry_SYSCALL_64_after_hwframe ... Signed-off-by: Changbin Du <[email protected]> Acked-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt (VMware) <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a80abe2 commit b1d84af

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ OPTIONS
7676
specify multiple functions (or glob patterns). It will be
7777
passed to 'set_ftrace_notrace' in tracefs.
7878

79+
--func-opts::
80+
List of options allowed to set:
81+
call-graph - Display kernel stack trace for function tracer.
82+
7983
-G::
8084
--graph-funcs=::
8185
Select function_graph tracer and set graph filter on the given

tools/perf/builtin-ftrace.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "util/cap.h"
2828
#include "util/config.h"
2929
#include "util/units.h"
30+
#include "util/parse-sublevel-options.h"
3031

3132
#define DEFAULT_TRACER "function_graph"
3233

@@ -42,6 +43,7 @@ struct perf_ftrace {
4243
int graph_depth;
4344
unsigned long percpu_buffer_size;
4445
bool inherit;
46+
int func_stack_trace;
4547
};
4648

4749
struct filter_entry {
@@ -202,6 +204,7 @@ static void reset_tracing_filters(void);
202204
static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
203205
{
204206
write_tracing_option_file("function-fork", "0");
207+
write_tracing_option_file("func_stack_trace", "0");
205208
}
206209

207210
static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
@@ -278,6 +281,17 @@ static int set_tracing_cpu(struct perf_ftrace *ftrace)
278281
return set_tracing_cpumask(cpumap);
279282
}
280283

284+
static int set_tracing_func_stack_trace(struct perf_ftrace *ftrace)
285+
{
286+
if (!ftrace->func_stack_trace)
287+
return 0;
288+
289+
if (write_tracing_option_file("func_stack_trace", "1") < 0)
290+
return -1;
291+
292+
return 0;
293+
}
294+
281295
static int reset_tracing_cpu(void)
282296
{
283297
struct perf_cpu_map *cpumap = perf_cpu_map__new(NULL);
@@ -426,6 +440,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
426440
goto out_reset;
427441
}
428442

443+
if (set_tracing_func_stack_trace(ftrace) < 0) {
444+
pr_err("failed to set tracing option func_stack_trace\n");
445+
goto out_reset;
446+
}
447+
429448
if (set_tracing_filters(ftrace) < 0) {
430449
pr_err("failed to set tracing filters\n");
431450
goto out_reset;
@@ -598,6 +617,26 @@ static int parse_buffer_size(const struct option *opt,
598617
return -1;
599618
}
600619

620+
static int parse_func_tracer_opts(const struct option *opt,
621+
const char *str, int unset)
622+
{
623+
int ret;
624+
struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
625+
struct sublevel_option func_tracer_opts[] = {
626+
{ .name = "call-graph", .value_ptr = &ftrace->func_stack_trace },
627+
{ .name = NULL, }
628+
};
629+
630+
if (unset)
631+
return 0;
632+
633+
ret = perf_parse_sublevel_options(str, func_tracer_opts);
634+
if (ret)
635+
return ret;
636+
637+
return 0;
638+
}
639+
601640
static void select_tracer(struct perf_ftrace *ftrace)
602641
{
603642
bool graph = !list_empty(&ftrace->graph_funcs) ||
@@ -645,6 +684,9 @@ int cmd_ftrace(int argc, const char **argv)
645684
parse_filter_func),
646685
OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func",
647686
"do not trace given functions", parse_filter_func),
687+
OPT_CALLBACK(0, "func-opts", &ftrace, "options",
688+
"function tracer options, available options: call-graph",
689+
parse_func_tracer_opts),
648690
OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func",
649691
"trace given functions using function_graph tracer",
650692
parse_filter_func),

0 commit comments

Comments
 (0)