perf tools: Add config options support for event parsing
Commit-ID: 8f707d843c2f4023490a873dbc182f632a3a5906 Gitweb: http://git.kernel.org/tip/8f707d843c2f4023490a873dbc182f632a3a5906 Author: Jiri Olsa <[email protected]> AuthorDate: Thu, 15 Mar 2012 20:09:16 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 16 Mar 2012 14:26:06 -0300
perf tools: Add config options support for event parsing
Adding a new rule to the event grammar to be able to specify values of additional attributes of symbolic event.
The new syntax for event symbolic definition is:
event_legacy_symbol: PE_NAME_SYM '/' event_config '/' |
PE_NAME_SYM sep_slash_dc
event_config: event_config ',' event_term | event_term
event_term: PE_NAME '=' PE_NAME |
PE_NAME '=' PE_VALUE
PE_NAME
sep_slash_dc: '/' | ':' |
At the moment the config options are hardcoded to be used for legacy symbol events to define several perf_event_attr fields. It is:
'config' to define perf_event_attr::config 'config1' to define perf_event_attr::config1 'config2' to define perf_event_attr::config2 'period' to define perf_event_attr::sample_period
Legacy events could be now specified as:
cycles/period=100000/
If term is specified without the value assignment, then 1 is assigned by default.
--- tools/perf/builtin-test.c | 22 + tools/perf/util/parse-events-bison.c | 310 +++++++++++----- tools/perf/util/parse-events-bison.h | 23 +- tools/perf/util/parse-events-flex.c | 713 ++++++++++++++++++---------------- tools/perf/util/parse-events-flex.h | 2 +- tools/perf/util/parse-events.c | 99 +++++- tools/perf/util/parse-events.h | 31 ++- tools/perf/util/parse-events.l | 19 + tools/perf/util/parse-events.y | 94 +++++- 9 files changed, 866 insertions(+), 447 deletions(-)
tools/perf/builtin-test.c +22 -0
@@ -677,6 +677,24 @@ static int test__checkevent_symbolic_name(struct perf_evlist *evlist)return 0 ; } +static int test__checkevent_symbolic_name_config (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel =list_entry (evlist->entries.next, + struct perf_evsel, node); + +TEST_ASSERT_VAL ("wrong number of entries" ,1 == evlist->nr_entries); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong period" , +100000 == evsel->attr.sample_period); +TEST_ASSERT_VAL ("wrong config1" , +0 == evsel->attr.config1); +TEST_ASSERT_VAL ("wrong config2" , +1 == evsel->attr.config2); +return 0 ; +} +static int test__checkevent_symbolic_alias (struct perf_evlist *evlist) { struct perf_evsel *evsel = list_entry(evlist->entries.next,
@@ -884,6 +902,10 @@ static struct test__event_st { .check = test__checkevent_symbolic_name, }, { + .name = "cycles/period=100000,config2/", + .check = test__checkevent_symbolic_name_config, + }, + { .name = "faults", .check = test__checkevent_symbolic_alias, },
tools/perf/util/parse-events-bison.c +217 -93
522 lines not on this page · raw message
tools/perf/util/parse-events-bison.h +13 -10
@@ -41,14 +41,15 @@PE_VALUE =258 ,PE_VALUE_SYM =259 ,PE_RAW =260 , -PE_NAME =261 , -PE_MODIFIER_EVENT =262 , -PE_MODIFIER_BP =263 , -PE_NAME_CACHE_TYPE =264 , -PE_NAME_CACHE_OP_RESULT =265 , -PE_PREFIX_MEM =266 , -PE_PREFIX_RAW =267 , -PE_ERROR =268 +PE_TERM =261 , +PE_NAME =262 , +PE_MODIFIER_EVENT =263 , +PE_MODIFIER_BP =264 , +PE_NAME_CACHE_TYPE =265 , +PE_NAME_CACHE_OP_RESULT =266 , +PE_PREFIX_MEM =267 , +PE_PREFIX_RAW =268 , +PE_ERROR =269 };#endif
@@ -59,15 +60,17 @@ typedef union YYSTYPE {/* Line 1685 of yacc.c */ -#line 42 "util/parse-events.y" +#line 45 "util/parse-events.y"char *str;unsigned long num; +struct list_head *head; +struct parse_events__term *term;/* Line 1685 of yacc.c */ -#line 71 "util/parse-events-bison.h" +#line 74 "util/parse-events-bison.h" }YYSTYPE ;# define YYSTYPE_IS_TRIVIAL 1# define yystype YYSTYPE/* obsolescent; will be withdrawn */
tools/perf/util/parse-events-flex.c +380 -333
947 lines not on this page · raw message
tools/perf/util/parse-events-flex.h +1 -1
@@ -308,7 +308,7 @@ extern int parse_events_lex (void);#undef YY_DECL#endif -#line 102 "util/parse-events.l" +#line 121 "util/parse-events.l"#line 315 "util/parse-events-flex.h"
tools/perf/util/parse-events.c +96 -3
114 lines not on this page · raw message
tools/perf/util/parse-events.h +30 -1
@@ -33,6 +33,34 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);#define EVENTS_HELP_MAX (128*1024) +enum { +PARSE_EVENTS__TERM_TYPE_CONFIG , +PARSE_EVENTS__TERM_TYPE_CONFIG1 , +PARSE_EVENTS__TERM_TYPE_CONFIG2 , +PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD , +PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE , +PARSE_EVENTS__TERM_TYPE_NUM , +PARSE_EVENTS__TERM_TYPE_STR , + +PARSE_EVENTS__TERM_TYPE_HARDCODED_MAX = +PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE , +}; + +struct parse_events__term { +char *config; +union { +char *str; +long num; + } val; +int type; + +struct list_head list; +}; + +int parse_events__is_hardcoded_term (struct parse_events__term *term); +int parse_events__new_term (struct parse_events__term **term,int type, +char *config,char *str,long num); +void parse_events__free_terms (struct list_head *terms);int parse_events_modifier (struct list_head *list__used ,char *str__used );int parse_events_add_tracepoint (struct list_head *list,int *idx,char *sys,char *event);
@@ -40,7 +68,8 @@ int parse_events_add_raw(struct perf_evlist *evlist, unsigned long config, unsigned long config1, unsigned long config2, char *mod);int parse_events_add_numeric (struct list_head *list,int *idx, -unsigned long type,unsigned long config); +unsigned long type,unsigned long config, +struct list_head *head_config);int parse_events_add_cache (struct list_head *list,int *idx,char *type,char *op_result1,char *op_result2); int parse_events_add_breakpoint(struct list_head *list, int *idx,
tools/perf/util/parse-events.l +19 -0
@@ -5,6 +5,7 @@ #include <errno.h> #include "../perf.h" #include "parse-events-bison.h" +#include "parse-events.h" static int __value(char *str, int base, int token) {
@@ -41,6 +42,12 @@ static int sym(int type, int config) return PE_VALUE_SYM; } +static int term(int type) +{ + parse_events_lval.num = type; + return PE_TERM; +} + %} num_dec [0-9]+
@@ -85,6 +92,18 @@ speculative-read|speculative-load | refs|Reference|ops|access | misses|miss { return str(PE_NAME_CACHE_OP_RESULT); } + /* + * These are event config hardcoded term names to be specified + * within xxx/.../ syntax. So far we dont clash with other names, + * so we can put them here directly. In case the we have a conflict + * in future, this needs to go into '//' condition block. + */ +config { return term(PARSE_EVENTS__TERM_TYPE_CONFIG); } +config1 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG1); } +config2 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG2); } +period { return term(PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } +branch_type { return term(PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } + mem: { return PE_PREFIX_MEM; } r{num_raw_hex} { return raw(); } {num_dec} { return value(10); }
tools/perf/util/parse-events.y +88 -6
147 lines not on this page · raw message