Skip to content

Commit d6d81bf

Browse files
changbinduacmel
authored andcommitted
perf ftrace: Add option '-F/--funcs' to list available functions
This adds an option '-F/--funcs' to list all available functions to trace, which is read from tracing file 'available_filter_functions'. $ sudo ./perf ftrace -F | head trace_initcall_finish_cb initcall_blacklisted do_one_initcall do_one_initcall trace_initcall_start_cb run_init_process try_to_run_init_process match_dev_by_label match_dev_by_uuid rootfs_init_fs_context $ Committer notes: This is the same command line option and for the same purpose as in 'perf probe'. Signed-off-by: Changbin Du <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Namhyung Kim <[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 eb6d31a commit d6d81bf

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ OPTIONS
3131
--verbose=::
3232
Verbosity level.
3333

34+
-F::
35+
--funcs::
36+
List all available functions to trace.
37+
3438
-p::
3539
--pid=::
3640
Trace on existing process id (comma separated list).

tools/perf/builtin-ftrace.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct perf_ftrace {
3333
struct evlist *evlist;
3434
struct target target;
3535
const char *tracer;
36+
bool list_avail_functions;
3637
struct list_head filters;
3738
struct list_head notrace;
3839
struct list_head graph_funcs;
@@ -128,6 +129,46 @@ static int append_tracing_file(const char *name, const char *val)
128129
return __write_tracing_file(name, val, true);
129130
}
130131

132+
static int read_tracing_file_to_stdout(const char *name)
133+
{
134+
char buf[4096];
135+
char *file;
136+
int fd;
137+
int ret = -1;
138+
139+
file = get_tracing_file(name);
140+
if (!file) {
141+
pr_debug("cannot get tracing file: %s\n", name);
142+
return -1;
143+
}
144+
145+
fd = open(file, O_RDONLY);
146+
if (fd < 0) {
147+
pr_debug("cannot open tracing file: %s: %s\n",
148+
name, str_error_r(errno, buf, sizeof(buf)));
149+
goto out;
150+
}
151+
152+
/* read contents to stdout */
153+
while (true) {
154+
int n = read(fd, buf, sizeof(buf));
155+
if (n == 0)
156+
break;
157+
else if (n < 0)
158+
goto out_close;
159+
160+
if (fwrite(buf, n, 1, stdout) != 1)
161+
goto out_close;
162+
}
163+
ret = 0;
164+
165+
out_close:
166+
close(fd);
167+
out:
168+
put_tracing_file(file);
169+
return ret;
170+
}
171+
131172
static int reset_tracing_cpu(void);
132173
static void reset_tracing_filters(void);
133174

@@ -302,6 +343,9 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
302343
signal(SIGCHLD, sig_handler);
303344
signal(SIGPIPE, sig_handler);
304345

346+
if (ftrace->list_avail_functions)
347+
return read_tracing_file_to_stdout("available_filter_functions");
348+
305349
if (reset_tracing_files(ftrace) < 0) {
306350
pr_err("failed to reset ftrace\n");
307351
goto out;
@@ -487,6 +531,8 @@ int cmd_ftrace(int argc, const char **argv)
487531
const struct option ftrace_options[] = {
488532
OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
489533
"tracer to use: function_graph(default) or function"),
534+
OPT_BOOLEAN('F', "funcs", &ftrace.list_avail_functions,
535+
"Show available functions to filter"),
490536
OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
491537
"trace on existing process id"),
492538
OPT_INCR('v', "verbose", &verbose,

0 commit comments

Comments
 (0)