perf tools: Fix attributes for '{}' defined event groups
authorJiri Olsa <jolsa@redhat.com>
Mon, 12 Nov 2012 17:34:00 +0000 (18:34 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Nov 2012 19:51:50 +0000 (16:51 -0300)
Fixing events attributes for groups defined via '{}'.

Currently 'enable_on_exec' attribute in record command and both
'disabled ' and 'enable_on_exec' attributes in stat command are set
based on the 'group' option. This eliminates proper setup for '{}'
defined groups as they don't set 'group' option.

Making above attributes values based on the 'evsel->leader' as this is
common to both group definition.

Moving perf_evlist__set_leader call within builtin-record ahead
perf_evlist__config_attrs call, because the latter needs possible group
leader links in place.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1352741644-16809-2-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-record.c
tools/perf/builtin-stat.c
tools/perf/tests/attr/test-record-group1
tools/perf/tests/attr/test-stat-group1
tools/perf/tests/open-syscall-tp-fields.c
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 5783c3225116aa3e3ff828efb695996ab343e1f4..371702785d6813235277efce039b625ac8ec9c56 100644 (file)
@@ -230,11 +230,15 @@ static int perf_record__open(struct perf_record *rec)
        struct perf_record_opts *opts = &rec->opts;
        int rc = 0;
 
-       perf_evlist__config_attrs(evlist, opts);
-
+       /*
+        * Set the evsel leader links before we configure attributes,
+        * since some might depend on this info.
+        */
        if (opts->group)
                perf_evlist__set_leader(evlist);
 
+       perf_evlist__config_attrs(evlist, opts);
+
        list_for_each_entry(pos, &evlist->entries, node) {
                struct perf_event_attr *attr = &pos->attr;
                /*
index 6888960ef8b81183d8d6cf36649b578b47c3dd4f..557081e0c6d9480ed9340b5bf7d270961f03614d 100644 (file)
@@ -129,8 +129,7 @@ static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];
 static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS];
 static struct stats walltime_nsecs_stats;
 
-static int create_perf_stat_counter(struct perf_evsel *evsel,
-                                   struct perf_evsel *first)
+static int create_perf_stat_counter(struct perf_evsel *evsel)
 {
        struct perf_event_attr *attr = &evsel->attr;
        bool exclude_guest_missing = false;
@@ -153,7 +152,7 @@ retry:
                return 0;
        }
 
-       if (!perf_target__has_task(&target) && (!group || evsel == first)) {
+       if (!perf_target__has_task(&target) && (!evsel->leader)) {
                attr->disabled = 1;
                attr->enable_on_exec = 1;
        }
@@ -272,7 +271,7 @@ static int read_counter(struct perf_evsel *counter)
 static int __run_perf_stat(int argc __maybe_unused, const char **argv)
 {
        unsigned long long t0, t1;
-       struct perf_evsel *counter, *first;
+       struct perf_evsel *counter;
        int status = 0;
        int child_ready_pipe[2], go_pipe[2];
        const bool forks = (argc > 0);
@@ -332,10 +331,8 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)
        if (group)
                perf_evlist__set_leader(evsel_list);
 
-       first = perf_evlist__first(evsel_list);
-
        list_for_each_entry(counter, &evsel_list->entries, node) {
-               if (create_perf_stat_counter(counter, first) < 0) {
+               if (create_perf_stat_counter(counter) < 0) {
                        /*
                         * PPC returns ENXIO for HW counters until 2.6.37
                         * (behavior changed with commit b0a873e).
index 39bf8609538ca0026d8a57d03973000529a70599..013572f2360506e34ef5364e5d783b10c2275602 100644 (file)
@@ -15,6 +15,4 @@ config=1
 sample_type=327
 mmap=0
 comm=0
-# TODO this is disabled for --group option, enabled otherwise
-#      check why..
-enable_on_exec=1
+enable_on_exec=0
index 5ae2718de8644a5ae23fa859bd191bcd7b41e31a..2a1f86e4a904c67f0d271fb729c7e4464efaae34 100644 (file)
@@ -11,7 +11,5 @@ group_fd=-1
 fd=2
 group_fd=1
 config=1
-# TODO both disabled and enable_on_exec are disabled for --group option,
-#      enabled otherwise, check why..
-disabled=1
-enable_on_exec=1
+disabled=0
+enable_on_exec=0
index b05b6a6f01af2c47727401f02a4aaa40c92780de..1c52fdc1164e49e0001f61cad9df75a48c5d97ce 100644 (file)
@@ -41,7 +41,7 @@ int test__syscall_open_tp_fields(void)
                goto out_delete_evlist;
        }
 
-       perf_evsel__config(evsel, &opts, evsel);
+       perf_evsel__config(evsel, &opts);
 
        evlist->threads->map[0] = getpid();
 
index a41dc4a5c2deeeefbe4794ebd9774e517c3363db..04acae0ce6976d7ca09759936f93c23f563f1758 100644 (file)
@@ -52,15 +52,13 @@ struct perf_evlist *perf_evlist__new(struct cpu_map *cpus,
 void perf_evlist__config_attrs(struct perf_evlist *evlist,
                               struct perf_record_opts *opts)
 {
-       struct perf_evsel *evsel, *first;
+       struct perf_evsel *evsel;
 
        if (evlist->cpus->map[0] < 0)
                opts->no_inherit = true;
 
-       first = perf_evlist__first(evlist);
-
        list_for_each_entry(evsel, &evlist->entries, node) {
-               perf_evsel__config(evsel, opts, first);
+               perf_evsel__config(evsel, opts);
 
                if (evlist->nr_entries > 1)
                        evsel->attr.sample_type |= PERF_SAMPLE_ID;
index 618d41140abd368072d9c978f70969233cd70260..6d4a5f6ed75a7c07c0cdcad6e10374e58fa70156 100644 (file)
@@ -404,8 +404,8 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
        return evsel->name ?: "unknown";
 }
 
-void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts,
-                       struct perf_evsel *first)
+void perf_evsel__config(struct perf_evsel *evsel,
+                       struct perf_record_opts *opts)
 {
        struct perf_event_attr *attr = &evsel->attr;
        int track = !evsel->idx; /* only the first counter needs these */
@@ -486,10 +486,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts,
        attr->mmap = track;
        attr->comm = track;
 
-       if (perf_target__none(&opts->target) &&
-           (!opts->group || evsel == first)) {
+       if (perf_target__none(&opts->target) && (!evsel->leader))
                attr->enable_on_exec = 1;
-       }
 }
 
 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
index 6f94d6dea00f4b26efb86533509b4c9dace89737..32d7ec78dedc4db4a28c3158256c6e1d47063739 100644 (file)
@@ -92,8 +92,7 @@ void perf_evsel__exit(struct perf_evsel *evsel);
 void perf_evsel__delete(struct perf_evsel *evsel);
 
 void perf_evsel__config(struct perf_evsel *evsel,
-                       struct perf_record_opts *opts,
-                       struct perf_evsel *first);
+                       struct perf_record_opts *opts);
 
 bool perf_evsel__is_cache_op_valid(u8 type, u8 op);