perf evlist: Introduce perf_evlist__parse_sample
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Aug 2012 14:42:57 +0000 (11:42 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Aug 2012 14:42:57 +0000 (11:42 -0300)
That is a more compact form of perf_session__parse_sample and to support
multiple evlists per perf_session is the way to go anyway.

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-vkxx3j5qktoj11bvcwmfjj13@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-test.c
tools/perf/builtin-top.c
tools/perf/util/evlist.c
tools/perf/util/evlist.h
tools/perf/util/python.c
tools/perf/util/session.c
tools/perf/util/session.h

index e5032ed2f2596d4830bf80f0bdb045f1af9c441a..1d592f5cbea9776fcc437e012dc20c1911fd7137 100644 (file)
@@ -562,9 +562,7 @@ static int test__basic_mmap(void)
                        goto out_munmap;
                }
 
-               err = perf_event__parse_sample(event, attr.sample_type,
-                                              evsels[0]->sample_size,
-                                              false, &sample, false);
+               err = perf_evlist__parse_sample(evlist, event, &sample, false);
                if (err) {
                        pr_err("Can't parse sample, err = %d\n", err);
                        goto out_munmap;
@@ -781,9 +779,7 @@ static int test__PERF_RECORD(void)
                                if (type < PERF_RECORD_MAX)
                                        nr_events[type]++;
 
-                               err = perf_event__parse_sample(event, evsel->attr.sample_type,
-                                                              evsel->sample_size, true,
-                                                              &sample, false);
+                               err = perf_evlist__parse_sample(evlist, event, &sample, false);
                                if (err < 0) {
                                        if (verbose)
                                                perf_event__fprintf(event, stderr);
index 520e4256fc66afec0d11502b8c869c233ef22366..40264eaa9f0f3a831b34eb21883b747bb2b1bb66 100644 (file)
@@ -811,7 +811,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
        int ret;
 
        while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) {
-               ret = perf_session__parse_sample(session, event, &sample);
+               ret = perf_evlist__parse_sample(top->evlist, event, &sample, false);
                if (ret) {
                        pr_err("Can't parse sample, err = %d\n", ret);
                        continue;
index 3edfd3483816dfa88ac49dc966d0c2a4db2b5923..1a560e0904a5a4eb299a9d909e88dbaa969cbff2 100644 (file)
@@ -881,3 +881,12 @@ int perf_evlist__start_workload(struct perf_evlist *evlist)
 
        return 0;
 }
+
+int perf_evlist__parse_sample(struct perf_evlist *evlist,
+                             const union perf_event *event,
+                             struct perf_sample *sample, bool swapped)
+{
+       struct perf_evsel *e = list_entry(evlist->entries.next, struct perf_evsel, node);
+       return perf_event__parse_sample(event, e->attr.sample_type, e->sample_size,
+                                       e->attr.sample_id_all, sample, swapped);
+}
index 40d4d3cdced0e081ec41863abe6ab46c562a3e3a..a5a49118a91a8e272f2c5ec7eabd73da63a2fa7b 100644 (file)
@@ -122,6 +122,10 @@ u64 perf_evlist__sample_type(const struct perf_evlist *evlist);
 bool perf_evlist__sample_id_all(const const struct perf_evlist *evlist);
 u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
 
+int perf_evlist__parse_sample(struct perf_evlist *evlist,
+                             const union perf_event *event,
+                             struct perf_sample *sample, bool swapped);
+
 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
 
index b0d6f85e30f152212adc4ea4cf406eec580d3c3d..0688bfb6d280a3b8ae3b8c0e3a474f51b9a404c2 100644 (file)
@@ -797,17 +797,13 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
 
        event = perf_evlist__mmap_read(evlist, cpu);
        if (event != NULL) {
-               struct perf_evsel *first;
                PyObject *pyevent = pyrf_event__new(event);
                struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
 
                if (pyevent == NULL)
                        return PyErr_NoMemory();
 
-               first = list_entry(evlist->entries.next, struct perf_evsel, node);
-               err = perf_event__parse_sample(event, first->attr.sample_type,
-                                              first->sample_size,
-                                              sample_id_all, &pevent->sample, false);
+               err = perf_evlist__parse_sample(evlist, event, &pevent->sample, false);
                if (err)
                        return PyErr_Format(PyExc_OSError,
                                            "perf: can't parse sample, err=%d", err);
index 5b8601df2392db35b34ea31ffb521659c3d9f5bc..7d07324db41cb2e5b539eedb1bde861db09282bf 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, first->attr.sample_type,
-                                       first->sample_size,
-                                       first->attr.sample_id_all, sample,
-                                       session->header.needs_swap);
-}
-
 int perf_session__synthesize_sample(struct perf_session *session,
                                    union perf_event *event,
                                    const struct perf_sample *sample)
@@ -692,7 +679,8 @@ static void flush_sample_queue(struct perf_session *s,
                if (iter->timestamp > limit)
                        break;
 
-               ret = perf_session__parse_sample(s, iter->event, &sample);
+               ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample,
+                                               s->header.needs_swap);
                if (ret)
                        pr_err("Can't parse sample, err = %d\n", ret);
                else
@@ -1103,7 +1091,8 @@ static int perf_session__process_event(struct perf_session *session,
        /*
         * For all kernel events we get the sample data
         */
-       ret = perf_session__parse_sample(session, event, &sample);
+       ret = perf_evlist__parse_sample(session->evlist, event, &sample,
+                                       session->header.needs_swap);
        if (ret)
                return ret;
 
index e2a1a4b7b236271484cc66e098144852374c0b56..7389fb1f010a2c36482e9d289df21bc8c948d0db 100644 (file)
@@ -126,10 +126,6 @@ size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
 
 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
 
-int perf_session__parse_sample(struct perf_session *session,
-                              const union perf_event *event,
-                              struct perf_sample *sample);
-
 int perf_session__synthesize_sample(struct perf_session *session,
                                    union perf_event *event,
                                    const struct perf_sample *sample);