aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/Documentation/perf-stat.txt5
-rw-r--r--tools/perf/builtin-stat.c22
2 files changed, 26 insertions, 1 deletions
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 2fe87fb558f0..73c9759005a3 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -132,6 +132,11 @@ is a useful mode to detect imbalance between physical cores. To enable this mod
132use --per-core in addition to -a. (system-wide). The output includes the 132use --per-core in addition to -a. (system-wide). The output includes the
133core number and the number of online logical processors on that physical processor. 133core number and the number of online logical processors on that physical processor.
134 134
135-D msecs::
136--initial-delay msecs::
137After starting the program, wait msecs before measuring. This is useful to
138filter out the startup phase of the program, which is often very different.
139
135EXAMPLES 140EXAMPLES
136-------- 141--------
137 142
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 352fbd7ff4a1..2e637e4c951d 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -100,6 +100,7 @@ static const char *pre_cmd = NULL;
100static const char *post_cmd = NULL; 100static const char *post_cmd = NULL;
101static bool sync_run = false; 101static bool sync_run = false;
102static unsigned int interval = 0; 102static unsigned int interval = 0;
103static unsigned int initial_delay = 0;
103static bool forever = false; 104static bool forever = false;
104static struct timespec ref_time; 105static struct timespec ref_time;
105static struct cpu_map *aggr_map; 106static struct cpu_map *aggr_map;
@@ -254,7 +255,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
254 if (!perf_target__has_task(&target) && 255 if (!perf_target__has_task(&target) &&
255 perf_evsel__is_group_leader(evsel)) { 256 perf_evsel__is_group_leader(evsel)) {
256 attr->disabled = 1; 257 attr->disabled = 1;
257 attr->enable_on_exec = 1; 258 if (!initial_delay)
259 attr->enable_on_exec = 1;
258 } 260 }
259 261
260 return perf_evsel__open_per_thread(evsel, evsel_list->threads); 262 return perf_evsel__open_per_thread(evsel, evsel_list->threads);
@@ -416,6 +418,20 @@ static void print_interval(void)
416 } 418 }
417} 419}
418 420
421static void handle_initial_delay(void)
422{
423 struct perf_evsel *counter;
424
425 if (initial_delay) {
426 const int ncpus = cpu_map__nr(evsel_list->cpus),
427 nthreads = thread_map__nr(evsel_list->threads);
428
429 usleep(initial_delay * 1000);
430 list_for_each_entry(counter, &evsel_list->entries, node)
431 perf_evsel__enable(counter, ncpus, nthreads);
432 }
433}
434
419static int __run_perf_stat(int argc, const char **argv) 435static int __run_perf_stat(int argc, const char **argv)
420{ 436{
421 char msg[512]; 437 char msg[512];
@@ -486,6 +502,7 @@ static int __run_perf_stat(int argc, const char **argv)
486 502
487 if (forks) { 503 if (forks) {
488 perf_evlist__start_workload(evsel_list); 504 perf_evlist__start_workload(evsel_list);
505 handle_initial_delay();
489 506
490 if (interval) { 507 if (interval) {
491 while (!waitpid(child_pid, &status, WNOHANG)) { 508 while (!waitpid(child_pid, &status, WNOHANG)) {
@@ -497,6 +514,7 @@ static int __run_perf_stat(int argc, const char **argv)
497 if (WIFSIGNALED(status)) 514 if (WIFSIGNALED(status))
498 psignal(WTERMSIG(status), argv[0]); 515 psignal(WTERMSIG(status), argv[0]);
499 } else { 516 } else {
517 handle_initial_delay();
500 while (!done) { 518 while (!done) {
501 nanosleep(&ts, NULL); 519 nanosleep(&ts, NULL);
502 if (interval) 520 if (interval)
@@ -1419,6 +1437,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1419 "aggregate counts per processor socket", AGGR_SOCKET), 1437 "aggregate counts per processor socket", AGGR_SOCKET),
1420 OPT_SET_UINT(0, "per-core", &aggr_mode, 1438 OPT_SET_UINT(0, "per-core", &aggr_mode,
1421 "aggregate counts per physical processor core", AGGR_CORE), 1439 "aggregate counts per physical processor core", AGGR_CORE),
1440 OPT_UINTEGER('D', "delay", &initial_delay,
1441 "ms to wait before starting measurement after program start"),
1422 OPT_END() 1442 OPT_END()
1423 }; 1443 };
1424 const char * const stat_usage[] = { 1444 const char * const stat_usage[] = {