Instead of passing it around for parsing as an explicit parameter, will help with reading tracepoint fields when not using a perf session or pevent structure, i.e. for non perf.data centered workflows.
Unified · Split
| @@ -564,7 +564,7 @@ static int test__basic_mmap(void) · 563 unmodified lines | ||
| 564 | 564 | goto out_munmap; |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | − err = perf_evlist__parse_sample(evlist, event, &sample, false); | |
| 567 | + err = perf_evlist__parse_sample(evlist, event, &sample); | |
| 568 | 568 | if (err) { |
| 569 | 569 | pr_err("Can't parse sample, err = %d\n", err); |
| 570 | 570 | goto out_munmap; |
| @@ -781,7 +781,7 @@ static int test__PERF_RECORD(void) · 210 unmodified lines | ||
| 781 | 781 | if (type < PERF_RECORD_MAX) |
| 782 | 782 | nr_events[type]++; |
| 783 | 783 | |
| 784 | − err = perf_evlist__parse_sample(evlist, event, &sample, false); | |
| 784 | + err = perf_evlist__parse_sample(evlist, event, &sample); | |
| 785 | 785 | if (err < 0) { |
| 786 | 786 | if (verbose) |
| 787 | 787 | perf_event__fprintf(event, stderr); |
| @@ -823,7 +823,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) · 822 unmodified lines | ||
| 823 | 823 | int ret; |
| 824 | 824 | |
| 825 | 825 | while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { |
| 826 | − ret = perf_evlist__parse_sample(top->evlist, event, &sample, false); | |
| 826 | + ret = perf_evlist__parse_sample(top->evlist, event, &sample); | |
| 827 | 827 | if (ret) { |
| 828 | 828 | pr_err("Can't parse sample, err = %d\n", ret); |
| 829 | 829 | continue; |
| @@ -884,10 +884,10 @@ int perf_evlist__start_workload(struct perf_evlist *evlist) · 883 unmodified lines | ||
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, |
| 887 | − struct perf_sample *sample, bool swapped) | |
| 887 | + struct perf_sample *sample) | |
| 888 | 888 | { |
| 889 | 889 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
| 890 | − return perf_evsel__parse_sample(evsel, event, sample, swapped); | |
| 890 | + return perf_evsel__parse_sample(evsel, event, sample); | |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp) |
| @@ -125,7 +125,7 @@ bool perf_evlist__sample_id_all(struct perf_evlist *evlist); · 124 unmodified lines | ||
| 125 | 125 | u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist); |
| 126 | 126 | |
| 127 | 127 | int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, |
| 128 | − struct perf_sample *sample, bool swapped); | |
| 128 | + struct perf_sample *sample); | |
| 129 | 129 | |
| 130 | 130 | bool perf_evlist__valid_sample_type(struct perf_evlist *evlist); |
| 131 | 131 | bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist); |
| @@ -767,11 +767,13 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel, · 766 unmodified lines | ||
| 767 | 767 | return __perf_evsel__open(evsel, &empty_cpu_map.map, threads); |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | −static int perf_event__parse_id_sample(const union perf_event *event, u64 type, | |
| 771 | − struct perf_sample *sample, | |
| 772 | − bool swapped) | |
| 770 | +static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel, | |
| 771 | + const union perf_event *event, | |
| 772 | + struct perf_sample *sample) | |
| 773 | 773 | { |
| 774 | + u64 type = evsel->attr.sample_type; | |
| 774 | 775 | const u64 *array = event->sample.array; |
| 776 | + bool swapped = evsel->needs_swap; | |
| 775 | 777 | union u64_swap u; |
| 776 | 778 | |
| 777 | 779 | array += ((event->header.size - |
| @@ -832,10 +834,11 @@ static bool sample_overlap(const union perf_event *event, · 54 unmodified lines | ||
| 832 | 834 | } |
| 833 | 835 | |
| 834 | 836 | int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, |
| 835 | − struct perf_sample *data, bool swapped) | |
| 837 | + struct perf_sample *data) | |
| 836 | 838 | { |
| 837 | 839 | u64 type = evsel->attr.sample_type; |
| 838 | 840 | u64 regs_user = evsel->attr.sample_regs_user; |
| 841 | + bool swapped = evsel->needs_swap; | |
| 839 | 842 | const u64 *array; |
| 840 | 843 | |
| 841 | 844 | /* |
| @@ -852,7 +855,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, · 10 unmodified lines | ||
| 852 | 855 | if (event->header.type != PERF_RECORD_SAMPLE) { |
| 853 | 856 | if (!evsel->attr.sample_id_all) |
| 854 | 857 | return 0; |
| 855 | − return perf_event__parse_id_sample(event, type, data, swapped); | |
| 858 | + return perf_evsel__parse_id_sample(evsel, event, data); | |
| 856 | 859 | } |
| 857 | 860 | |
| 858 | 861 | array = event->sample.array; |
| @@ -69,6 +69,7 @@ struct perf_evsel { · 68 unmodified lines | ||
| 69 | 69 | struct cpu_map *cpus; |
| 70 | 70 | unsigned int sample_size; |
| 71 | 71 | bool supported; |
| 72 | + bool needs_swap; | |
| 72 | 73 | /* parse modifier helper */ |
| 73 | 74 | int exclude_GH; |
| 74 | 75 | struct perf_evsel *leader; |
| @@ -205,7 +206,7 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel, · 130 unmodified lines | ||
| 205 | 206 | void hists__init(struct hists *hists); |
| 206 | 207 | |
| 207 | 208 | int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, |
| 208 | − struct perf_sample *sample, bool swapped); | |
| 209 | + struct perf_sample *sample); | |
| 209 | 210 | |
| 210 | 211 | static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel) |
| 211 | 212 | { |
| @@ -1256,8 +1256,10 @@ read_event_desc(struct perf_header *ph, int fd) · 1255 unmodified lines | ||
| 1256 | 1256 | if (ret != (ssize_t)sizeof(nr)) |
| 1257 | 1257 | goto error; |
| 1258 | 1258 | |
| 1259 | − if (ph->needs_swap) | |
| 1259 | + if (ph->needs_swap) { | |
| 1260 | 1260 | nr = bswap_32(nr); |
| 1261 | + evsel->needs_swap = true; | |
| 1262 | + } | |
| 1261 | 1263 | |
| 1262 | 1264 | evsel->name = do_read_string(fd, ph); |
| 1263 | 1265 | |
| @@ -2626,6 +2628,8 @@ int perf_session__read_header(struct perf_session *session, int fd) · 1362 unmodified lines | ||
| 2626 | 2628 | |
| 2627 | 2629 | if (evsel == NULL) |
| 2628 | 2630 | goto out_delete_evlist; |
| 2631 | + | |
| 2632 | + evsel->needs_swap = header->needs_swap; | |
| 2629 | 2633 | /* |
| 2630 | 2634 | * Do it before so that if perf_evsel__alloc_id fails, this |
| 2631 | 2635 | * entry gets purged too at perf_evlist__delete(). |
| @@ -805,7 +805,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, · 804 unmodified lines | ||
| 805 | 805 | if (pyevent == NULL) |
| 806 | 806 | return PyErr_NoMemory(); |
| 807 | 807 | |
| 808 | − err = perf_evlist__parse_sample(evlist, event, &pevent->sample, false); | |
| 808 | + err = perf_evlist__parse_sample(evlist, event, &pevent->sample); | |
| 809 | 809 | if (err) |
| 810 | 810 | return PyErr_Format(PyExc_OSError, |
| 811 | 811 | "perf: can't parse sample, err=%d", err); |
| @@ -722,8 +722,7 @@ static int flush_sample_queue(struct perf_session *s, · 721 unmodified lines | ||
| 722 | 722 | if (iter->timestamp > limit) |
| 723 | 723 | break; |
| 724 | 724 | |
| 725 | − ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample, | |
| 726 | − s->header.needs_swap); | |
| 725 | + ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample); | |
| 727 | 726 | if (ret) |
| 728 | 727 | pr_err("Can't parse sample, err = %d\n", ret); |
| 729 | 728 | else { |
| @@ -1174,8 +1173,7 @@ static int perf_session__process_event(struct perf_session *session, · 444 unmodified lines | ||
| 1174 | 1173 | /* |
| 1175 | 1174 | * For all kernel events we get the sample data |
| 1176 | 1175 | */ |
| 1177 | − ret = perf_evlist__parse_sample(session->evlist, event, &sample, | |
| 1178 | − session->header.needs_swap); | |
| 1176 | + ret = perf_evlist__parse_sample(session->evlist, event, &sample); | |
| 1179 | 1177 | if (ret) |
| 1180 | 1178 | return ret; |
| 1181 | 1179 | |