perf tools: Add perf pmu object to access pmu format definition
Commit-ID: cd82a32e9924d3a82bd27f830755d23e4ded25bc Gitweb: http://git.kernel.org/tip/cd82a32e9924d3a82bd27f830755d23e4ded25bc Author: Jiri Olsa <[email protected]> AuthorDate: Thu, 15 Mar 2012 20:09:17 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 16 Mar 2012 14:29:35 -0300
perf tools: Add perf pmu object to access pmu format definition
Adding pmu object which provides interface to pmu's sysfs event format definition located at:
${sysfs_mount}/bus/event_source/devices/${pmu}/format
Following interface is exported:
struct perf_pmu* perf_pmu__find(char *name);
- this function returns pmu object, which is then passed as a handle to other interface functions
int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
struct list_head *head_terms);
- this function configures perf_event_attr struct based on pmu's format definitions and config terms data, containined in head_terms list.
Parser generator is used to retrive the pmu's format definition. The generated parser is part of the patch. Added makefile rule 'pmu-parser' to generate the parser code out of the bison/flex sources.
Added builtin test 'Test perf pmu format parsing', which could be run like:
perf test pmu
--- tools/perf/Makefile | 12 + tools/perf/builtin-test.c | 10 + tools/perf/util/pmu-bison.c | 1663 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu-bison.h | 73 ++ tools/perf/util/pmu-flex.c | 1821 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu-flex.h | 316 ++++++++ tools/perf/util/pmu.c | 469 +++++++++++ tools/perf/util/pmu.h | 41 + tools/perf/util/pmu.l | 43 + tools/perf/util/pmu.y | 93 +++ 10 files changed, 4541 insertions(+), 0 deletions(-)
tools/perf/Makefile +12 -0
@@ -276,6 +276,7 @@ LIB_H += util/build-id.h LIB_H += util/debug.h LIB_H += util/debugfs.h LIB_H += util/sysfs.h +LIB_H += util/pmu.h LIB_H += util/event.h LIB_H += util/evsel.h LIB_H += util/evlist.h
@@ -323,6 +324,7 @@ LIB_OBJS += $(OUTPUT)util/config.o LIB_OBJS += $(OUTPUT)util/ctype.o LIB_OBJS += $(OUTPUT)util/debugfs.o LIB_OBJS += $(OUTPUT)util/sysfs.o +LIB_OBJS += $(OUTPUT)util/pmu.o LIB_OBJS += $(OUTPUT)util/environment.o LIB_OBJS += $(OUTPUT)util/event.o LIB_OBJS += $(OUTPUT)util/evlist.o
@@ -361,6 +363,8 @@ 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/pmu-flex.o +LIB_OBJS += $(OUTPUT)util/pmu-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
@@ -773,6 +777,9 @@ $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS $(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/pmu-flex.o: util/pmu-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 $<
@@ -810,6 +817,7 @@ help: @echo ' info - make GNU info documentation (access with info <foo>)' @echo ' pdf - make pdf documentation' @echo ' event-parser - make event parser code' + @echo ' pmu-parser - make pmu format 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'
@@ -863,6 +871,10 @@ 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 +pmu-parser: + $(QUIET_BISON)$(BISON) -v util/pmu.y -d -o util/pmu-bison.c + $(QUIET_FLEX)$(FLEX) --header-file=util/pmu-flex.h -t util/pmu.l > util/pmu-flex.c + ### Detect prefix changes TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/builtin-test.c +10 -0
@@ -13,6 +13,7 @@#include "util/parse-events.h" #include "util/symbol.h" #include "util/thread_map.h" +#include "util/pmu.h" #include "../../include/linux/hw_breakpoint.h" #include <sys/mman.h>
@@ -1484,6 +1485,11 @@ static int test__rdpmc(void)#endif +static int test__perf_pmu (void ) +{ +return perf_pmu__test (); +} + static struct test { const char *desc; int (*func)(void);
@@ -1519,6 +1525,10 @@ static struct test { .func = test__PERF_RECORD, }, { + .desc = "Test perf pmu format parsing", + .func = test__perf_pmu, + }, + { .func = NULL, }, };
tools/perf/util/pmu-bison.c new file +1663 -0
1,663 lines not on this page · raw message
tools/perf/util/pmu-bison.h new file +73 -0
73 lines not on this page · raw message
tools/perf/util/pmu-flex.c new file +1821 -0
1,188 lines not on this page · raw message
tools/perf/util/pmu-flex.h new file +316 -0
316 lines not on this page · raw message
tools/perf/util/pmu.c new file +469 -0
469 lines not on this page · raw message
tools/perf/util/pmu.h new file +41 -0
41 lines not on this page · raw message
tools/perf/util/pmu.l new file +43 -0
43 lines not on this page · raw message
tools/perf/util/pmu.y new file +93 -0
93 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.