From e90d08c3e665f90f8f1e1b123739a06f3101a57f Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 13 Jun 2012 18:33:44 -0300 Subject: WIP Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 5 ++-- tools/perf/builtin-test.c | 52 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/evsel.c | 42 ++++++++++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + tools/perf/util/python-ext-sources | 8 ++++++ tools/perf/util/setup.py | 5 ++-- 6 files changed, 109 insertions(+), 4 deletions(-) diff --git a/tools/perf/Makefile b/tools/perf/Makefile index d698c118a602..f43fa32b3f31 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -170,7 +170,7 @@ SCRIPT_SH += perf-archive.sh grep-libs = $(filter -l%,$(1)) strip-libs = $(filter-out -l%,$(1)) -PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources) +PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources | sed 's/OUTPUT/$(OUTPUT)/g') PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) @@ -233,6 +233,7 @@ $(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c: util/pmu.y $(QUIET_BISON)$(BISON) -v util/pmu.y -d -o $(OUTPUT)util/pmu-bison.c +$(OUTPUT)util/evsel.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c $(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c @@ -579,7 +580,7 @@ else PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/ - export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP + export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP OUTPUT python-clean := rm -rf $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 5ce30305462b..9180eb8d4b5f 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c @@ -1103,6 +1103,54 @@ static int test__perf_pmu(void) return perf_pmu__test(); } +static int test__evsel_parser_constructor(const char *ev) +{ + int err = 0; + struct perf_evsel *evsel = perf_evsel__new2(ev); + + if (evsel == NULL) { + pr_debug("perf_evsel__new2 failed!"); + return -1; + } + + if (strcmp(perf_evsel__name(evsel), ev)) { + pr_debug("Expected %s, got %s!\n", ev, perf_evsel__name(evsel)); + ++err; + } + + /* + * Force rebuild + */ + free(evsel->name); + evsel->name = NULL; + if (strcmp(perf_evsel__name(evsel), ev)) { + pr_debug("Expected %s, got %s!\n", ev, perf_evsel__name(evsel)); + ++err; + } + + perf_evsel__delete(evsel); + return err ? -1 : 0; +} + +static int test__evsel_parser_constructors(void) +{ + char ev[] = "cycles:u"; + char *tok = strchr(ev, ':'); + const char modifiers[] = "hkuGp"; + size_t i; + int err = 0; + + if (tok++ == NULL) + return -1; + + for (i = 0; i < sizeof(modifiers) - 1; ++i) { + *tok = modifiers[i]; + err += test__evsel_parser_constructor(ev); + } + + return err ? -1 : 0; +} + static struct test { const char *desc; int (*func)(void); @@ -1141,6 +1189,10 @@ static struct test { .desc = "Test perf pmu format parsing", .func = test__perf_pmu, }, + { + .desc = "evsel parser constructor", + .func = test__evsel_parser_constructors, + }, { .func = NULL, }, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 876f639d69ed..45d1e4883715 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -15,8 +15,14 @@ #include "cpumap.h" #include "thread_map.h" #include "target.h" +#include "parse-events-flex.h" #include "../../include/linux/perf_event.h" +#ifdef PARSER_DEBUG +extern int parse_events_debug; +#endif +int parse_events_parse(struct list_head *list, int *idx); + #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) @@ -46,6 +52,42 @@ void hists__init(struct hists *hists) pthread_mutex_init(&hists->lock, NULL); } +struct perf_evsel *perf_evsel__new2(const char *str) +{ + struct perf_evsel *evsel, *n; + LIST_HEAD(list); + LIST_HEAD(list_tmp); + int ret, idx = 0; + YY_BUFFER_STATE buffer = parse_events__scan_string(str); + +#ifdef PARSER_DEBUG + parse_events_debug = 1; +#endif + ret = parse_events_parse(&list, &idx); + + parse_events__flush_buffer(buffer); + parse_events__delete_buffer(buffer); + parse_events_lex_destroy(); + + if (ret) + goto out_err; + + if (idx > 1) + goto out_delete_list; + + evsel = list_entry(list.next, struct perf_evsel, node); + list_del_init(&evsel->node); + return evsel; + +out_delete_list: + list_for_each_entry_safe(evsel, n, &list, node) { + list_del_init(&evsel->node); + perf_evsel__delete(evsel); + } +out_err: + return NULL; +} + void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, int idx) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 67cc5033d192..c64087b8dcff 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -74,6 +74,7 @@ struct perf_evlist; struct perf_record_opts; struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); +struct perf_evsel *perf_evsel__new2(const char *str); void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, int idx); void perf_evsel__exit(struct perf_evsel *evsel); diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 2884e67ee625..ea88142765e5 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -16,4 +16,12 @@ util/xyarray.c util/cgroup.c util/debugfs.c util/strlist.c +util/parse-events.c +util/pmu.c +util/string.c +util/sysfs.c ../../lib/rbtree.c +OUTPUT/util/parse-events-flex.c +OUTPUT/util/parse-events-bison.c +OUTPUT/util/pmu-flex.c +OUTPUT/util/pmu-bison.c diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py index d0f9f29cf181..209e38f4a55f 100644 --- a/tools/perf/util/setup.py +++ b/tools/perf/util/setup.py @@ -23,13 +23,14 @@ cflags += getenv('CFLAGS', '').split() build_lib = getenv('PYTHON_EXTBUILD_LIB') build_tmp = getenv('PYTHON_EXTBUILD_TMP') +output = getenv('OUTPUT') -ext_sources = [f.strip() for f in file('util/python-ext-sources') +ext_sources = [f.strip().replace("OUTPUT", output) for f in file('util/python-ext-sources') if len(f.strip()) > 0 and f[0] != '#'] perf = Extension('perf', sources = ext_sources, - include_dirs = ['util/include'], + include_dirs = ['util/include', 'util'], extra_compile_args = cflags, ) -- cgit v1.2.3