aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2015-12-03 04:06:44 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-12-07 16:12:59 -0500
commit67ccdecd09cac818146b1e153ff901cb67570012 (patch)
treec0aec4f06541d9c887e1939b00499448701b988a /tools/perf
parentab46db0a3325a064bb24e826b12995d157565efb (diff)
perf stat: Create events as disabled
Currently we have 2 kinds of stat counters based on when the event is enabled: 1) tracee command events, which are enable once the tracee executes exec syscall (enable_on_exec bit) 2) all other events which get alive within the perf_event_open syscall And 2) case could raise a problem in case we want additional filter to be attached for event. In this case we want the event to be enabled after it's configured with filter. Changing the behaviour of 2) events, so they all are created as disabled (disabled bit). Adding extra enable call to make them alive once they finish setup. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1449133606-14429-6-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-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)