Skip to content

Commit

Permalink
perf ftrace: Add option -D/--delay to delay tracing
Browse files Browse the repository at this point in the history
This adds an option '-D/--delay' to allow us to start tracing some times
later after workload is launched.

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]>
  • Loading branch information
changbindu authored and acmel committed Aug 14, 2020
1 parent a8f87a5 commit 6555c2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tools/perf/Documentation/perf-ftrace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ OPTIONS
--pid=::
Trace on existing process id (comma separated list).

-D::
--delay::
Time (ms) to wait before starting tracing after program start.

-a::
--all-cpus::
Force system-wide collection. Scripts run without a <command>
Expand Down
19 changes: 16 additions & 3 deletions tools/perf/builtin-ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct perf_ftrace {
int graph_noirqs;
int graph_verbose;
int graph_thresh;
unsigned int initial_delay;
};

struct filter_entry {
Expand Down Expand Up @@ -596,13 +597,23 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
/* display column headers */
read_tracing_file_to_stdout("trace");

if (write_tracing_file("tracing_on", "1") < 0) {
pr_err("can't enable tracing\n");
goto out_close_fd;
if (!ftrace->initial_delay) {
if (write_tracing_file("tracing_on", "1") < 0) {
pr_err("can't enable tracing\n");
goto out_close_fd;
}
}

perf_evlist__start_workload(ftrace->evlist);

if (ftrace->initial_delay) {
usleep(ftrace->initial_delay * 1000);
if (write_tracing_file("tracing_on", "1") < 0) {
pr_err("can't enable tracing\n");
goto out_close_fd;
}
}

while (!done) {
if (poll(&pollfd, 1, -1) < 0)
break;
Expand Down Expand Up @@ -827,6 +838,8 @@ int cmd_ftrace(int argc, const char **argv)
"size of per cpu buffer", parse_buffer_size),
OPT_BOOLEAN(0, "inherit", &ftrace.inherit,
"trace children processes"),
OPT_UINTEGER('D', "delay", &ftrace.initial_delay,
"ms to wait before starting tracing after program start"),
OPT_END()
};

Expand Down

0 comments on commit 6555c2f

Please sign in to comment.