diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index c407897f04359c9e253fbcb27368926419aced51..82bffac036e1d95e792e13fda38bb4c73a43e5b0 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -209,6 +209,10 @@ overrides that and uses per-thread mmaps. A side-effect of that is that inheritance is automatically disabled. --per-thread is ignored with a warning if combined with -a or -C options. +--initial-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. + SEE ALSO -------- linkperf:perf-stat[1], linkperf:perf-list[1] diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 88600158400ef005d471eaa6d53789600275a9d3..07d4cf8d3fd3058f184209a170aa64512c18c1e2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -499,7 +499,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) * (apart from group members) have enable_on_exec=1 set, * so don't spoil it by prematurely enabling them. */ - if (!target__none(&opts->target)) + if (!target__none(&opts->target) && !opts->initial_delay) perf_evlist__enable(rec->evlist); /* @@ -508,6 +508,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) if (forks) perf_evlist__start_workload(rec->evlist); + if (opts->initial_delay) { + usleep(opts->initial_delay * 1000); + perf_evlist__enable(rec->evlist); + } + for (;;) { int hits = rec->samples; @@ -877,6 +882,8 @@ const struct option record_options[] = { OPT_CALLBACK('G', "cgroup", &record.evlist, "name", "monitor event in cgroup name only", parse_cgroups), + OPT_UINTEGER(0, "initial-delay", &record.opts.initial_delay, + "ms to wait before starting measurement after program start"), OPT_STRING('u', "uid", &record.opts.target.uid_str, "user", "user to profile"), diff --git a/tools/perf/perf.h b/tools/perf/perf.h index b1cc84b01d5b935a77c0c492d50b5a1a1d8e54b5..af1ce6e14a934b1b1a3d8f4eb2d03707c4d511a0 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -269,6 +269,7 @@ struct record_opts { u64 user_interval; u16 stack_dump_size; bool sample_transaction; + unsigned initial_delay; }; #endif diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ade8d9c1c43135688717214c48bb93f1a1556c28..cd4630abfa4362ad5b19314b965accc8820fab54 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -658,7 +658,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) * Setting enable_on_exec for independent events and * group leaders for traced executed by perf. */ - if (target__none(&opts->target) && perf_evsel__is_group_leader(evsel)) + if (target__none(&opts->target) && perf_evsel__is_group_leader(evsel) && + !opts->initial_delay) attr->enable_on_exec = 1; }