Skip to content

Commit 5b34747

Browse files
changbinduacmel
authored andcommitted
perf ftrace: Add option '--inherit' to trace children processes
This adds an option '--inherit' to allow us trace children processes spawned by our target. Signed-off-by: Changbin Du <[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 81523c1 commit 5b34747

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ OPTIONS
5858
Set the size of per-cpu tracing buffer, <size> is expected to
5959
be a number with appended unit character - B/K/M/G.
6060

61+
--inherit::
62+
Trace children processes spawned by our target.
63+
6164
-T::
6265
--trace-funcs=::
6366
Select function tracer and set function filter on the given

tools/perf/builtin-ftrace.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct perf_ftrace {
4141
struct list_head nograph_funcs;
4242
int graph_depth;
4343
unsigned long percpu_buffer_size;
44+
bool inherit;
4445
};
4546

4647
struct filter_entry {
@@ -182,9 +183,27 @@ static int write_tracing_file_int(const char *name, int value)
182183
return 0;
183184
}
184185

186+
static int write_tracing_option_file(const char *name, const char *val)
187+
{
188+
char *file;
189+
int ret;
190+
191+
if (asprintf(&file, "options/%s", name) < 0)
192+
return -1;
193+
194+
ret = __write_tracing_file(file, val, false);
195+
free(file);
196+
return ret;
197+
}
198+
185199
static int reset_tracing_cpu(void);
186200
static void reset_tracing_filters(void);
187201

202+
static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
203+
{
204+
write_tracing_option_file("function-fork", "0");
205+
}
206+
188207
static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
189208
{
190209
if (write_tracing_file("tracing_on", "0") < 0)
@@ -203,6 +222,7 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
203222
return -1;
204223

205224
reset_tracing_filters();
225+
reset_tracing_options(ftrace);
206226
return 0;
207227
}
208228

@@ -341,6 +361,17 @@ static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace)
341361
return 0;
342362
}
343363

364+
static int set_tracing_trace_inherit(struct perf_ftrace *ftrace)
365+
{
366+
if (!ftrace->inherit)
367+
return 0;
368+
369+
if (write_tracing_option_file("function-fork", "1") < 0)
370+
return -1;
371+
372+
return 0;
373+
}
374+
344375
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
345376
{
346377
char *trace_file;
@@ -410,6 +441,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
410441
goto out_reset;
411442
}
412443

444+
if (set_tracing_trace_inherit(ftrace) < 0) {
445+
pr_err("failed to set tracing option function-fork\n");
446+
goto out_reset;
447+
}
448+
413449
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
414450
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
415451
goto out_reset;
@@ -618,6 +654,8 @@ int cmd_ftrace(int argc, const char **argv)
618654
"Max depth for function graph tracer"),
619655
OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
620656
"size of per cpu buffer", parse_buffer_size),
657+
OPT_BOOLEAN(0, "inherit", &ftrace.inherit,
658+
"trace children processes"),
621659
OPT_END()
622660
};
623661

0 commit comments

Comments
 (0)