diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt index 1ab0782369b1..781b019751a4 100644 --- a/tools/perf/Documentation/perf-trace.txt +++ b/tools/perf/Documentation/perf-trace.txt @@ -39,6 +39,11 @@ OPTIONS Prefixing with ! shows all syscalls but the ones specified. You may need to escape it. +-D msecs:: +--delay msecs:: +After starting the program, wait msecs before measuring. This is useful to +filter out the startup phase of the program, which is often very different. + -o:: --output=:: Output file name. diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index c298bd3e1d90..0bae454e8efa 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2310,12 +2310,17 @@ static int trace__run(struct trace *trace, int argc, const char **argv) if (err < 0) goto out_error_mmap; - if (!target__none(&trace->opts.target)) + if (!target__none(&trace->opts.target) && !trace->opts.initial_delay) perf_evlist__enable(evlist); if (forks) perf_evlist__start_workload(evlist); + if (trace->opts.initial_delay) { + usleep(trace->opts.initial_delay * 1000); + perf_evlist__enable(evlist); + } + trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 || evlist->threads->nr > 1 || perf_evlist__first(evlist)->attr.inherit; @@ -2816,6 +2821,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout, "per thread proc mmap processing timeout in ms"), + OPT_UINTEGER('D', "delay", &trace.opts.initial_delay, + "ms to wait before starting measurement after program " + "start"), OPT_END() }; bool __maybe_unused max_stack_user_set = true;