perf tools: Add parser generator for events parsing
Commit-ID: 89812fc81f8d62d70433a8ff63d26819f372e8ec Gitweb: http://git.kernel.org/tip/89812fc81f8d62d70433a8ff63d26819f372e8ec Author: Jiri Olsa <[email protected]> AuthorDate: Thu, 15 Mar 2012 20:09:15 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 16 Mar 2012 14:20:21 -0300
perf tools: Add parser generator for events parsing
Changing event parsing to use flex/bison parse generator. The event syntax stays as it was.
grammar description:
events: events ',' event | event
event: event_def PE_MODIFIER_EVENT | event_def
event_def: event_legacy_symbol sep_dc |
event_legacy_cache sep_dc |
event_legacy_breakpoint sep_dc |
event_legacy_tracepoint sep_dc |
event_legacy_numeric sep_dc | event_legacy_raw sep_dc
event_legacy_symbol: PE_NAME_SYM
event_legacy_cache: PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT |
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT | PE_NAME_CACHE_TYPE
event_legacy_raw: PE_SEP_RAW PE_VALUE
event_legacy_numeric: PE_VALUE ':' PE_VALUE
event_legacy_breakpoint: PE_SEP_BP ':' PE_VALUE ':' PE_MODIFIER_BP
event_breakpoint_type: PE_MODIFIER_BPTYPE | empty
PE_NAME_SYM: cpu-cycles|cycles |
stalled-cycles-frontend|idle-cycles-frontend |
stalled-cycles-backend|idle-cycles-backend |
instructions |
cache-references |
cache-misses |
branch-instructions|branches |
branch-misses |
bus-cycles |
cpu-clock |
task-clock |
page-faults|faults |
minor-faults |
major-faults |
context-switches|cs |
cpu-migrations|migrations |
alignment-faults |emulation-faults
PE_NAME_CACHE_TYPE: L1-dcache|l1-d|l1d|L1-data |
L1-icache|l1-i|l1i|L1-instruction |
LLC|L2 |
dTLB|d-tlb|Data-TLB |
iTLB|i-tlb|Instruction-TLB |
branch|branches|bpu|btb|bpc |node
PE_NAME_CACHE_OP_RESULT: load|loads|read |
store|stores|write |
prefetch|prefetches |
speculative-read|speculative-load |
refs|Reference|ops|access |misses|miss
PE_MODIFIER_EVENT: [ukhp]{0,5}
PE_MODIFIER_BP: [rwx]
PE_SEP_BP: 'mem'
PE_SEP_RAW: 'r'
sep_dc: ':' |
Added flex/bison files for event grammar parsing. The generated parser is part of the patch. Added makefile rule 'event-parser' to generate the parser code out of the bison/flex sources.
--- tools/perf/Makefile | 17 + tools/perf/builtin-test.c | 6 +- tools/perf/util/parse-events-bison.c | 1715 ++++++++++++++++++++++++++ tools/perf/util/parse-events-bison.h | 79 ++ tools/perf/util/parse-events-flex.c | 2225 ++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events-flex.h | 316 +++++ tools/perf/util/parse-events.c | 486 +++------ tools/perf/util/parse-events.h | 15 + tools/perf/util/parse-events.l | 107 ++ tools/perf/util/parse-events.y | 127 ++ 10 files changed, 4752 insertions(+), 341 deletions(-)
tools/perf/Makefile +17 -0
@@ -61,6 +61,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ CC = $(CROSS_COMPILE)gcc AR = $(CROSS_COMPILE)ar +FLEX = $(CROSS_COMPILE)flex +BISON= $(CROSS_COMPILE)bison # Additional ARCH settings for x86 ifeq ($(ARCH),i386)
@@ -357,6 +359,8 @@ LIB_OBJS += $(OUTPUT)util/session.o LIB_OBJS += $(OUTPUT)util/thread.o LIB_OBJS += $(OUTPUT)util/thread_map.o LIB_OBJS += $(OUTPUT)util/trace-event-parse.o +LIB_OBJS += $(OUTPUT)util/parse-events-flex.o +LIB_OBJS += $(OUTPUT)util/parse-events-bison.o LIB_OBJS += $(OUTPUT)util/trace-event-read.o LIB_OBJS += $(OUTPUT)util/trace-event-info.o LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -645,6 +649,8 @@ ifndef V QUIET_LINK = @echo ' ' LINK $@; QUIET_MKDIR = @echo ' ' MKDIR $@; QUIET_GEN = @echo ' ' GEN $@; + QUIET_FLEX = @echo ' ' FLEX $@; + QUIET_BISON = @echo ' ' BISON $@; endif endif
@@ -725,6 +731,9 @@ $(OUTPUT)perf.o perf.spec \ $(SCRIPTS) \ : $(OUTPUT)PERF-VERSION-FILE +.SUFFIXES: +.SUFFIXES: .o .c .S .s + $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< $(OUTPUT)%.i: %.c $(OUTPUT)PERF-CFLAGS
@@ -761,6 +770,9 @@ $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< +$(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $< + $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
@@ -797,6 +809,7 @@ help: @echo ' html - make html documentation' @echo ' info - make GNU info documentation (access with info <foo>)' @echo ' pdf - make pdf documentation' + @echo ' event-parser - make event parser code' @echo ' TAGS - use etags to make tag information for source browsing' @echo ' tags - use ctags to make tag information for source browsing' @echo ' cscope - use cscope to make interactive browsing database'
@@ -846,6 +859,10 @@ cscope: $(RM) cscope* $(FIND) . -name '*.[hcS]' -print | xargs cscope -b +event-parser: + $(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o util/parse-events-bison.c + $(QUIET_FLEX)$(FLEX) --header-file=util/parse-events-flex.h -t util/parse-events.l > util/parse-events-flex.c + ### Detect prefix changes TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/builtin-test.c +3 -3
@@ -650,7 +650,7 @@ static int test__checkevent_raw(struct perf_evlist *evlist)TEST_ASSERT_VAL ("wrong number of entries" ,1 == evlist->nr_entries);TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_RAW == evsel->attr.type); -TEST_ASSERT_VAL ("wrong config" ,1 == evsel->attr.config); +TEST_ASSERT_VAL ("wrong config" ,0x1a == evsel->attr.config);return 0 ; }
@@ -872,7 +872,7 @@ static struct test__event_st { .check = test__checkevent_tracepoint_multi, }, { - .name = "r1", + .name = "r1a", .check = test__checkevent_raw, }, {
@@ -916,7 +916,7 @@ static struct test__event_st { .check = test__checkevent_tracepoint_multi_modifier, }, { - .name = "r1:kp", + .name = "r1a:kp", .check = test__checkevent_raw_modifier, }, {
tools/perf/util/parse-events-bison.c new file +1715 -0
1,715 lines not on this page · raw message
tools/perf/util/parse-events-bison.h new file +79 -0
79 lines not on this page · raw message
tools/perf/util/parse-events-flex.c new file +2225 -0
1,123 lines not on this page · raw message
tools/perf/util/parse-events-flex.h new file +316 -0
316 lines not on this page · raw message
tools/perf/util/parse-events.c +148 -338
486 lines not on this page · raw message
tools/perf/util/parse-events.l new file +107 -0
107 lines not on this page · raw message
tools/perf/util/parse-events.y new file +127 -0
127 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.