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

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

perf evlist: Don't die if sample_{id_all|type} is invalid

Fixes two more cases where the python binding would not load:

. Not finding die(), which it shouldn't anyway, not good to just stop the
  world because some particular perf.data file is invalid, just propagate
  the error to the caller.

. Not finding perf_sample_size: fix it by moving it from event.c to evsel,
  where it belongs, as most cases are moving to operate on an evsel object.o

One of the fixed problems:

[root@emilia ~]# python
>>> import perf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/acme/git/build/perf/python/perf.so: undefined symbol: perf_sample_size
>>>
[root@emilia ~]#

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
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-1hkj7b2cvgbfnoizsekjb6c9@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9c850d6c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -474,7 +474,7 @@ static int test__basic_mmap(void)
	unsigned int nr_events[nsyscalls],
		     expected_nr_events[nsyscalls], i, j;
	struct perf_evsel *evsels[nsyscalls], *evsel;
	int sample_size = perf_sample_size(attr.sample_type);
	int sample_size = __perf_evsel__sample_size(attr.sample_type);

	for (i = 0; i < nsyscalls; ++i) {
		char name[64];
+0 −16
Original line number Diff line number Diff line
@@ -35,22 +35,6 @@ const char *perf_event__name(unsigned int id)
	return perf_event__names[id];
}

int perf_sample_size(u64 sample_type)
{
	u64 mask = sample_type & PERF_SAMPLE_MASK;
	int size = 0;
	int i;

	for (i = 0; i < 64; i++) {
		if (mask & (1ULL << i))
			size++;
	}

	size *= sizeof(u64);

	return size;
}

static struct perf_sample synth_sample = {
	.pid	   = -1,
	.tid	   = -1,
+0 −2
Original line number Diff line number Diff line
@@ -82,8 +82,6 @@ struct perf_sample {
	struct ip_callchain *callchain;
};

int perf_sample_size(u64 sample_type);

#define BUILD_ID_SIZE 20

struct build_id_event {
+34 −21
Original line number Diff line number Diff line
@@ -455,33 +455,46 @@ int perf_evlist__set_filters(struct perf_evlist *evlist)
	return 0;
}

u64 perf_evlist__sample_type(struct perf_evlist *evlist)
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
{
	struct perf_evsel *pos;
	u64 type = 0;
	struct perf_evsel *pos, *first;

	list_for_each_entry(pos, &evlist->entries, node) {
		if (!type)
			type = pos->attr.sample_type;
		else if (type != pos->attr.sample_type)
			die("non matching sample_type");
	pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);

	list_for_each_entry_continue(pos, &evlist->entries, node) {
		if (first->attr.sample_type != pos->attr.sample_type)
			return false;
	}

	return type;
	return true;
}

bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
u64 perf_evlist__sample_type(const struct perf_evlist *evlist)
{
	struct perf_evsel *first;

	first = list_entry(evlist->entries.next, struct perf_evsel, node);
	return first->attr.sample_type;
}

bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist)
{
	bool value = false, first = true;
	struct perf_evsel *pos;
	struct perf_evsel *pos, *first;

	list_for_each_entry(pos, &evlist->entries, node) {
		if (first) {
			value = pos->attr.sample_id_all;
			first = false;
		} else if (value != pos->attr.sample_id_all)
			die("non matching sample_id_all");
	pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);

	list_for_each_entry_continue(pos, &evlist->entries, node) {
		if (first->attr.sample_id_all != pos->attr.sample_id_all)
			return false;
	}

	return true;
}

	return value;
bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
{
	struct perf_evsel *first;

	first = list_entry(evlist->entries.next, struct perf_evsel, node);
	return first->attr.sample_id_all;
}
+4 −2
Original line number Diff line number Diff line
@@ -66,7 +66,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid,
void perf_evlist__delete_maps(struct perf_evlist *evlist);
int perf_evlist__set_filters(struct perf_evlist *evlist);

u64 perf_evlist__sample_type(struct perf_evlist *evlist);
bool perf_evlist__sample_id_all(const struct perf_evlist *evlist);
u64 perf_evlist__sample_type(const struct perf_evlist *evlist);
bool perf_evlist__sample_id_all(const const struct perf_evlist *evlist);

bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
#endif /* __PERF_EVLIST_H */
Loading