perf tools: Move event__parse_sample to evsel.c
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 21 Jan 2011 15:46:41 +0000 (13:46 -0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 24 Jan 2011 15:17:56 +0000 (13:17 -0200)
To avoid linking more stuff in the python binding I'm working on, future
csets will make the sample type be taken from the evsel itself, but for
that we need to first have one file per cpu and per sample_type, not a
single perf.data file.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-test.c
tools/perf/builtin-top.c
tools/perf/util/event.c
tools/perf/util/event.h
tools/perf/util/evsel.c
tools/perf/util/session.c
tools/perf/util/session.h

index dc91ee06a37ccf19cf65f519a928bfaae4b969b7..231e3e21810cf16f1721732eef3512e10722e49b 100644 (file)
@@ -10,7 +10,6 @@
 #include "util/evlist.h"
 #include "util/parse-options.h"
 #include "util/parse-events.h"
-#include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread_map.h"
 
@@ -457,7 +456,6 @@ static int test__basic_mmap(void)
        int err = -1;
        event_t *event;
        struct thread_map *threads;
-       struct perf_session session;
        struct cpu_map *cpus;
        struct perf_evlist *evlist;
        struct perf_event_attr attr = {
@@ -521,13 +519,6 @@ static int test__basic_mmap(void)
        attr.wakeup_events = 1;
        attr.sample_period = 1;
 
-       /*
-        * FIXME: use evsel->attr.sample_type in event__parse_sample.
-        *        This will nicely remove the requirement that we have
-        *        all the events with the same sample_type.
-        */
-       session.sample_type = attr.sample_type;
-
        for (i = 0; i < nsyscalls; ++i) {
                attr.config = ids[i];
                evsels[i] = perf_evsel__new(&attr, i);
@@ -567,7 +558,7 @@ static int test__basic_mmap(void)
                        goto out_munmap;
                }
 
-               event__parse_sample(event, &session, &sample);
+               event__parse_sample(event, attr.sample_type, false, &sample);
                evsel = perf_evlist__id2evsel(evlist, sample.id);
                if (evsel == NULL) {
                        pr_debug("event with id %" PRIu64
index d0b16d9054051596cb257d474b85b23e29d9ea25..ce2e50c891c76dd674e881c379fbe1d0a1186953 100644 (file)
@@ -1106,7 +1106,7 @@ static void perf_session__mmap_read_cpu(struct perf_session *self, int cpu)
        event_t *event;
 
        while ((event = perf_evlist__read_on_cpu(evsel_list, cpu)) != NULL) {
-               event__parse_sample(event, self, &sample);
+               perf_session__parse_sample(self, event, &sample);
 
                if (event->header.type == PERF_RECORD_SAMPLE)
                        event__process_sample(event, &sample, self);
index 1478ab4ee2221e8dc5d44cd6677bf56e0d79205d..e4db8b88854694deb47d5fa53bac0f1f01a2d4f4 100644 (file)
@@ -826,128 +826,3 @@ out_filtered:
        al->filtered = true;
        return 0;
 }
-
-static int event__parse_id_sample(const event_t *event,
-                                 struct perf_session *session,
-                                 struct sample_data *sample)
-{
-       const u64 *array;
-       u64 type;
-
-       sample->cpu = sample->pid = sample->tid = -1;
-       sample->stream_id = sample->id = sample->time = -1ULL;
-
-       if (!session->sample_id_all)
-               return 0;
-
-       array = event->sample.array;
-       array += ((event->header.size -
-                  sizeof(event->header)) / sizeof(u64)) - 1;
-       type = session->sample_type;
-
-       if (type & PERF_SAMPLE_CPU) {
-               u32 *p = (u32 *)array;
-               sample->cpu = *p;
-               array--;
-       }
-
-       if (type & PERF_SAMPLE_STREAM_ID) {
-               sample->stream_id = *array;
-               array--;
-       }
-
-       if (type & PERF_SAMPLE_ID) {
-               sample->id = *array;
-               array--;
-       }
-
-       if (type & PERF_SAMPLE_TIME) {
-               sample->time = *array;
-               array--;
-       }
-
-       if (type & PERF_SAMPLE_TID) {
-               u32 *p = (u32 *)array;
-               sample->pid = p[0];
-               sample->tid = p[1];
-       }
-
-       return 0;
-}
-
-int event__parse_sample(const event_t *event, struct perf_session *session,
-                       struct sample_data *data)
-{
-       const u64 *array;
-       u64 type;
-
-       if (event->header.type != PERF_RECORD_SAMPLE)
-               return event__parse_id_sample(event, session, data);
-
-       array = event->sample.array;
-       type = session->sample_type;
-
-       if (type & PERF_SAMPLE_IP) {
-               data->ip = event->ip.ip;
-               array++;
-       }
-
-       if (type & PERF_SAMPLE_TID) {
-               u32 *p = (u32 *)array;
-               data->pid = p[0];
-               data->tid = p[1];
-               array++;
-       }
-
-       if (type & PERF_SAMPLE_TIME) {
-               data->time = *array;
-               array++;
-       }
-
-       if (type & PERF_SAMPLE_ADDR) {
-               data->addr = *array;
-               array++;
-       }
-
-       data->id = -1ULL;
-       if (type & PERF_SAMPLE_ID) {
-               data->id = *array;
-               array++;
-       }
-
-       if (type & PERF_SAMPLE_STREAM_ID) {
-               data->stream_id = *array;
-               array++;
-       }
-
-       if (type & PERF_SAMPLE_CPU) {
-               u32 *p = (u32 *)array;
-               data->cpu = *p;
-               array++;
-       } else
-               data->cpu = -1;
-
-       if (type & PERF_SAMPLE_PERIOD) {
-               data->period = *array;
-               array++;
-       }
-
-       if (type & PERF_SAMPLE_READ) {
-               pr_debug("PERF_SAMPLE_READ is unsuported for now\n");
-               return -1;
-       }
-
-       if (type & PERF_SAMPLE_CALLCHAIN) {
-               data->callchain = (struct ip_callchain *)array;
-               array += 1 + data->callchain->nr;
-       }
-
-       if (type & PERF_SAMPLE_RAW) {
-               u32 *p = (u32 *)array;
-               data->raw_size = *p;
-               p++;
-               data->raw_data = p;
-       }
-
-       return 0;
-}
index 2b7e91902f105d5962a68254737ce21cfeef935c..d79e4edd82f96503b3b78f816d5983dd15ff291e 100644 (file)
@@ -169,9 +169,10 @@ struct addr_location;
 int event__preprocess_sample(const event_t *self, struct perf_session *session,
                             struct addr_location *al, struct sample_data *data,
                             symbol_filter_t filter);
-int event__parse_sample(const event_t *event, struct perf_session *session,
-                       struct sample_data *sample);
 
 const char *event__get_event_name(unsigned int id);
 
+int event__parse_sample(const event_t *event, u64 type, bool sample_id_all,
+                       struct sample_data *sample);
+
 #endif /* __PERF_RECORD_H */
index 9a6d94299ab8cfb0d534d2ed830caa3b69fb7727..a85ae12845eac68dd14f9ee8b4435311092637e4 100644 (file)
@@ -355,3 +355,121 @@ out_unmap:
        }
        return -1;
 }
+
+static int event__parse_id_sample(const event_t *event, u64 type,
+                                 struct sample_data *sample)
+{
+       const u64 *array = event->sample.array;
+
+       array += ((event->header.size -
+                  sizeof(event->header)) / sizeof(u64)) - 1;
+
+       if (type & PERF_SAMPLE_CPU) {
+               u32 *p = (u32 *)array;
+               sample->cpu = *p;
+               array--;
+       }
+
+       if (type & PERF_SAMPLE_STREAM_ID) {
+               sample->stream_id = *array;
+               array--;
+       }
+
+       if (type & PERF_SAMPLE_ID) {
+               sample->id = *array;
+               array--;
+       }
+
+       if (type & PERF_SAMPLE_TIME) {
+               sample->time = *array;
+               array--;
+       }
+
+       if (type & PERF_SAMPLE_TID) {
+               u32 *p = (u32 *)array;
+               sample->pid = p[0];
+               sample->tid = p[1];
+       }
+
+       return 0;
+}
+
+int event__parse_sample(const event_t *event, u64 type, bool sample_id_all,
+                       struct sample_data *data)
+{
+       const u64 *array;
+
+       data->cpu = data->pid = data->tid = -1;
+       data->stream_id = data->id = data->time = -1ULL;
+
+       if (event->header.type != PERF_RECORD_SAMPLE) {
+               if (!sample_id_all)
+                       return 0;
+               return event__parse_id_sample(event, type, data);
+       }
+
+       array = event->sample.array;
+
+       if (type & PERF_SAMPLE_IP) {
+               data->ip = event->ip.ip;
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_TID) {
+               u32 *p = (u32 *)array;
+               data->pid = p[0];
+               data->tid = p[1];
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_TIME) {
+               data->time = *array;
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_ADDR) {
+               data->addr = *array;
+               array++;
+       }
+
+       data->id = -1ULL;
+       if (type & PERF_SAMPLE_ID) {
+               data->id = *array;
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_STREAM_ID) {
+               data->stream_id = *array;
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_CPU) {
+               u32 *p = (u32 *)array;
+               data->cpu = *p;
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_PERIOD) {
+               data->period = *array;
+               array++;
+       }
+
+       if (type & PERF_SAMPLE_READ) {
+               fprintf(stderr, "PERF_SAMPLE_READ is unsuported for now\n");
+               return -1;
+       }
+
+       if (type & PERF_SAMPLE_CALLCHAIN) {
+               data->callchain = (struct ip_callchain *)array;
+               array += 1 + data->callchain->nr;
+       }
+
+       if (type & PERF_SAMPLE_RAW) {
+               u32 *p = (u32 *)array;
+               data->raw_size = *p;
+               p++;
+               data->raw_data = p;
+       }
+
+       return 0;
+}
index b58a48a5e5a9a7a29fea122fd2f4ca560acbd045..e6a07408669ec27cba012bbf99b17f6bb50125cc 100644 (file)
@@ -496,7 +496,7 @@ static void flush_sample_queue(struct perf_session *s,
                if (iter->timestamp > limit)
                        break;
 
-               event__parse_sample(iter->event, s, &sample);
+               perf_session__parse_sample(s, iter->event, &sample);
                perf_session_deliver_event(s, iter->event, &sample, ops,
                                           iter->file_offset);
 
@@ -806,7 +806,7 @@ static int perf_session__process_event(struct perf_session *session,
        /*
         * For all kernel events we get the sample data
         */
-       event__parse_sample(event, session, &sample);
+       perf_session__parse_sample(session, event, &sample);
 
        /* Preprocess sample records - precheck callchains */
        if (perf_session__preprocess_sample(session, event, &sample))
index e815468eb88862ba8d954c919bcd5d3932f0bbe4..78239767011e1b2d58255cb4e451d86d0d81a007 100644 (file)
@@ -155,4 +155,13 @@ size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp)
 {
        return hists__fprintf_nr_events(&self->hists, fp);
 }
+
+static inline int perf_session__parse_sample(struct perf_session *session,
+                                            const event_t *event,
+                                            struct sample_data *sample)
+{
+       return event__parse_sample(event, session->sample_type,
+                                  session->sample_id_all, sample);
+}
+
 #endif /* __PERF_SESSION_H */