[PATCH 12/21] perf tools: Add struct parse_args arg to perf_sample__parse

Jiri Olsa
2018-01-24T11:52:19Z

Move perf_sample__parse function arguments into
struct parse_args to be able to pass other sample
type than the one in perf_evsel.

Link: http://lkml.kernel.org/n/tip-1e1vrg29sr8kbjrmi244yft8@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/util/evsel.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 5a95839994a1..035da5d1fdd3 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2045,13 +2045,21 @@ perf_event__check_size(union perf_event *event, unsigned int sample_size)
return 0;
}

+struct parse_args {
+ struct perf_evsel *evsel;
+ union perf_event *event;
+ const u64 *array;
+ u64 type;
+};
+
static int
-perf_sample__parse(struct perf_sample *data, struct perf_evsel *evsel,
- union perf_event *event)
+perf_sample__parse(struct perf_sample *data, struct parse_args *arg)
{
- u64 type = evsel->attr.sample_type;
+ struct perf_evsel *evsel = arg->evsel;
+ union perf_event *event = arg->event;
+ u64 type = arg->type;
+ const u64 *array = arg->array;
bool swapped = evsel->needs_swap;
- const u64 *array;
u16 max_size = event->header.size;
const void *endp = (void *)event + max_size;
u64 sz;
@@ -2062,8 +2070,6 @@ perf_sample__parse(struct perf_sample *data, struct perf_evsel *evsel,
*/
union u64_swap u;

- array = event->sample.array;
-
if (type & PERF_SAMPLE_IDENTIFIER) {
data->id = *array;
array++;
@@ -2310,6 +2316,13 @@ perf_sample__parse(struct perf_sample *data, struct perf_evsel *evsel,
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *data)
{
+ struct parse_args arg = {
+ .evsel = evsel,
+ .event = event,
+ .array = event->sample.array,
+ .type = evsel->attr.sample_type,
+ };
+
memset(data, 0, sizeof(*data));
data->cpu = data->pid = data->tid = -1;
data->stream_id = data->id = data->time = -1ULL;
@@ -2328,7 +2341,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
if (perf_event__check_size(event, evsel->sample_size))
return -EFAULT;

- return perf_sample__parse(data, evsel, event);
+ return perf_sample__parse(data, &arg);
}

int perf_evsel__parse_sample_timestamp(struct perf_evsel *evsel,
--
2.13.6