perf evsel: Precalculate the sample size
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 1 Aug 2012 21:53:11 +0000 (18:53 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 1 Aug 2012 21:53:11 +0000 (18:53 -0300)
So that we don't have to store it in the perf_session instance, because
in the future perf_session instances may have multiple evlists, each
with different sample_type/sizes.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ptod86fxkpgq3h62m9refkv4@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-test.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/python.c
tools/perf/util/session.c
tools/perf/util/session.h

index d909eb74a0eb74bc46ec8a9e6cb9d8acca5da7f2..2ea5fe4cc940b6009798b2d4fa6ec6bd05a0ea51 100644 (file)
@@ -478,7 +478,6 @@ static int test__basic_mmap(void)
        unsigned int nr_events[nsyscalls],
                     expected_nr_events[nsyscalls], i, j;
        struct perf_evsel *evsels[nsyscalls], *evsel;
-       int sample_size = __perf_evsel__sample_size(attr.sample_type);
 
        for (i = 0; i < nsyscalls; ++i) {
                char name[64];
@@ -563,7 +562,8 @@ static int test__basic_mmap(void)
                        goto out_munmap;
                }
 
-               err = perf_event__parse_sample(event, attr.sample_type, sample_size,
+               err = perf_event__parse_sample(event, attr.sample_type,
+                                              evsels[0]->sample_size,
                                               false, &sample, false);
                if (err) {
                        pr_err("Can't parse sample, err = %d\n", err);
@@ -666,7 +666,7 @@ static int test__PERF_RECORD(void)
             found_libc_mmap = false,
             found_vdso_mmap = false,
             found_ld_mmap = false;
-       int err = -1, errs = 0, i, wakeups = 0, sample_size;
+       int err = -1, errs = 0, i, wakeups = 0;
        u32 cpu;
        int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };
 
@@ -761,7 +761,6 @@ static int test__PERF_RECORD(void)
         * event.
         */
        sample_type = perf_evlist__sample_type(evlist);
-       sample_size = __perf_evsel__sample_size(sample_type);
 
        /*
         * Now that all is properly set up, enable the events, they will
@@ -789,7 +788,7 @@ static int test__PERF_RECORD(void)
                                        nr_events[type]++;
 
                                err = perf_event__parse_sample(event, sample_type,
-                                                              sample_size, true,
+                                                              evsel->sample_size, true,
                                                               &sample, false);
                                if (err < 0) {
                                        if (verbose)
index e81771364867bd2b5d7bf52e38e9ae0984316a0a..8feec4011356693c4c4a37cd85e33475b56439ab 100644 (file)
@@ -20,7 +20,7 @@
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))
 
-int __perf_evsel__sample_size(u64 sample_type)
+static int __perf_evsel__sample_size(u64 sample_type)
 {
        u64 mask = sample_type & PERF_SAMPLE_MASK;
        int size = 0;
@@ -53,6 +53,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
        evsel->attr        = *attr;
        INIT_LIST_HEAD(&evsel->node);
        hists__init(&evsel->hists);
+       evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
 }
 
 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
index 67cc5033d19234e28071523f51ecf7c7186822b1..894bd77d90ccf466c13c40b56e6853e868529036 100644 (file)
@@ -65,6 +65,7 @@ struct perf_evsel {
                void            *func;
                void            *data;
        } handler;
+       unsigned int            sample_size;
        bool                    supported;
 };
 
@@ -177,13 +178,6 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
        return __perf_evsel__read(evsel, ncpus, nthreads, true);
 }
 
-int __perf_evsel__sample_size(u64 sample_type);
-
-static inline int perf_evsel__sample_size(struct perf_evsel *evsel)
-{
-       return __perf_evsel__sample_size(evsel->attr.sample_type);
-}
-
 void hists__init(struct hists *hists);
 
 #endif /* __PERF_EVSEL_H */
index e03b58a4842431d51edaf68ec6da95cec6caadf5..b0d6f85e30f152212adc4ea4cf406eec580d3c3d 100644 (file)
@@ -806,7 +806,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
 
                first = list_entry(evlist->entries.next, struct perf_evsel, node);
                err = perf_event__parse_sample(event, first->attr.sample_type,
-                                              perf_evsel__sample_size(first),
+                                              first->sample_size,
                                               sample_id_all, &pevent->sample, false);
                if (err)
                        return PyErr_Format(PyExc_OSError,
index 8e4f0755d2aa8364d81fa714888d622d61f6a2db..b8da60d1ecb5d349a8b39f5ab3df81c0306f55d3 100644 (file)
 #include "cpumap.h"
 #include "event-parse.h"
 
+int perf_session__parse_sample(struct perf_session *session,
+                              const union perf_event *event,
+                              struct perf_sample *sample)
+{
+       struct perf_evsel *first;
+       first = list_entry(session->evlist->entries.next, struct perf_evsel, node);
+
+       return perf_event__parse_sample(event, session->sample_type,
+                                       first->sample_size,
+                                       session->sample_id_all, sample,
+                                       session->header.needs_swap);
+}
+
 static int perf_session__open(struct perf_session *self, bool force)
 {
        struct stat input_stat;
@@ -83,7 +96,6 @@ out_close:
 void perf_session__update_sample_type(struct perf_session *self)
 {
        self->sample_type = perf_evlist__sample_type(self->evlist);
-       self->sample_size = __perf_evsel__sample_size(self->sample_type);
        self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
        self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist);
        self->host_machine.id_hdr_size = self->id_hdr_size;
index 7c435bde6eb0ea1f913e1dadfca3da0c23432302..4d549e28248f314fc99a277effe44190c5987662 100644 (file)
@@ -42,7 +42,6 @@ struct perf_session {
         */
        struct hists            hists;
        u64                     sample_type;
-       int                     sample_size;
        int                     fd;
        bool                    fd_pipe;
        bool                    repipe;
@@ -130,15 +129,9 @@ size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
 
 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
 
-static inline int perf_session__parse_sample(struct perf_session *session,
-                                            const union perf_event *event,
-                                            struct perf_sample *sample)
-{
-       return perf_event__parse_sample(event, session->sample_type,
-                                       session->sample_size,
-                                       session->sample_id_all, sample,
-                                       session->header.needs_swap);
-}
+int perf_session__parse_sample(struct perf_session *session,
+                              const union perf_event *event,
+                              struct perf_sample *sample);
 
 static inline int perf_session__synthesize_sample(struct perf_session *session,
                                                  union perf_event *event,