#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"
 
        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 = {
        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);
                        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
 
        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);
 
        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;
-}
 
 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 */
 
        }
        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;
+}
 
                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);
 
        /*
         * 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))
 
 {
        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 */