perf tools: Pass whole attr to event selectors
authorLin Ming <ming.m.lin@intel.com>
Fri, 7 Jan 2011 03:11:09 +0000 (11:11 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 7 Jan 2011 03:44:36 +0000 (01:44 -0200)
Since commit 69aad6f1(perf tools: Introduce event selectors), only
perf_event_attr::type and ::config are passed to event selector, which
makes perf tool not work correctly.

For example, PEBS does not work because perf_event_attr::precise_ip is
not passed to the syscall.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1294369869.20563.19.camel@minggr.sh.intel.com>
Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c
tools/perf/builtin-test.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/parse-events.c

index 02b2d8013a61e537bf80e5d110d6c2f2c3f6b150..2dfcb613e66be4337ca4e4f1373ae0522e25c232 100644 (file)
@@ -683,8 +683,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
                nr_counters = ARRAY_SIZE(default_attrs);
 
                for (c = 0; c < ARRAY_SIZE(default_attrs); ++c) {
-                       pos = perf_evsel__new(default_attrs[c].type,
-                                             default_attrs[c].config,
+                       pos = perf_evsel__new(&default_attrs[c],
                                              nr_counters);
                        if (pos == NULL)
                                goto out;
index 1c984342a5795090d2e863d0b2da1a995e0201d2..e12753f976a1dc522d957e984e1d98b7afe1bce6 100644 (file)
@@ -264,6 +264,7 @@ static int test__open_syscall_event(void)
        int err = -1, fd;
        struct thread_map *threads;
        struct perf_evsel *evsel;
+       struct perf_event_attr attr;
        unsigned int nr_open_calls = 111, i;
        int id = trace_event__id("sys_enter_open");
 
@@ -278,7 +279,10 @@ static int test__open_syscall_event(void)
                return -1;
        }
 
-       evsel = perf_evsel__new(PERF_TYPE_TRACEPOINT, id, 0);
+       memset(&attr, 0, sizeof(attr));
+       attr.type = PERF_TYPE_TRACEPOINT;
+       attr.config = id;
+       evsel = perf_evsel__new(&attr, 0);
        if (evsel == NULL) {
                pr_debug("perf_evsel__new\n");
                goto out_thread_map_delete;
index c95267e63c5b435192fa7c61b7069c32d1f15f2a..1a5591d7a2450885444ac3e1b0b14ad55b6cb108 100644 (file)
@@ -6,14 +6,13 @@
 
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 
-struct perf_evsel *perf_evsel__new(u32 type, u64 config, int idx)
+struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
 {
        struct perf_evsel *evsel = zalloc(sizeof(*evsel));
 
        if (evsel != NULL) {
                evsel->idx         = idx;
-               evsel->attr.type   = type;
-               evsel->attr.config = config;
+               evsel->attr        = *attr;
                INIT_LIST_HEAD(&evsel->node);
        }
 
index a0ccd69c3fc283fd50f8d55a52df8b1ada2e10e3..b2d755fe88a50614da63ac4c6e674a6045ab6188 100644 (file)
@@ -37,7 +37,7 @@ struct perf_evsel {
 struct cpu_map;
 struct thread_map;
 
-struct perf_evsel *perf_evsel__new(u32 type, u64 config, int idx);
+struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
 void perf_evsel__delete(struct perf_evsel *evsel);
 
 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
index 917a0ca521c1ac936259fab309000c5d4070c4d8..5cb6f4bde9055b84c202970cd39b86ce7f144f54 100644 (file)
@@ -823,7 +823,7 @@ int parse_events(const struct option *opt __used, const char *str, int unset __u
 
                if (ret != EVT_HANDLED_ALL) {
                        struct perf_evsel *evsel;
-                       evsel = perf_evsel__new(attr.type, attr.config,
+                       evsel = perf_evsel__new(&attr,
                                                nr_counters);
                        if (evsel == NULL)
                                return -1;
@@ -1013,8 +1013,15 @@ void print_events(void)
 
 int perf_evsel_list__create_default(void)
 {
-       struct perf_evsel *evsel = perf_evsel__new(PERF_TYPE_HARDWARE,
-                                                  PERF_COUNT_HW_CPU_CYCLES, 0);
+       struct perf_evsel *evsel;
+       struct perf_event_attr attr;
+
+       memset(&attr, 0, sizeof(attr));
+       attr.type = PERF_TYPE_HARDWARE;
+       attr.config = PERF_COUNT_HW_CPU_CYCLES;
+
+       evsel = perf_evsel__new(&attr, 0);
+
        if (evsel == NULL)
                return -ENOMEM;