aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-stat.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 8ca40deaa728..2e70610649a1 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -168,11 +168,18 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
168 attr->sample_period = 0; 168 attr->sample_period = 0;
169 attr->sample_type = 0; 169 attr->sample_type = 0;
170 170
171 /*
172 * Disabling all counters initially, they will be enabled
173 * either manually by us or by kernel via enable_on_exec
174 * set later.
175 */
176 if (perf_evsel__is_group_leader(evsel))
177 attr->disabled = 1;
178
171 if (target__has_cpu(&target)) 179 if (target__has_cpu(&target))
172 return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); 180 return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
173 181
174 if (!target__has_task(&target) && perf_evsel__is_group_leader(evsel)) { 182 if (!target__has_task(&target) && perf_evsel__is_group_leader(evsel)) {
175 attr->disabled = 1;
176 if (!initial_delay) 183 if (!initial_delay)
177 attr->enable_on_exec = 1; 184 attr->enable_on_exec = 1;
178 } 185 }
@@ -251,12 +258,18 @@ static void process_interval(void)
251 print_counters(&rs, 0, NULL); 258 print_counters(&rs, 0, NULL);
252} 259}
253 260
254static void handle_initial_delay(void) 261static void enable_counters(void)
255{ 262{
256 if (initial_delay) { 263 if (initial_delay)
257 usleep(initial_delay * 1000); 264 usleep(initial_delay * 1000);
265
266 /*
267 * We need to enable counters only if:
268 * - we don't have tracee (attaching to task or cpu)
269 * - we have initial delay configured
270 */
271 if (!target__none(&target) || initial_delay)
258 perf_evlist__enable(evsel_list); 272 perf_evlist__enable(evsel_list);
259 }
260} 273}
261 274
262static volatile int workload_exec_errno; 275static volatile int workload_exec_errno;
@@ -353,7 +366,7 @@ static int __run_perf_stat(int argc, const char **argv)
353 366
354 if (forks) { 367 if (forks) {
355 perf_evlist__start_workload(evsel_list); 368 perf_evlist__start_workload(evsel_list);
356 handle_initial_delay(); 369 enable_counters();
357 370
358 if (interval) { 371 if (interval) {
359 while (!waitpid(child_pid, &status, WNOHANG)) { 372 while (!waitpid(child_pid, &status, WNOHANG)) {
@@ -372,7 +385,7 @@ static int __run_perf_stat(int argc, const char **argv)
372 if (WIFSIGNALED(status)) 385 if (WIFSIGNALED(status))
373 psignal(WTERMSIG(status), argv[0]); 386 psignal(WTERMSIG(status), argv[0]);
374 } else { 387 } else {
375 handle_initial_delay(); 388 enable_counters();
376 while (!done) { 389 while (!done) {
377 nanosleep(&ts, NULL); 390 nanosleep(&ts, NULL);
378 if (interval) 391 if (interval)