Skip to contentSkip to conversation

perf tools: fix parsing with no sample_id_all bit set

PATCH In review Adrian Hunter 3 participants 6 messages Sep 4, 2013 – Sep 6, 2013 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf tools: fix parsing with no sample_id_all bit set

Hi

Here is a fix, with a test to illustrate the issue.

Adrian Hunter (2):
perf tools: add test for parsing with no sample_id_all bit perf tools: fix parsing with no sample_id_all bit set

 tools/perf/Makefile                       |   3 +-
 tools/perf/tests/builtin-test.c           |   4 ++
 tools/perf/tests/parse-no-sample-id-all.c | 108 ++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h                  |   1 +
 tools/perf/util/evlist.c                  |   9 ++-
 5 files changed, 122 insertions(+), 3 deletions(-)
 create mode 100644 tools/perf/tests/parse-no-sample-id-all.c

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/2 perf tools: add test for parsing with no sample_id_all bit

Add a test for parsing a non-sample event when there is more than one selected event but no sample_id_all bit set.

The test fails because of a bug in the evlist logic. That is fixed in a separate patch.

---
 tools/perf/Makefile                       |   3 +-
 tools/perf/tests/builtin-test.c           |   4 ++
 tools/perf/tests/parse-no-sample-id-all.c | 108 ++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h                  |   1 +
 4 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/tests/parse-no-sample-id-all.c
tools/perf/Makefile +2 -1
index c5dc1ad..3a0ff7f 100644
@@ -394,6 +394,8 @@ ifeq ($(ARCH),x86)
 LIB_OBJS += $(OUTPUT)tests/perf-time-to-tsc.o
 endif
 LIB_OBJS += $(OUTPUT)tests/code-reading.o
+LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
+LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
@@ -439,7 +441,6 @@ PERFLIBS = $(LIB_FILE) $(LIBLK) $(LIBTRACEEVENT)
 ifneq ($(OUTPUT),)
   CFLAGS += -I$(OUTPUT)
 endif
-LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
 
 ifdef NO_LIBELF
 EXTLIBS := $(filter-out -lelf,$(EXTLIBS))
