Skip to content

Commit 6555c2f

Browse files
changbinduacmel
authored andcommitted
perf ftrace: Add option -D/--delay to delay tracing
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]>
1 parent a8f87a5 commit 6555c2f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ OPTIONS
3939
--pid=::
4040
Trace on existing process id (comma separated list).
4141

42+
-D::
43+
--delay::
44+
Time (ms) to wait before starting tracing after program start.
45+
4246
-a::
4347
--all-cpus::
4448
Force system-wide collection. Scripts run without a <command>

tools/perf/builtin-ftrace.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct perf_ftrace {
4949
int graph_noirqs;
5050
int graph_verbose;
5151
int graph_thresh;
52+
unsigned int initial_delay;
5253
};
5354

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

599-
if (write_tracing_file("tracing_on", "1") < 0) {
600-
pr_err("can't enable tracing\n");
601-
goto out_close_fd;
600+
if (!ftrace->initial_delay) {
601+
if (write_tracing_file("tracing_on", "1") < 0) {
602+
pr_err("can't enable tracing\n");
603+
goto out_close_fd;
604+
}
602605
}
603606

604607
perf_evlist__start_workload(ftrace->evlist);
605608

609+
if (ftrace->initial_delay) {
610+
usleep(ftrace->initial_delay * 1000);
611+
if (write_tracing_file("tracing_on", "1") < 0) {
612+
pr_err("can't enable tracing\n");
613+
goto out_close_fd;
614+
}
615+
}
616+
606617
while (!done) {
607618
if (poll(&pollfd, 1, -1) < 0)
608619
break;
@@ -827,6 +838,8 @@ int cmd_ftrace(int argc, const char **argv)
827838
"size of per cpu buffer", parse_buffer_size),
828839
OPT_BOOLEAN(0, "inherit", &ftrace.inherit,
829840
"trace children processes"),
841+
OPT_UINTEGER('D', "delay", &ftrace.initial_delay,
842+
"ms to wait before starting tracing after program start"),
830843
OPT_END()
831844
};
832845

0 commit comments

Comments
 (0)