Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0dd74e8 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf tools: Move event__parse_sample to evsel.c



To avoid linking more stuff in the python binding I'm working on, future
csets will make the sample type be taken from the evsel itself, but for
that we need to first have one file per cpu and per sample_type, not a
single perf.data file.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent fd78260b
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@
#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"

@@ -457,7 +456,6 @@ static int test__basic_mmap(void)
	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 = {
@@ -521,13 +519,6 @@ static int test__basic_mmap(void)
	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);
@@ -567,7 +558,7 @@ static int test__basic_mmap(void)
			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
+1 −1
Original line number Diff line number Diff line
@@ -1106,7 +1106,7 @@ static void perf_session__mmap_read_cpu(struct perf_session *self, int cpu)
	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);
+0 −125
Original line number Diff line number Diff line
@@ -826,128 +826,3 @@ out_filtered:
	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;
}
+3 −2
Original line number Diff line number Diff line
@@ -169,9 +169,10 @@ struct addr_location;
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 */
+118 −0
Original line number Diff line number Diff line
@@ -355,3 +355,121 @@ out_unmap:
	}
	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;
}
Loading