perf tools: fix parsing with no sample_id_all bit set
Adrian Hunter
reviewercover 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
Adrian Hunter
reviewerPATCH 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
@@ -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
@@ -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
@@ -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
tip-bot for Adrian Hunter
merge bot[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.
--- 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
@@ -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
@@ -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
@@ -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 */
Adrian Hunter
reviewerPATCH 2/2 perf tools: fix parsing with no sample_id_all bit set
In reply to Adrian HunterThe 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
@@ -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
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. whensample_id_allis not set.Note that such events have a fixed format, so that the selected event (evsel) they are associated with is immaterial.
Signed-off-by Adrian Hunter <[email protected]>
Fixes the regression. Thanks for the fix.
Arnaldo: this needs to go in perf/urgent and pushed into 3.12.
David
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf evlist: Fix parsing with no sample_id_all bit set
In reply to Adrian Hunterperf 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
@@ -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];