perf python: Fix pyrf_evlist__read_on_cpu event consuming
[cascardo/linux.git] / tools / perf / util / python.c
index 98f127a..c68ef03 100644 (file)
@@ -653,6 +653,7 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel,
        attr.precise_ip     = precise_ip;
        attr.mmap_data      = mmap_data;
        attr.sample_id_all  = sample_id_all;
+       attr.size           = sizeof(attr);
 
        perf_evsel__init(&pevsel->evsel, &attr, idx);
        return 0;
@@ -864,12 +865,14 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
                PyObject *pyevent = pyrf_event__new(event);
                struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
 
-               perf_evlist__mmap_consume(evlist, cpu);
-
                if (pyevent == NULL)
                        return PyErr_NoMemory();
 
                err = perf_evlist__parse_sample(evlist, event, &pevent->sample);
+
+               /* Consume the even only after we parsed it out. */
+               perf_evlist__mmap_consume(evlist, cpu);
+
                if (err)
                        return PyErr_Format(PyExc_OSError,
                                            "perf: can't parse sample, err=%d", err);
@@ -957,7 +960,7 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i)
        if (i >= pevlist->evlist.nr_entries)
                return NULL;
 
-       evlist__for_each(&pevlist->evlist, pos) {
+       evlist__for_each_entry(&pevlist->evlist, pos) {
                if (i-- == 0)
                        break;
        }