tools/perf/tests/builtin-test.c +4 -0
index 8bbeba3..1e67437 100644
@@ -112,6 +112,10 @@ static struct test {
 		.func = test__keep_tracking,
 	},
 	{
+		.desc = "Test parsing with no sample_id_all bit set",
+		.func = test__parse_no_sample_id_all,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/parse-no-sample-id-all.c new file +108 -0

108 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index c048b58..e0ac713 100644
@@ -39,5 +39,6 @@ int test__perf_time_to_tsc(void);
 int test__code_reading(void);
 int test__sample_parsing(void);
 int test__keep_tracking(void);
+int test__parse_no_sample_id_all(void);
 
 #endif /* TESTS_H */
Signature · 1 line
1.7.11.7
#2 lore raw

[tip:perf/urgent] perf tools: Add test for parsing with no sample_id_all bit

perf tools: Add test for parsing with no sample_id_all bit
Commit-ID:  53a277e5c9b55ed3e91345fb98e5f57d6d70efd6
Gitweb:     http://git.kernel.org/tip/53a277e5c9b55ed3e91345fb98e5f57d6d70efd6
Author:     Adrian Hunter <[email protected]>
AuthorDate: Wed, 4 Sep 2013 23:18:16 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 5 Sep 2013 16:17:46 -0300

perf tools: Add test for parsing with no sample_id_all bit

Add a test for parsing a non-sample event when there is more than one selected event but no sample_id_all bit set.

The test fails because of a bug in the evlist logic. That is fixed in a separate patch.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Makefile                       |   3 +-
 tools/perf/tests/builtin-test.c           |   4 ++
 tools/perf/tests/parse-no-sample-id-all.c | 108 ++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h                  |   1 +
 4 files changed, 115 insertions(+), 1 deletion(-)
tools/perf/Makefile +2 -1
index c5dc1ad..3a0ff7f 100644
@@ -394,6 +394,8 @@ ifeq ($(ARCH),x86)
 LIB_OBJS += $(OUTPUT)tests/perf-time-to-tsc.o
 endif
 LIB_OBJS += $(OUTPUT)tests/code-reading.o
+LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
+LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
@@ -439,7 +441,6 @@ PERFLIBS = $(LIB_FILE) $(LIBLK) $(LIBTRACEEVENT)
 ifneq ($(OUTPUT),)
   CFLAGS += -I$(OUTPUT)
 endif
-LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
 
 ifdef NO_LIBELF
 EXTLIBS := $(filter-out -lelf,$(EXTLIBS))
tools/perf/tests/builtin-test.c +4 -0
index 8bbeba3..1e67437 100644
@@ -112,6 +112,10 @@ static struct test {
 		.func = test__keep_tracking,
 	},
 	{
+		.desc = "Test parsing with no sample_id_all bit set",
+		.func = test__parse_no_sample_id_all,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/parse-no-sample-id-all.c new file +108 -0

108 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index c048b58..e0ac713 100644
@@ -39,5 +39,6 @@ int test__perf_time_to_tsc(void);
 int test__code_reading(void);
 int test__sample_parsing(void);
 int test__keep_tracking(void);
+int test__parse_no_sample_id_all(void);
 
 #endif /* TESTS_H */
author reviewer
#3 lore raw

PATCH 2/2 perf tools: fix parsing with no sample_id_all bit set

In reply to Adrian Hunter

The perf_evlist__event2evsel() is changed to handle non-sample events (such as mmap events) that have no id sample appended i.e. when sample_id_all is not set.

Note that such events have a fixed format, so that the selected event (evsel) they are associated with is immaterial.

---
 tools/perf/util/evlist.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +7 -2
index b8727ae..7101283 100644
@@ -446,20 +446,25 @@ static int perf_evlist__event2id(struct perf_evlist *evlist,
 static struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
 						   union perf_event *event)
 {
+	struct perf_evsel *first = perf_evlist__first(evlist);
 	struct hlist_head *head;
 	struct perf_sample_id *sid;
 	int hash;
 	u64 id;
 
 	if (evlist->nr_entries == 1)
-		return perf_evlist__first(evlist);
+		return first;
+
+	if (!first->attr.sample_id_all &&
+	    event->header.type != PERF_RECORD_SAMPLE)
+		return first;
 
 	if (perf_evlist__event2id(evlist, event, &id))
 		return NULL;
 
 	/* Synthesized events have an id of zero */
 	if (!id)
-		return perf_evlist__first(evlist);
+		return first;
 
 	hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
 	head = &evlist->heads[hash];
Signature · 1 line
1.7.11.7
#4 lore raw
Quoted 9 lines · Adrian Hunter

The perf_evlist__event2evsel() is changed to handle non-sample events (such as mmap events) that have no id sample appended i.e. when sample_id_all is not set.

Note that such events have a fixed format, so that the selected event (evsel) they are associated with is immaterial.

Fixes the regression. Thanks for the fix.

Arnaldo: this needs to go in perf/urgent and pushed into 3.12.

David

#5 lore raw

[tip:perf/urgent] perf evlist: Fix parsing with no sample_id_all bit set

In reply to Adrian Hunter
perf evlist: Fix parsing with no sample_id_all bit set
Commit-ID:  98be6966ed7ed977881305aff5a1bfb305090f43
Gitweb:     http://git.kernel.org/tip/98be6966ed7ed977881305aff5a1bfb305090f43
Author:     Adrian Hunter <[email protected]>
AuthorDate: Wed, 4 Sep 2013 23:18:17 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 5 Sep 2013 16:18:08 -0300

perf evlist: Fix parsing with no sample_id_all bit set

The perf_evlist__event2evsel() is changed to handle non-sample events (such as mmap events) that have no id sample appended i.e. when sample_id_all is not set.

Note that such events have a fixed format, so that the selected event (evsel) they are associated with is immaterial.

---
 tools/perf/util/evlist.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +7 -2
index b8727ae..7101283 100644
@@ -446,20 +446,25 @@ static int perf_evlist__event2id(struct perf_evlist *evlist,
 static struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
 						   union perf_event *event)
 {
+	struct perf_evsel *first = perf_evlist__first(evlist);
 	struct hlist_head *head;
 	struct perf_sample_id *sid;
 	int hash;
 	u64 id;
 
 	if (evlist->nr_entries == 1)
-		return perf_evlist__first(evlist);
+		return first;
+
+	if (!first->attr.sample_id_all &&
+	    event->header.type != PERF_RECORD_SAMPLE)
+		return first;
 
 	if (perf_evlist__event2id(evlist, event, &id))
 		return NULL;
 
 	/* Synthesized events have an id of zero */
 	if (!id)
-		return perf_evlist__first(evlist);
+		return first;
 
 	hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
 	head = &evlist->heads[hash];