perf evsel: Know if byte swap is needed

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.

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-qa67ikv2sm49cwa7dyjhhp6g@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a14bb7a6
...@@ -564,7 +564,7 @@ static int test__basic_mmap(void) ...@@ -564,7 +564,7 @@ static int test__basic_mmap(void)
goto out_munmap; goto out_munmap;
} }
err = perf_evlist__parse_sample(evlist, event, &sample, false); err = perf_evlist__parse_sample(evlist, event, &sample);
if (err) { if (err) {
pr_err("Can't parse sample, err = %d\n", err); pr_err("Can't parse sample, err = %d\n", err);
goto out_munmap; goto out_munmap;
...@@ -781,7 +781,7 @@ static int test__PERF_RECORD(void) ...@@ -781,7 +781,7 @@ static int test__PERF_RECORD(void)
if (type < PERF_RECORD_MAX) if (type < PERF_RECORD_MAX)
nr_events[type]++; nr_events[type]++;
err = perf_evlist__parse_sample(evlist, event, &sample, false); err = perf_evlist__parse_sample(evlist, event, &sample);
if (err < 0) { if (err < 0) {
if (verbose) if (verbose)
perf_event__fprintf(event, stderr); perf_event__fprintf(event, stderr);
......
...@@ -823,7 +823,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) ...@@ -823,7 +823,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
int ret; int ret;
while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) {
ret = perf_evlist__parse_sample(top->evlist, event, &sample, false); ret = perf_evlist__parse_sample(top->evlist, event, &sample);
if (ret) { if (ret) {
pr_err("Can't parse sample, err = %d\n", ret); pr_err("Can't parse sample, err = %d\n", ret);
continue; continue;
......
...@@ -884,10 +884,10 @@ int perf_evlist__start_workload(struct perf_evlist *evlist) ...@@ -884,10 +884,10 @@ int perf_evlist__start_workload(struct perf_evlist *evlist)
} }
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
struct perf_sample *sample, bool swapped) struct perf_sample *sample)
{ {
struct perf_evsel *evsel = perf_evlist__first(evlist); struct perf_evsel *evsel = perf_evlist__first(evlist);
return perf_evsel__parse_sample(evsel, event, sample, swapped); return perf_evsel__parse_sample(evsel, event, sample);
} }
size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp) 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); ...@@ -125,7 +125,7 @@ bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist); u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
struct perf_sample *sample, bool swapped); struct perf_sample *sample);
bool perf_evlist__valid_sample_type(struct perf_evlist *evlist); bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist); 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, ...@@ -767,11 +767,13 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel,
return __perf_evsel__open(evsel, &empty_cpu_map.map, threads); return __perf_evsel__open(evsel, &empty_cpu_map.map, threads);
} }
static int perf_event__parse_id_sample(const union perf_event *event, u64 type, static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel,
struct perf_sample *sample, const union perf_event *event,
bool swapped) struct perf_sample *sample)
{ {
u64 type = evsel->attr.sample_type;
const u64 *array = event->sample.array; const u64 *array = event->sample.array;
bool swapped = evsel->needs_swap;
union u64_swap u; union u64_swap u;
array += ((event->header.size - array += ((event->header.size -
...@@ -832,10 +834,11 @@ static bool sample_overlap(const union perf_event *event, ...@@ -832,10 +834,11 @@ static bool sample_overlap(const union perf_event *event,
} }
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *data, bool swapped) struct perf_sample *data)
{ {
u64 type = evsel->attr.sample_type; u64 type = evsel->attr.sample_type;
u64 regs_user = evsel->attr.sample_regs_user; u64 regs_user = evsel->attr.sample_regs_user;
bool swapped = evsel->needs_swap;
const u64 *array; const u64 *array;
/* /*
...@@ -852,7 +855,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, ...@@ -852,7 +855,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
if (event->header.type != PERF_RECORD_SAMPLE) { if (event->header.type != PERF_RECORD_SAMPLE) {
if (!evsel->attr.sample_id_all) if (!evsel->attr.sample_id_all)
return 0; return 0;
return perf_event__parse_id_sample(event, type, data, swapped); return perf_evsel__parse_id_sample(evsel, event, data);
} }
array = event->sample.array; array = event->sample.array;
......
...@@ -69,6 +69,7 @@ struct perf_evsel { ...@@ -69,6 +69,7 @@ struct perf_evsel {
struct cpu_map *cpus; struct cpu_map *cpus;
unsigned int sample_size; unsigned int sample_size;
bool supported; bool supported;
bool needs_swap;
/* parse modifier helper */ /* parse modifier helper */
int exclude_GH; int exclude_GH;
struct perf_evsel *leader; struct perf_evsel *leader;
...@@ -205,7 +206,7 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel, ...@@ -205,7 +206,7 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
void hists__init(struct hists *hists); void hists__init(struct hists *hists);
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *sample, bool swapped); struct perf_sample *sample);
static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel) static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
{ {
......
...@@ -1256,8 +1256,10 @@ read_event_desc(struct perf_header *ph, int fd) ...@@ -1256,8 +1256,10 @@ read_event_desc(struct perf_header *ph, int fd)
if (ret != (ssize_t)sizeof(nr)) if (ret != (ssize_t)sizeof(nr))
goto error; goto error;
if (ph->needs_swap) if (ph->needs_swap) {
nr = bswap_32(nr); nr = bswap_32(nr);
evsel->needs_swap = true;
}
evsel->name = do_read_string(fd, ph); evsel->name = do_read_string(fd, ph);
...@@ -2626,6 +2628,8 @@ int perf_session__read_header(struct perf_session *session, int fd) ...@@ -2626,6 +2628,8 @@ int perf_session__read_header(struct perf_session *session, int fd)
if (evsel == NULL) if (evsel == NULL)
goto out_delete_evlist; goto out_delete_evlist;
evsel->needs_swap = header->needs_swap;
/* /*
* Do it before so that if perf_evsel__alloc_id fails, this * Do it before so that if perf_evsel__alloc_id fails, this
* entry gets purged too at perf_evlist__delete(). * entry gets purged too at perf_evlist__delete().
......
...@@ -805,7 +805,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, ...@@ -805,7 +805,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
if (pyevent == NULL) if (pyevent == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
err = perf_evlist__parse_sample(evlist, event, &pevent->sample, false); err = perf_evlist__parse_sample(evlist, event, &pevent->sample);
if (err) if (err)
return PyErr_Format(PyExc_OSError, return PyErr_Format(PyExc_OSError,
"perf: can't parse sample, err=%d", err); "perf: can't parse sample, err=%d", err);
......
...@@ -722,8 +722,7 @@ static int flush_sample_queue(struct perf_session *s, ...@@ -722,8 +722,7 @@ static int flush_sample_queue(struct perf_session *s,
if (iter->timestamp > limit) if (iter->timestamp > limit)
break; break;
ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample, ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample);
s->header.needs_swap);
if (ret) if (ret)
pr_err("Can't parse sample, err = %d\n", ret); pr_err("Can't parse sample, err = %d\n", ret);
else { else {
...@@ -1174,8 +1173,7 @@ static int perf_session__process_event(struct perf_session *session, ...@@ -1174,8 +1173,7 @@ static int perf_session__process_event(struct perf_session *session,
/* /*
* For all kernel events we get the sample data * For all kernel events we get the sample data
*/ */
ret = perf_evlist__parse_sample(session->evlist, event, &sample, ret = perf_evlist__parse_sample(session->evlist, event, &sample);
session->header.needs_swap);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment