summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-events.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-06-15 14:31:40 +0800
committerIngo Molnar <mingo@kernel.org>2012-06-18 12:13:25 +0200
commit90e2b22dee908c13df256140a0d6527e3e8ea3f4 (patch)
tree1b874dc6daed04ffd2e6cbdcf30b649407b4f77d /tools/perf/util/parse-events.c
parentac20de6fff445d6deb0c44c25946d198f79f2f00 (diff)
downloadlinux-90e2b22dee908c13df256140a0d6527e3e8ea3f4.tar.gz
linux-90e2b22dee908c13df256140a0d6527e3e8ea3f4.tar.bz2
linux-90e2b22dee908c13df256140a0d6527e3e8ea3f4.zip
perf/tool: Add support to reuse event grammar to parse out terms
We want to reuse the event grammar for parsing aliased terms. The obvious reason is we dont need to add new code when there's already support for this in event grammar. Doing this by adding terms and event start entries into event parse grammar. The grammar forks on the begining based on the starting token, which is supplied via bison interface into the lexer. The lexer then returns the starting token as the first token, thus making the grammar switch accordingly. Currently 2 starting tokens/grammars are supported: PE_START_TERMS, PE_START_EVENTS The PE_START_TERMS related grammar uses 'event_config' part of the grammar for term parsing. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1339741902-8449-12-git-send-email-zheng.z.yan@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r--tools/perf/util/parse-events.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index ca8665e19c0d..d002170adb3f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -12,6 +12,7 @@
#include "header.h"
#include "debugfs.h"
#include "parse-events-bison.h"
+#define YY_EXTRA_TYPE int
#include "parse-events-flex.h"
#include "pmu.h"
@@ -788,13 +789,13 @@ int parse_events_modifier(struct list_head *list, char *str)
return 0;
}
-static int parse_events__scanner(const char *str, void *data)
+static int parse_events__scanner(const char *str, void *data, int start_token)
{
YY_BUFFER_STATE buffer;
void *scanner;
int ret;
- ret = parse_events_lex_init(&scanner);
+ ret = parse_events_lex_init_extra(start_token, &scanner);
if (ret)
return ret;
@@ -811,6 +812,27 @@ static int parse_events__scanner(const char *str, void *data)
return ret;
}
+/*
+ * parse event config string, return a list of event terms.
+ */
+int parse_events_terms(struct list_head *terms, const char *str)
+{
+ struct parse_events_data__terms data = {
+ .terms = NULL,
+ };
+ int ret;
+
+ ret = parse_events__scanner(str, &data, PE_START_TERMS);
+ if (!ret) {
+ list_splice(data.terms, terms);
+ free(data.terms);
+ return 0;
+ }
+
+ parse_events__free_terms(data.terms);
+ return ret;
+}
+
int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
{
struct parse_events_data__events data = {
@@ -819,7 +841,7 @@ int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
};
int ret;
- ret = parse_events__scanner(str, &data);
+ ret = parse_events__scanner(str, &data, PE_START_EVENTS);
if (!ret) {
int entries = data.idx - evlist->nr_entries;
perf_evlist__splice_list_tail(evlist, &data.list, entries);