perf tools: Report event parsing errors
Jiri Olsa
reviewercover perf tools: Report event parsing errors
hi,
adding support to report error from event string parsing.
v1 changes (from RFC):
- display list of allowed terms for pmu event error [Ingo]
- changing 'invalid or unsupported event' string into 'event syntax error' for cases we know the precise error
This patchset contains support for standard parsing errors and more logic to recognize tracepoint and 'pmu//' terms, like:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
... $ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2..
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...Changes are also reachable in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/event_parse_error
thanks
jirka
---
Jiri Olsa (9):
perf tools: Add parse_events_error interface
perf tools: Add flex support for parse_events_error perf tools: Always bail out when config_attr function fails perf tools: Change parse_events_add_pmu interface perf tools: Add location to pmu event terms
perf tools: Add term support for parse_events_error perf tools: Add static terms support for parse_events_error perf tools: Add tracepoint support for parse_events_error perf tools: Add symbolic events support for parse_events_error
tools/perf/builtin-stat.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 4 +- tools/perf/tests/hists_link.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/keep-tracking.c | 4 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/pmu.c | 3 +- tools/perf/tests/switch-tracking.c | 8 +-- tools/perf/util/parse-events.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------- tools/perf/util/parse-events.h | 36 ++++++++---- tools/perf/util/parse-events.l | 41 ++++++++++++-- tools/perf/util/parse-events.y | 48 ++++++++-------- tools/perf/util/pmu.c | 57 +++++++++++++++++-- tools/perf/util/pmu.h | 6 +- tools/perf/util/record.c | 4 +- 19 files changed, 325 insertions(+), 100 deletions(-)
Jiri Olsa
reviewerPATCH 1/9 perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function. Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};where 'idx' is the position in the string where the parsing failed, 'str' contains dynamically allocated error string describing the error and 'help' is optional help string.
The change contains reporting function, which currently does not display anything. The code changes to supply error data for specific event types are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
... $ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...The output functions cut the beginning of the event string so the error starts up to 10th character and cut the end of the string of it crosses the terminal width.
--- tools/perf/builtin-stat.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 4 +- tools/perf/tests/hists_link.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/keep-tracking.c | 4 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/switch-tracking.c | 8 +-- tools/perf/util/parse-events.c | 100 +++++++++++++++++++++++++++++--- tools/perf/util/parse-events.h | 19 ++++-- tools/perf/util/record.c | 4 +- 14 files changed, 127 insertions(+), 32 deletions(-)
tools/perf/builtin-stat.c +1 -1
@@ -1541,7 +1541,7 @@ static int setup_events(const char * const *attrs, unsigned len)unsigned i;for (i =0 ; i < len; i++) { -if (parse_events (evsel_list, attrs[i])) +if (parse_events (evsel_list, attrs[i],NULL ))return -1 ; }return 0 ;
tools/perf/tests/code-reading.c +1 -1
@@ -482,7 +482,7 @@ static int do_test_code_reading(bool try_kcore)else str ="cycles" ;pr_debug ("Parsing event '%s'\n" , str); - ret =parse_events (evlist, str); + ret =parse_events (evlist, str,NULL );if (ret <0 ) {pr_debug ("parse_events failed\n" ); goto out_err;
tools/perf/tests/evsel-roundtrip-name.c +2 -2
@@ -23,7 +23,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)for (i =0 ; i <PERF_COUNT_HW_CACHE_RESULT_MAX ; i++) {__perf_evsel__hw_cache_type_op_res_name (type, op, i, name,sizeof (name)); - err =parse_events (evlist, name); + err =parse_events (evlist, name,NULL );if (err) ret = err; }
@@ -71,7 +71,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names)return -ENOMEM ;for (i =0 ; i < nr_names; ++i) { - err =parse_events (evlist, names[i]); + err =parse_events (evlist, names[i],NULL );if (err) {pr_debug ("failed to parse event '%s', err %d\n" , names[i], err);
tools/perf/tests/hists_cumulate.c +1 -1
@@ -695,7 +695,7 @@ int test__hists_cumulate(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_filter.c +2 -2
@@ -108,10 +108,10 @@ int test__hists_filter(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out; - err =parse_events (evlist,"task-clock" ); + err =parse_events (evlist,"task-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_link.c +2 -2
@@ -282,10 +282,10 @@ int test__hists_link(void)if (evlist ==NULL )return -ENOMEM ; - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out; - err =parse_events (evlist,"task-clock" ); + err =parse_events (evlist,"task-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_output.c +1 -1
@@ -590,7 +590,7 @@ int test__hists_output(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out;
tools/perf/tests/keep-tracking.c +2 -2
@@ -78,8 +78,8 @@ int test__keep_tracking(void)perf_evlist__set_maps (evlist, cpus, threads); -CHECK__ (parse_events (evlist,"dummy:u" )); -CHECK__ (parse_events (evlist,"cycles:u" )); +CHECK__ (parse_events (evlist,"dummy:u" ,NULL )); +CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));perf_evlist__config (evlist, &opts);
tools/perf/tests/parse-events.c +1 -1
@@ -1571,7 +1571,7 @@ static int test_event(struct evlist_test *e)if (evlist ==NULL )return -ENOMEM ; - ret =parse_events (evlist, e->name); + ret =parse_events (evlist, e->name,NULL );if (ret) {pr_debug ("failed to parse event '%s', err %d\n" , e->name, ret);
tools/perf/tests/perf-time-to-tsc.c +1 -1
@@ -68,7 +68,7 @@ int test__perf_time_to_tsc(void)perf_evlist__set_maps (evlist, cpus, threads); -CHECK__ (parse_events (evlist,"cycles:u" )); +CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));perf_evlist__config (evlist, &opts);
tools/perf/tests/switch-tracking.c +4 -4
@@ -347,7 +347,7 @@ int test__switch_tracking(void)perf_evlist__set_maps (evlist, cpus, threads);/* First event */ - err =parse_events (evlist,"cpu-clock:u" ); + err =parse_events (evlist,"cpu-clock:u" ,NULL );if (err) {pr_debug ("Failed to parse event dummy:u\n" ); goto out_err;
@@ -356,7 +356,7 @@ int test__switch_tracking(void) cpu_clocks_evsel =perf_evlist__last (evlist);/* Second event */ - err =parse_events (evlist,"cycles:u" ); + err =parse_events (evlist,"cycles:u" ,NULL );if (err) {pr_debug ("Failed to parse event cycles:u\n" ); goto out_err;
@@ -371,7 +371,7 @@ int test__switch_tracking(void) goto out; } - err =parse_events (evlist, sched_switch); + err =parse_events (evlist, sched_switch,NULL );if (err) {pr_debug ("Failed to parse event %s\n" , sched_switch); goto out_err;
@@ -401,7 +401,7 @@ int test__switch_tracking(void)perf_evsel__set_sample_bit (cycles_evsel,TIME );/* Fourth event */ - err =parse_events (evlist,"dummy:u" ); + err =parse_events (evlist,"dummy:u" ,NULL );if (err) {pr_debug ("Failed to parse event dummy:u\n" ); goto out_err;
tools/perf/util/parse-events.c +92 -8
128 lines not on this page · raw message
tools/perf/util/parse-events.h +15 -4
@@ -12,6 +12,7 @@struct list_head ;struct perf_evsel ;struct perf_evlist ; +struct parse_events_error ;struct option ;
@@ -29,7 +30,8 @@ const char *event_type(int type);extern int parse_events_option (const struct option *opt,const char *str,int unset); -extern int parse_events (struct perf_evlist *evlist,const char *str); +extern int parse_events (struct perf_evlist *evlist,const char *str, +struct parse_events_error *error);extern int parse_events_terms (struct list_head *terms,const char *str);extern int parse_filter (const struct option *opt,const char *str,int unset);
@@ -74,10 +76,17 @@ struct parse_events_term {bool used; }; +struct parse_events_error { +int idx;/* index in the parsed string */ +char *str;/* string to display at the index */ +char *help;/* optional help string */ +}; +struct parse_events_evlist { -struct list_head list; -int idx; -int nr_groups; +struct list_head list; +int idx; +int nr_groups; +struct parse_events_error *error; };struct parse_events_terms {
@@ -114,6 +123,8 @@ void parse_events__set_leader(char *name, struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all);void parse_events_error (void *data,void *scanner,char const *msg); +void parse_events_evlist_error (struct parse_events_evlist *data, +int idx,const char *str);void print_events (const char *event_glob,bool name_only);
tools/perf/util/record.c +2 -2
@@ -20,7 +20,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)if (!evlist)return -ENOMEM ; -if (parse_events (evlist, str)) +if (parse_events (evlist, str,NULL )) goto out_delete; evsel =perf_evlist__first (evlist);
@@ -216,7 +216,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)if (!temp_evlist)return false; - err =parse_events (temp_evlist, str); + err =parse_events (temp_evlist, str,NULL );if (err) goto out_delete;
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add parse_events_error interface
perf tools: Add parse_events_error interface
Commit-ID: b39b839309ce8c5dd15cd95d26af153fa392c3e6 Gitweb: http://git.kernel.org/tip/b39b839309ce8c5dd15cd95d26af153fa392c3e6 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:16 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:37:58 -0300
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function. Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};where 'idx' is the position in the string where the parsing failed, 'str' contains dynamically allocated error string describing the error and 'help' is optional help string.
The change contains reporting function, which currently does not display anything. The code changes to supply error data for specific event types are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
... $ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...The output functions cut the beginning of the event string so the error starts up to 10th character and cut the end of the string of it crosses the terminal width.
--- tools/perf/builtin-stat.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 4 +- tools/perf/tests/hists_link.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/keep-tracking.c | 4 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/switch-tracking.c | 8 +-- tools/perf/util/parse-events.c | 100 +++++++++++++++++++++++++++++--- tools/perf/util/parse-events.h | 19 ++++-- tools/perf/util/record.c | 4 +- 14 files changed, 127 insertions(+), 32 deletions(-)
tools/perf/builtin-stat.c +1 -1
@@ -1541,7 +1541,7 @@ static int setup_events(const char * const *attrs, unsigned len)unsigned i;for (i =0 ; i < len; i++) { -if (parse_events (evsel_list, attrs[i])) +if (parse_events (evsel_list, attrs[i],NULL ))return -1 ; }return 0 ;
tools/perf/tests/code-reading.c +1 -1
@@ -482,7 +482,7 @@ static int do_test_code_reading(bool try_kcore)else str ="cycles" ;pr_debug ("Parsing event '%s'\n" , str); - ret =parse_events (evlist, str); + ret =parse_events (evlist, str,NULL );if (ret <0 ) {pr_debug ("parse_events failed\n" ); goto out_err;
tools/perf/tests/evsel-roundtrip-name.c +2 -2
@@ -23,7 +23,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)for (i =0 ; i <PERF_COUNT_HW_CACHE_RESULT_MAX ; i++) {__perf_evsel__hw_cache_type_op_res_name (type, op, i, name,sizeof (name)); - err =parse_events (evlist, name); + err =parse_events (evlist, name,NULL );if (err) ret = err; }
@@ -71,7 +71,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names)return -ENOMEM ;for (i =0 ; i < nr_names; ++i) { - err =parse_events (evlist, names[i]); + err =parse_events (evlist, names[i],NULL );if (err) {pr_debug ("failed to parse event '%s', err %d\n" , names[i], err);
tools/perf/tests/hists_cumulate.c +1 -1
@@ -695,7 +695,7 @@ int test__hists_cumulate(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_filter.c +2 -2
@@ -108,10 +108,10 @@ int test__hists_filter(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out; - err =parse_events (evlist,"task-clock" ); + err =parse_events (evlist,"task-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_link.c +2 -2
@@ -282,10 +282,10 @@ int test__hists_link(void)if (evlist ==NULL )return -ENOMEM ; - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out; - err =parse_events (evlist,"task-clock" ); + err =parse_events (evlist,"task-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_output.c +1 -1
@@ -590,7 +590,7 @@ int test__hists_output(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out;
tools/perf/tests/keep-tracking.c +2 -2
@@ -78,8 +78,8 @@ int test__keep_tracking(void)perf_evlist__set_maps (evlist, cpus, threads); -CHECK__ (parse_events (evlist,"dummy:u" )); -CHECK__ (parse_events (evlist,"cycles:u" )); +CHECK__ (parse_events (evlist,"dummy:u" ,NULL )); +CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));perf_evlist__config (evlist, &opts);
tools/perf/tests/parse-events.c +1 -1
@@ -1571,7 +1571,7 @@ static int test_event(struct evlist_test *e)if (evlist ==NULL )return -ENOMEM ; - ret =parse_events (evlist, e->name); + ret =parse_events (evlist, e->name,NULL );if (ret) {pr_debug ("failed to parse event '%s', err %d\n" , e->name, ret);
tools/perf/tests/perf-time-to-tsc.c +1 -1
@@ -68,7 +68,7 @@ int test__perf_time_to_tsc(void)perf_evlist__set_maps (evlist, cpus, threads); -CHECK__ (parse_events (evlist,"cycles:u" )); +CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));perf_evlist__config (evlist, &opts);
tools/perf/tests/switch-tracking.c +4 -4
@@ -347,7 +347,7 @@ int test__switch_tracking(void)perf_evlist__set_maps (evlist, cpus, threads);/* First event */ - err =parse_events (evlist,"cpu-clock:u" ); + err =parse_events (evlist,"cpu-clock:u" ,NULL );if (err) {pr_debug ("Failed to parse event dummy:u\n" ); goto out_err;
@@ -356,7 +356,7 @@ int test__switch_tracking(void) cpu_clocks_evsel =perf_evlist__last (evlist);/* Second event */ - err =parse_events (evlist,"cycles:u" ); + err =parse_events (evlist,"cycles:u" ,NULL );if (err) {pr_debug ("Failed to parse event cycles:u\n" ); goto out_err;
@@ -371,7 +371,7 @@ int test__switch_tracking(void) goto out; } - err =parse_events (evlist, sched_switch); + err =parse_events (evlist, sched_switch,NULL );if (err) {pr_debug ("Failed to parse event %s\n" , sched_switch); goto out_err;
@@ -401,7 +401,7 @@ int test__switch_tracking(void)perf_evsel__set_sample_bit (cycles_evsel,TIME );/* Fourth event */ - err =parse_events (evlist,"dummy:u" ); + err =parse_events (evlist,"dummy:u" ,NULL );if (err) {pr_debug ("Failed to parse event dummy:u\n" ); goto out_err;
tools/perf/util/parse-events.c +92 -8
128 lines not on this page · raw message
tools/perf/util/parse-events.h +15 -4
@@ -12,6 +12,7 @@struct list_head ;struct perf_evsel ;struct perf_evlist ; +struct parse_events_error ;struct option ;
@@ -29,7 +30,8 @@ const char *event_type(int type);extern int parse_events_option (const struct option *opt,const char *str,int unset); -extern int parse_events (struct perf_evlist *evlist,const char *str); +extern int parse_events (struct perf_evlist *evlist,const char *str, +struct parse_events_error *error);extern int parse_events_terms (struct list_head *terms,const char *str);extern int parse_filter (const struct option *opt,const char *str,int unset);
@@ -74,10 +76,17 @@ struct parse_events_term {bool used; }; +struct parse_events_error { +int idx;/* index in the parsed string */ +char *str;/* string to display at the index */ +char *help;/* optional help string */ +}; +struct parse_events_evlist { -struct list_head list; -int idx; -int nr_groups; +struct list_head list; +int idx; +int nr_groups; +struct parse_events_error *error; };struct parse_events_terms {
@@ -114,6 +123,8 @@ void parse_events__set_leader(char *name, struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all);void parse_events_error (void *data,void *scanner,char const *msg); +void parse_events_evlist_error (struct parse_events_evlist *data, +int idx,const char *str);void print_events (const char *event_glob,bool name_only);
tools/perf/util/record.c +2 -2
@@ -20,7 +20,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)if (!evlist)return -ENOMEM ; -if (parse_events (evlist, str)) +if (parse_events (evlist, str,NULL )) goto out_delete; evsel =perf_evlist__first (evlist);
@@ -216,7 +216,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)if (!temp_evlist)return false; - err =parse_events (temp_evlist, str); + err =parse_events (temp_evlist, str,NULL );if (err) goto out_delete;
Jiri Olsa
reviewerPATCH 2/9 perf tools: Add flex support for parse_events_error
In reply to Jiri OlsaAllowing flex parser to report back event parsing error, like:
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...--- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-events.l | 37 +++++++++++++++++++++++++++++++++---- tools/perf/util/parse-events.y | 7 ++++--- 3 files changed, 37 insertions(+), 8 deletions(-)
tools/perf/util/parse-events.h +0 -1
@@ -122,7 +122,6 @@ perf_pmu__parse_check(const char *name);void parse_events__set_leader (char *name,struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all); -void parse_events_error (void *data,void *scanner,char const *msg);void parse_events_evlist_error (struct parse_events_evlist *data,int idx,const char *str);
tools/perf/util/parse-events.l +33 -4
@@ -3,6 +3,8 @@ %option bison-bridge %option prefix="parse_events_" %option stack +%option bison-locations +%option yylineno %{ #include <errno.h>
@@ -51,6 +53,18 @@ static int str(yyscan_t scanner, int token) return token; } +#define REWIND(__alloc) \ +do { \ + YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ + char *text = parse_events_get_text(yyscanner); \ + \ + if (__alloc) \ + __yylval->str = strdup(text); \ + \ + yycolumn -= strlen(text); \ + yyless(0); \ +} while (0) + static int pmu_str_check(yyscan_t scanner) { YYSTYPE *yylval = parse_events_get_lval(scanner);
@@ -85,6 +99,13 @@ static int term(yyscan_t scanner, int type) return PE_TERM; } +#define YY_USER_ACTION \ +do { \ + yylloc->last_column = yylloc->first_column; \ + yylloc->first_column = yycolumn; \ + yycolumn += yyleng; \ +} while (0); + %} %x mem
@@ -119,6 +140,12 @@ modifier_bp [rwx]{1,3} if (start_token) { parse_events_set_extra(NULL, yyscanner); + /* + * The flex parser does not init locations variable + * via the scan_string interface, so we need do the + * init in here. + */ + yycolumn = 0; return start_token; } }
@@ -127,19 +154,21 @@ modifier_bp [rwx]{1,3} <event>{ {group} { - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(0); } {event_pmu} | {event} { - str(yyscanner, PE_EVENT_NAME); - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(1); return PE_EVENT_NAME; } . | <<EOF>> { - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(0); } }
tools/perf/util/parse-events.y +4 -3
@@ -2,6 +2,7 @@ %parse-param {void *_data} %parse-param {void *scanner} %lex-param {void* scanner} +%locations %{
@@ -14,8 +15,6 @@ #include "parse-events.h" #include "parse-events-bison.h" -extern int parse_events_lex (YYSTYPE* lvalp, void* scanner); - #define ABORT_ON(val) \ do { \ if (val) \
@@ -520,7 +519,9 @@ sep_slash_dc: '/' | ':' | %% -void parse_events_error(void *data __maybe_unused, void *scanner __maybe_unused, +void parse_events_error(YYLTYPE *loc, void *data, + void *scanner __maybe_unused, char const *msg __maybe_unused) { + parse_events_evlist_error(data, loc->last_column, "parser error"); }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add flex support for parse_events_error
perf tools: Add flex support for parse_events_error
Commit-ID: 6297d42372b6ff02135ce170b0d90ccf0b1531e4 Gitweb: http://git.kernel.org/tip/6297d42372b6ff02135ce170b0d90ccf0b1531e4 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:17 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:37:59 -0300
perf tools: Add flex support for parse_events_error
Allowing flex parser to report back event parsing error, like:
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...--- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-events.l | 37 +++++++++++++++++++++++++++++++++---- tools/perf/util/parse-events.y | 7 ++++--- 3 files changed, 37 insertions(+), 8 deletions(-)
tools/perf/util/parse-events.h +0 -1
@@ -122,7 +122,6 @@ perf_pmu__parse_check(const char *name);void parse_events__set_leader (char *name,struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all); -void parse_events_error (void *data,void *scanner,char const *msg);void parse_events_evlist_error (struct parse_events_evlist *data,int idx,const char *str);
tools/perf/util/parse-events.l +33 -4
@@ -3,6 +3,8 @@ %option bison-bridge %option prefix="parse_events_" %option stack +%option bison-locations +%option yylineno %{ #include <errno.h>
@@ -51,6 +53,18 @@ static int str(yyscan_t scanner, int token) return token; } +#define REWIND(__alloc) \ +do { \ + YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ + char *text = parse_events_get_text(yyscanner); \ + \ + if (__alloc) \ + __yylval->str = strdup(text); \ + \ + yycolumn -= strlen(text); \ + yyless(0); \ +} while (0) + static int pmu_str_check(yyscan_t scanner) { YYSTYPE *yylval = parse_events_get_lval(scanner);
@@ -85,6 +99,13 @@ static int term(yyscan_t scanner, int type) return PE_TERM; } +#define YY_USER_ACTION \ +do { \ + yylloc->last_column = yylloc->first_column; \ + yylloc->first_column = yycolumn; \ + yycolumn += yyleng; \ +} while (0); + %} %x mem
@@ -119,6 +140,12 @@ modifier_bp [rwx]{1,3} if (start_token) { parse_events_set_extra(NULL, yyscanner); + /* + * The flex parser does not init locations variable + * via the scan_string interface, so we need do the + * init in here. + */ + yycolumn = 0; return start_token; } }
@@ -127,19 +154,21 @@ modifier_bp [rwx]{1,3} <event>{ {group} { - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(0); } {event_pmu} | {event} { - str(yyscanner, PE_EVENT_NAME); - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(1); return PE_EVENT_NAME; } . | <<EOF>> { - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(0); } }
tools/perf/util/parse-events.y +4 -3
@@ -2,6 +2,7 @@ %parse-param {void *_data} %parse-param {void *scanner} %lex-param {void* scanner} +%locations %{
@@ -14,8 +15,6 @@ #include "parse-events.h" #include "parse-events-bison.h" -extern int parse_events_lex (YYSTYPE* lvalp, void* scanner); - #define ABORT_ON(val) \ do { \ if (val) \
@@ -520,7 +519,9 @@ sep_slash_dc: '/' | ':' | %% -void parse_events_error(void *data __maybe_unused, void *scanner __maybe_unused, +void parse_events_error(YYLTYPE *loc, void *data, + void *scanner __maybe_unused, char const *msg __maybe_unused) { + parse_events_evlist_error(data, loc->last_column, "parser error"); }
Jiri Olsa
reviewerPATCH 3/9 perf tools: Always bail out when config_attr function fails
In reply to Jiri OlsaNot sure why we allowed the fail state, but it's wrong. Wrong type for 'name' term can cause segfault, and there's probably more fun hidden.
--- tools/perf/util/parse-events.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +11 -4
@@ -549,6 +549,12 @@ do { \ }while (0 )switch (term->type_term) { +case PARSE_EVENTS__TERM_TYPE_USER : +/* +* Always succeed for sysfs terms, as we dont know +* at this point what type they need to have. +*/ +return 0 ;case PARSE_EVENTS__TERM_TYPE_CONFIG :CHECK_TYPE_VAL (NUM ); attr->config = term->val.num;
@@ -583,12 +589,12 @@ do { \ }static int config_attr (struct perf_event_attr *attr, -struct list_head *head,int fail) +struct list_head *head) {struct parse_events_term *term;list_for_each_entry (term, head, list) -if (config_term (attr, term) && fail) +if (config_term (attr, term))return -EINVAL ;return 0 ;
@@ -605,7 +611,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config,1 )) +config_attr (&attr, head_config))return -EINVAL ;return add_event (list, idx, &attr,NULL );
@@ -659,7 +665,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -config_attr (&attr, head_config,0 ); +if (config_attr (&attr, head_config)) +return -EINVAL ;if (perf_pmu__config (pmu, &attr, head_config))return -EINVAL ;
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Always bail out when config_attr function fails
perf tools: Always bail out when config_attr function fails
Commit-ID: c056ba6a174f4d5d79fe27f259fc133041a451da Gitweb: http://git.kernel.org/tip/c056ba6a174f4d5d79fe27f259fc133041a451da Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:18 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:37:59 -0300
perf tools: Always bail out when config_attr function fails
Not sure why we allowed the fail state, but it's wrong. Wrong type for 'name' term can cause segfault, and there's probably more fun hidden.
--- tools/perf/util/parse-events.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +11 -4
@@ -549,6 +549,12 @@ do { \ }while (0 )switch (term->type_term) { +case PARSE_EVENTS__TERM_TYPE_USER : +/* +* Always succeed for sysfs terms, as we dont know +* at this point what type they need to have. +*/ +return 0 ;case PARSE_EVENTS__TERM_TYPE_CONFIG :CHECK_TYPE_VAL (NUM ); attr->config = term->val.num;
@@ -583,12 +589,12 @@ do { \ }static int config_attr (struct perf_event_attr *attr, -struct list_head *head,int fail) +struct list_head *head) {struct parse_events_term *term;list_for_each_entry (term, head, list) -if (config_term (attr, term) && fail) +if (config_term (attr, term))return -EINVAL ;return 0 ;
@@ -605,7 +611,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config,1 )) +config_attr (&attr, head_config))return -EINVAL ;return add_event (list, idx, &attr,NULL );
@@ -659,7 +665,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -config_attr (&attr, head_config,0 ); +if (config_attr (&attr, head_config)) +return -EINVAL ;if (perf_pmu__config (pmu, &attr, head_config))return -EINVAL ;
Jiri Olsa
reviewerPATCH 4/9 perf tools: Change parse_events_add_pmu interface
In reply to Jiri OlsaChanging parse_events_add_pmu interface to allow
propagating of the parse_events_error info.
--- tools/perf/util/parse-events.c | 11 ++++++----- tools/perf/util/parse-events.h | 5 +++-- tools/perf/util/parse-events.y | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-)
tools/perf/util/parse-events.c +6 -5
@@ -633,8 +633,9 @@ static char *pmu_event_name(struct list_head *head_terms)return NULL ; } -int parse_events_add_pmu (struct list_head *list,int *idx, -char *name,struct list_head *head_config) +int parse_events_add_pmu (struct parse_events_evlist *data, +struct list_head *list,char *name, +struct list_head *head_config) {struct perf_event_attr attr;struct perf_pmu_info info;
@@ -654,7 +655,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,if (!head_config) { attr.type = pmu->type; - evsel =__add_event (list, idx, &attr,NULL , pmu->cpus); + evsel =__add_event (list, &data->idx, &attr,NULL , pmu->cpus);return evsel ?0 : -ENOMEM ; }
@@ -671,8 +672,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,if (perf_pmu__config (pmu, &attr, head_config))return -EINVAL ; - evsel =__add_event (list, idx, &attr,pmu_event_name (head_config), - pmu->cpus); + evsel =__add_event (list, &data->idx, &attr, +pmu_event_name (head_config), pmu->cpus);if (evsel) { evsel->unit = info.unit; evsel->scale = info.scale;
tools/perf/util/parse-events.h +3 -2
@@ -115,8 +115,9 @@ 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,void *ptr,char *type,u64 len); -int parse_events_add_pmu (struct list_head *list,int *idx, -char *pmu ,struct list_head *head_config); +int parse_events_add_pmu (struct parse_events_evlist *data, +struct list_head *list,char *name, +struct list_head *head_config);enum perf_pmu_event_symbol_type perf_pmu__parse_check (const char *name);void parse_events__set_leader (char *name,struct list_head *list);
tools/perf/util/parse-events.y +3 -3
@@ -207,7 +207,7 @@ PE_NAME '/' event_config '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, $3)); + ABORT_ON(parse_events_add_pmu(data, list, $1, $3)); parse_events__free_terms($3); $$ = list; }
@@ -218,7 +218,7 @@ PE_NAME '/' '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, NULL)); + ABORT_ON(parse_events_add_pmu(data, list, $1, NULL)); $$ = list; } |
@@ -235,7 +235,7 @@ PE_KERNEL_PMU_EVENT sep_dc list_add_tail(&term->list, head); ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, "cpu", head)); + ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); parse_events__free_terms(head); $$ = list; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Change parse_events_add_pmu interface
perf tools: Change parse_events_add_pmu interface
Commit-ID: 36adec85a86f2daa521cda48ea7be8a95c20ed10 Gitweb: http://git.kernel.org/tip/36adec85a86f2daa521cda48ea7be8a95c20ed10 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:19 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:00 -0300
perf tools: Change parse_events_add_pmu interface
Changing parse_events_add_pmu interface to allow propagating of the parse_events_error info.
--- tools/perf/util/parse-events.c | 11 ++++++----- tools/perf/util/parse-events.h | 5 +++-- tools/perf/util/parse-events.y | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-)
tools/perf/util/parse-events.c +6 -5
@@ -633,8 +633,9 @@ static char *pmu_event_name(struct list_head *head_terms)return NULL ; } -int parse_events_add_pmu (struct list_head *list,int *idx, -char *name,struct list_head *head_config) +int parse_events_add_pmu (struct parse_events_evlist *data, +struct list_head *list,char *name, +struct list_head *head_config) {struct perf_event_attr attr;struct perf_pmu_info info;
@@ -654,7 +655,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,if (!head_config) { attr.type = pmu->type; - evsel =__add_event (list, idx, &attr,NULL , pmu->cpus); + evsel =__add_event (list, &data->idx, &attr,NULL , pmu->cpus);return evsel ?0 : -ENOMEM ; }
@@ -671,8 +672,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,if (perf_pmu__config (pmu, &attr, head_config))return -EINVAL ; - evsel =__add_event (list, idx, &attr,pmu_event_name (head_config), - pmu->cpus); + evsel =__add_event (list, &data->idx, &attr, +pmu_event_name (head_config), pmu->cpus);if (evsel) { evsel->unit = info.unit; evsel->scale = info.scale;
tools/perf/util/parse-events.h +3 -2
@@ -115,8 +115,9 @@ 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,void *ptr,char *type,u64 len); -int parse_events_add_pmu (struct list_head *list,int *idx, -char *pmu ,struct list_head *head_config); +int parse_events_add_pmu (struct parse_events_evlist *data, +struct list_head *list,char *name, +struct list_head *head_config);enum perf_pmu_event_symbol_type perf_pmu__parse_check (const char *name);void parse_events__set_leader (char *name,struct list_head *list);
tools/perf/util/parse-events.y +3 -3
@@ -207,7 +207,7 @@ PE_NAME '/' event_config '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, $3)); + ABORT_ON(parse_events_add_pmu(data, list, $1, $3)); parse_events__free_terms($3); $$ = list; }
@@ -218,7 +218,7 @@ PE_NAME '/' '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, NULL)); + ABORT_ON(parse_events_add_pmu(data, list, $1, NULL)); $$ = list; } |
@@ -235,7 +235,7 @@ PE_KERNEL_PMU_EVENT sep_dc list_add_tail(&term->list, head); ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, "cpu", head)); + ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); parse_events__free_terms(head); $$ = list; }
Jiri Olsa
reviewerPATCH 5/9 perf tools: Add location to pmu event terms
In reply to Jiri OlsaSaving the terms location within term struct,
so it could be used later for report.
--- tools/perf/util/parse-events.c | 32 ++++++++++++++++++++++++-------- tools/perf/util/parse-events.h | 8 ++++---- tools/perf/util/parse-events.y | 16 ++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-)
tools/perf/util/parse-events.c +24 -8
@@ -25,6 +25,12 @@extern int parse_events_debug;#endif int parse_events_parse (void *data,void *scanner); +int parse_events_term__num (struct parse_events_term **term, +int type_term,char *config,u64 num, +YYLTYPE *loc_term,YYLTYPE *loc_val); +int parse_events_term__str (struct parse_events_term **term, +int type_term,char *config,char *str, +YYLTYPE *loc_term,YYLTYPE *loc_val);static struct perf_pmu_event_symbol *perf_pmu_events_list;/*
@@ -1542,7 +1548,7 @@ int parse_events__is_hardcoded_term(struct parse_events_term *term)static int new_term (struct parse_events_term **_term,int type_val,int type_term,char *config, -char *str,u64 num) +char *str,u64 num,int err_term,int err_val) {struct parse_events_term *term;
@@ -1554,6 +1560,8 @@ static int new_term(struct parse_events_term **_term, int type_val, term->type_val = type_val; term->type_term = type_term; term->config = config; + term->err_term = err_term; + term->err_val = err_val;switch (type_val) {case PARSE_EVENTS__TERM_TYPE_NUM :
@@ -1572,17 +1580,23 @@ static int new_term(struct parse_events_term **_term, int type_val, }int parse_events_term__num (struct parse_events_term **term, -int type_term,char *config,u64 num) +int type_term,char *config,u64 num, +YYLTYPE *loc_term,YYLTYPE *loc_val) {return new_term (term,PARSE_EVENTS__TERM_TYPE_NUM , type_term, - config,NULL , num); + config,NULL , num, + loc_term ? loc_term->first_column :0 , + loc_val ? loc_val->first_column :0 ); }int parse_events_term__str (struct parse_events_term **term, -int type_term,char *config,char *str) +int type_term,char *config,char *str, +YYLTYPE *loc_term,YYLTYPE *loc_val) {return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , type_term, - config, str,0 ); + config, str,0 , + loc_term ? loc_term->first_column :0 , + loc_val ? loc_val->first_column :0 ); } int parse_events_term__sym_hw(struct parse_events_term **term,
@@ -1596,18 +1610,20 @@ int parse_events_term__sym_hw(struct parse_events_term **term,if (config)return new_term (term,PARSE_EVENTS__TERM_TYPE_STR ,PARSE_EVENTS__TERM_TYPE_USER , config, - (char *) sym->symbol,0 ); + (char *) sym->symbol,0 ,0 ,0 );else return new_term (term,PARSE_EVENTS__TERM_TYPE_STR ,PARSE_EVENTS__TERM_TYPE_USER , - (char *)"event" , (char *) sym->symbol,0 ); + (char *)"event" , (char *) sym->symbol, +0 ,0 ,0 ); }int parse_events_term__clone (struct parse_events_term **new,struct parse_events_term *term) {return new_term (new, term->type_val, term->type_term, term->config, - term->val.str, term->val.num); + term->val.str, term->val.num, + term->err_term, term->err_val); }void parse_events__free_terms (struct list_head *terms)
tools/perf/util/parse-events.h +4 -4
@@ -74,6 +74,10 @@ struct parse_events_term {int type_term;struct list_head list;bool used; + +/* error string indexes for within parsed string */ +int err_term; +int err_val; };struct parse_events_error {
@@ -94,10 +98,6 @@ struct parse_events_terms { };int parse_events__is_hardcoded_term (struct parse_events_term *term); -int parse_events_term__num (struct parse_events_term **_term, -int type_term,char *config,u64 num); -int parse_events_term__str (struct parse_events_term **_term, -int type_term,char *config,char *str);int parse_events_term__sym_hw (struct parse_events_term **term,char *config,unsigned idx); int parse_events_term__clone(struct parse_events_term **new,
tools/perf/util/parse-events.y +8 -8
@@ -231,7 +231,7 @@ PE_KERNEL_PMU_EVENT sep_dc ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, &@1, NULL)); list_add_tail(&term->list, head); ALLOC_LIST(list);
@@ -251,7 +251,7 @@ PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - &pmu_name, 1)); + &pmu_name, 1, &@1, NULL)); list_add_tail(&term->list, head); ALLOC_LIST(list);
@@ -449,7 +449,7 @@ PE_NAME '=' PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, &@1, &@3)); $$ = term; } |
@@ -458,7 +458,7 @@ PE_NAME '=' PE_VALUE struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, &@1, &@3)); $$ = term; } |
@@ -476,7 +476,7 @@ PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, &@1, NULL)); $$ = term; } |
@@ -493,7 +493,7 @@ PE_TERM '=' PE_NAME { struct parse_events_term *term; - ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); $$ = term; } |
@@ -501,7 +501,7 @@ PE_TERM '=' PE_VALUE { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3)); $$ = term; } |
@@ -509,7 +509,7 @@ PE_TERM { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1)); + ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL)); $$ = term; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add location to pmu event terms
perf tools: Add location to pmu event terms
Commit-ID: cecf3a2e185c1d843428166d644ba3b564231293 Gitweb: http://git.kernel.org/tip/cecf3a2e185c1d843428166d644ba3b564231293 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:20 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:00 -0300
perf tools: Add location to pmu event terms
Saving the terms location within term struct, so it could be used later for report.
--- tools/perf/util/parse-events.c | 32 ++++++++++++++++++++++++-------- tools/perf/util/parse-events.h | 8 ++++---- tools/perf/util/parse-events.y | 16 ++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-)
tools/perf/util/parse-events.c +24 -8
@@ -25,6 +25,12 @@extern int parse_events_debug;#endif int parse_events_parse (void *data,void *scanner); +int parse_events_term__num (struct parse_events_term **term, +int type_term,char *config,u64 num, +YYLTYPE *loc_term,YYLTYPE *loc_val); +int parse_events_term__str (struct parse_events_term **term, +int type_term,char *config,char *str, +YYLTYPE *loc_term,YYLTYPE *loc_val);static struct perf_pmu_event_symbol *perf_pmu_events_list;/*
@@ -1542,7 +1548,7 @@ int parse_events__is_hardcoded_term(struct parse_events_term *term)static int new_term (struct parse_events_term **_term,int type_val,int type_term,char *config, -char *str,u64 num) +char *str,u64 num,int err_term,int err_val) {struct parse_events_term *term;
@@ -1554,6 +1560,8 @@ static int new_term(struct parse_events_term **_term, int type_val, term->type_val = type_val; term->type_term = type_term; term->config = config; + term->err_term = err_term; + term->err_val = err_val;switch (type_val) {case PARSE_EVENTS__TERM_TYPE_NUM :
@@ -1572,17 +1580,23 @@ static int new_term(struct parse_events_term **_term, int type_val, }int parse_events_term__num (struct parse_events_term **term, -int type_term,char *config,u64 num) +int type_term,char *config,u64 num, +YYLTYPE *loc_term,YYLTYPE *loc_val) {return new_term (term,PARSE_EVENTS__TERM_TYPE_NUM , type_term, - config,NULL , num); + config,NULL , num, + loc_term ? loc_term->first_column :0 , + loc_val ? loc_val->first_column :0 ); }int parse_events_term__str (struct parse_events_term **term, -int type_term,char *config,char *str) +int type_term,char *config,char *str, +YYLTYPE *loc_term,YYLTYPE *loc_val) {return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , type_term, - config, str,0 ); + config, str,0 , + loc_term ? loc_term->first_column :0 , + loc_val ? loc_val->first_column :0 ); } int parse_events_term__sym_hw(struct parse_events_term **term,
@@ -1596,18 +1610,20 @@ int parse_events_term__sym_hw(struct parse_events_term **term,if (config)return new_term (term,PARSE_EVENTS__TERM_TYPE_STR ,PARSE_EVENTS__TERM_TYPE_USER , config, - (char *) sym->symbol,0 ); + (char *) sym->symbol,0 ,0 ,0 );else return new_term (term,PARSE_EVENTS__TERM_TYPE_STR ,PARSE_EVENTS__TERM_TYPE_USER , - (char *)"event" , (char *) sym->symbol,0 ); + (char *)"event" , (char *) sym->symbol, +0 ,0 ,0 ); }int parse_events_term__clone (struct parse_events_term **new,struct parse_events_term *term) {return new_term (new, term->type_val, term->type_term, term->config, - term->val.str, term->val.num); + term->val.str, term->val.num, + term->err_term, term->err_val); }void parse_events__free_terms (struct list_head *terms)
tools/perf/util/parse-events.h +4 -4
@@ -74,6 +74,10 @@ struct parse_events_term {int type_term;struct list_head list;bool used; + +/* error string indexes for within parsed string */ +int err_term; +int err_val; };struct parse_events_error {
@@ -94,10 +98,6 @@ struct parse_events_terms { };int parse_events__is_hardcoded_term (struct parse_events_term *term); -int parse_events_term__num (struct parse_events_term **_term, -int type_term,char *config,u64 num); -int parse_events_term__str (struct parse_events_term **_term, -int type_term,char *config,char *str);int parse_events_term__sym_hw (struct parse_events_term **term,char *config,unsigned idx); int parse_events_term__clone(struct parse_events_term **new,
tools/perf/util/parse-events.y +8 -8
@@ -231,7 +231,7 @@ PE_KERNEL_PMU_EVENT sep_dc ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, &@1, NULL)); list_add_tail(&term->list, head); ALLOC_LIST(list);
@@ -251,7 +251,7 @@ PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - &pmu_name, 1)); + &pmu_name, 1, &@1, NULL)); list_add_tail(&term->list, head); ALLOC_LIST(list);
@@ -449,7 +449,7 @@ PE_NAME '=' PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, &@1, &@3)); $$ = term; } |
@@ -458,7 +458,7 @@ PE_NAME '=' PE_VALUE struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, &@1, &@3)); $$ = term; } |
@@ -476,7 +476,7 @@ PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, &@1, NULL)); $$ = term; } |
@@ -493,7 +493,7 @@ PE_TERM '=' PE_NAME { struct parse_events_term *term; - ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); $$ = term; } |
@@ -501,7 +501,7 @@ PE_TERM '=' PE_VALUE { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3)); $$ = term; } |
@@ -509,7 +509,7 @@ PE_TERM { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1)); + ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL)); $$ = term; }
Jiri Olsa
reviewerPATCH 6/9 perf tools: Add term support for parse_events_error
In reply to Jiri OlsaAllowing event's term processing to report back error, like:
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown termvalid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
--- tools/perf/tests/pmu.c | 3 ++- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.l | 4 +++ tools/perf/util/pmu.c | 57 +++++++++++++++++++++++++++++++++++++----- tools/perf/util/pmu.h | 6 +++-- 5 files changed, 62 insertions(+), 10 deletions(-)
tools/perf/tests/pmu.c +2 -1
@@ -152,7 +152,8 @@ int test__pmu(void)if (ret)break ; - ret =perf_pmu__config_terms (&formats, &attr, terms, false); + ret =perf_pmu__config_terms (&formats, &attr, terms, + false,NULL );if (ret)break ;
tools/perf/util/parse-events.c +1 -1
@@ -675,7 +675,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,if (config_attr (&attr, head_config))return -EINVAL ; -if (perf_pmu__config (pmu, &attr, head_config)) +if (perf_pmu__config (pmu, &attr, head_config, data->error))return -EINVAL ; evsel = __add_event(list, &data->idx, &attr,
tools/perf/util/parse-events.l +4 -0
@@ -174,6 +174,10 @@ modifier_bp [rwx]{1,3} } <config>{ + /* + * Please update formats_error_string any time + * new static term is added. + */ config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
tools/perf/util/pmu.c +51 -6
103 lines not on this page · raw message
tools/perf/util/pmu.h +4 -2
@@ -4,6 +4,7 @@#include <linux/bitmap.h> #include <linux/perf_event.h> #include <stdbool.h> +#include "parse-events.h" enum {PERF_PMU_FORMAT_VALUE_CONFIG ,
@@ -47,11 +48,12 @@ struct perf_pmu_alias {struct perf_pmu *perf_pmu__find (const char *name);int perf_pmu__config (struct perf_pmu *pmu,struct perf_event_attr *attr, -struct list_head *head_terms); +struct list_head *head_terms, +struct parse_events_error *error);int perf_pmu__config_terms (struct list_head *formats,struct perf_event_attr *attr,struct list_head *head_terms, -bool zero); +bool zero,struct parse_events_error *error);int perf_pmu__check_alias (struct perf_pmu *pmu,struct list_head *head_terms,struct perf_pmu_info *info); struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add term support for parse_events_error
perf tools: Add term support for parse_events_error
Commit-ID: e64b020ba1adfd081a26c5a35a2990f91da043a0 Gitweb: http://git.kernel.org/tip/e64b020ba1adfd081a26c5a35a2990f91da043a0 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:21 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:01 -0300
perf tools: Add term support for parse_events_error
Allowing event's term processing to report back error, like:
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown termvalid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
--- tools/perf/tests/pmu.c | 3 ++- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.l | 4 +++ tools/perf/util/pmu.c | 57 +++++++++++++++++++++++++++++++++++++----- tools/perf/util/pmu.h | 6 +++-- 5 files changed, 62 insertions(+), 10 deletions(-)
tools/perf/tests/pmu.c +2 -1
@@ -152,7 +152,8 @@ int test__pmu(void)if (ret)break ; - ret =perf_pmu__config_terms (&formats, &attr, terms, false); + ret =perf_pmu__config_terms (&formats, &attr, terms, + false,NULL );if (ret)break ;
tools/perf/util/parse-events.c +1 -1
@@ -675,7 +675,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,if (config_attr (&attr, head_config))return -EINVAL ; -if (perf_pmu__config (pmu, &attr, head_config)) +if (perf_pmu__config (pmu, &attr, head_config, data->error))return -EINVAL ; evsel = __add_event(list, &data->idx, &attr,
tools/perf/util/parse-events.l +4 -0
@@ -174,6 +174,10 @@ modifier_bp [rwx]{1,3} } <config>{ + /* + * Please update formats_error_string any time + * new static term is added. + */ config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
tools/perf/util/pmu.c +51 -6
103 lines not on this page · raw message
tools/perf/util/pmu.h +4 -2
@@ -4,6 +4,7 @@#include <linux/bitmap.h> #include <linux/perf_event.h> #include <stdbool.h> +#include "parse-events.h" enum {PERF_PMU_FORMAT_VALUE_CONFIG ,
@@ -47,11 +48,12 @@ struct perf_pmu_alias {struct perf_pmu *perf_pmu__find (const char *name);int perf_pmu__config (struct perf_pmu *pmu,struct perf_event_attr *attr, -struct list_head *head_terms); +struct list_head *head_terms, +struct parse_events_error *error);int perf_pmu__config_terms (struct list_head *formats,struct perf_event_attr *attr,struct list_head *head_terms, -bool zero); +bool zero,struct parse_events_error *error);int perf_pmu__check_alias (struct perf_pmu *pmu,struct list_head *head_terms,struct perf_pmu_info *info); struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
Jiri Olsa
reviewerPATCH 7/9 perf tools: Add static terms support for parse_events_error
In reply to Jiri OlsaAllowing static terms like 'name,period,config,config1..' processing to report back error.
$ perf record -e 'cpu/event=1,name=1/' ls
event syntax error: '..=1,name=1/'
\___ expected string value $ perf record -e 'cpu/event=1,period=krava/' ls
event syntax error: '..,period=krava/'
\___ expected numeric value $ perf record -e 'cpu/config=krava1/' ls
event syntax error: '../config=krava1/'
\___ expected numeric value--- tools/perf/util/parse-events.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
tools/perf/util/parse-events.c +28 -9
@@ -545,13 +545,31 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,return add_event (list, idx, &attr,NULL ); } +static int check_type_val (struct parse_events_term *term, +struct parse_events_error *error, +int type) +{ +if (type == term->type_val) +return 0 ; + +if (error) { + error->idx = term->err_val; +if (type ==PARSE_EVENTS__TERM_TYPE_NUM ) + error->str =strdup ("expected numeric value" ); +else + error->str =strdup ("expected string value" ); + } +return -EINVAL ; +} +static int config_term (struct perf_event_attr *attr, -struct parse_events_term *term) +struct parse_events_term *term, +struct parse_events_error *error) { -#define CHECK_TYPE_VAL (type) \ -do { \ - if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \ - return -EINVAL; \ +#define CHECK_TYPE_VAL (type) \ +do { \ + if (check_type_val(term, error, PARSE_EVENTS__TERM_TYPE_ ## type)) \ + return -EINVAL; \ } while (0)switch (term->type_term) {
@@ -595,12 +613,13 @@ do { \ }static int config_attr (struct perf_event_attr *attr, -struct list_head *head) +struct list_head *head, +struct parse_events_error *error) {struct parse_events_term *term;list_for_each_entry (term, head, list) -if (config_term (attr, term)) +if (config_term (attr, term, error))return -EINVAL ;return 0 ;
@@ -617,7 +636,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config)) +config_attr (&attr, head_config,NULL ))return -EINVAL ;return add_event (list, idx, &attr,NULL );
@@ -672,7 +691,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -if (config_attr (&attr, head_config)) +if (config_attr (&attr, head_config, data->error))return -EINVAL ;if (perf_pmu__config (pmu, &attr, head_config, data->error))
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add static terms support for parse_events_error
perf tools: Add static terms support for parse_events_error
Commit-ID: 3b0e371cc05dfb624f990ea5e1da2bff615adaef Gitweb: http://git.kernel.org/tip/3b0e371cc05dfb624f990ea5e1da2bff615adaef Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:22 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:01 -0300
perf tools: Add static terms support for parse_events_error
Allowing static terms like 'name,period,config,config1..' processing to report back error.
$ perf record -e 'cpu/event=1,name=1/' ls
event syntax error: '..=1,name=1/'
\___ expected string value $ perf record -e 'cpu/event=1,period=krava/' ls
event syntax error: '..,period=krava/'
\___ expected numeric value $ perf record -e 'cpu/config=krava1/' ls
event syntax error: '../config=krava1/'
\___ expected numeric value--- tools/perf/util/parse-events.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
tools/perf/util/parse-events.c +28 -9
@@ -545,13 +545,31 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,return add_event (list, idx, &attr,NULL ); } +static int check_type_val (struct parse_events_term *term, +struct parse_events_error *err, +int type) +{ +if (type == term->type_val) +return 0 ; + +if (err) { + err->idx = term->err_val; +if (type ==PARSE_EVENTS__TERM_TYPE_NUM ) + err->str =strdup ("expected numeric value" ); +else + err->str =strdup ("expected string value" ); + } +return -EINVAL ; +} +static int config_term (struct perf_event_attr *attr, -struct parse_events_term *term) +struct parse_events_term *term, +struct parse_events_error *err) { -#define CHECK_TYPE_VAL (type) \ -do { \ - if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \ - return -EINVAL; \ +#define CHECK_TYPE_VAL (type) \ +do { \ + if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \ + return -EINVAL; \ } while (0)switch (term->type_term) {
@@ -595,12 +613,13 @@ do { \ }static int config_attr (struct perf_event_attr *attr, -struct list_head *head) +struct list_head *head, +struct parse_events_error *err) {struct parse_events_term *term;list_for_each_entry (term, head, list) -if (config_term (attr, term)) +if (config_term (attr, term, err))return -EINVAL ;return 0 ;
@@ -617,7 +636,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config)) +config_attr (&attr, head_config,NULL ))return -EINVAL ;return add_event (list, idx, &attr,NULL );
@@ -672,7 +691,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -if (config_attr (&attr, head_config)) +if (config_attr (&attr, head_config, data->error))return -EINVAL ;if (perf_pmu__config (pmu, &attr, head_config, data->error))
Jiri Olsa
reviewerPATCH 8/9 perf tools: Add tracepoint support for parse_events_error
In reply to Jiri OlsaAllowing tracepoint events processing to report back error.
$ perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...--- tools/perf/util/parse-events.y | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.y +7 -1
@@ -388,7 +388,13 @@ PE_NAME ':' PE_NAME struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_tracepoint(list, &data->idx, $1, $3)); + if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) { + struct parse_events_error *error = data->error; + + error->idx = @1.first_column; + error->str = strdup("unknown tracepoint"); + return -1; + } $$ = list; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add tracepoint support for parse_events_error
perf tools: Add tracepoint support for parse_events_error
Commit-ID: 492d977444734e03c0633a238f1431b3c66b3e97 Gitweb: http://git.kernel.org/tip/492d977444734e03c0633a238f1431b3c66b3e97 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:23 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:01 -0300
perf tools: Add tracepoint support for parse_events_error
Allowing tracepoint events processing to report back error.
$ perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...--- tools/perf/util/parse-events.y | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.y +7 -1
@@ -388,7 +388,13 @@ PE_NAME ':' PE_NAME struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_tracepoint(list, &data->idx, $1, $3)); + if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) { + struct parse_events_error *error = data->error; + + error->idx = @1.first_column; + error->str = strdup("unknown tracepoint"); + return -1; + } $$ = list; }
Jiri Olsa
reviewerPATCH 9/9 perf tools: Add symbolic events support for parse_events_error
In reply to Jiri OlsaAllowing symbolic events processing to report back error.
$ perf record -e 'cycles/period=krava/' ls
event syntax error: '../period=krava/'
\___ expected numeric value $ perf record -e 'cycles/name=1/' ls
event syntax error: '..es/name=1/'
\___ expected string value--- tools/perf/util/parse-events.c | 7 ++++--- tools/perf/util/parse-events.h | 3 ++- tools/perf/util/parse-events.y | 11 ++++------- 3 files changed, 10 insertions(+), 11 deletions(-)
tools/perf/util/parse-events.c +4 -3
@@ -625,7 +625,8 @@ static int config_attr(struct perf_event_attr *attr,return 0 ; } -int parse_events_add_numeric (struct list_head *list,int *idx, +int parse_events_add_numeric (struct parse_events_evlist *data, +struct list_head *list,u32 type,u64 config,struct list_head *head_config) {
@@ -636,10 +637,10 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config,NULL )) +config_attr (&attr, head_config, data->error))return -EINVAL ; -return add_event (list, idx, &attr,NULL ); +return add_event (list, &data->idx, &attr,NULL ); }static int parse_events__is_name_term (struct parse_events_term *term)
tools/perf/util/parse-events.h +2 -1
@@ -108,7 +108,8 @@ int parse_events__modifier_group(struct list_head *list, char *event_mod);int parse_events_name (struct list_head *list,char *name);int parse_events_add_tracepoint (struct list_head *list,int *idx,char *sys,char *event); -int parse_events_add_numeric (struct list_head *list,int *idx, +int parse_events_add_numeric (struct parse_events_evlist *data, +struct list_head *list,u32 type,u64 config,struct list_head *head_config); int parse_events_add_cache(struct list_head *list, int *idx,
tools/perf/util/parse-events.y +4 -7
@@ -274,8 +274,7 @@ value_sym '/' event_config '/' int config = $1 & 255; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - type, config, $3)); + ABORT_ON(parse_events_add_numeric(data, list, type, config, $3)); parse_events__free_terms($3); $$ = list; }
@@ -288,8 +287,7 @@ value_sym sep_slash_dc int config = $1 & 255; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - type, config, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL)); $$ = list; }
@@ -405,7 +403,7 @@ PE_VALUE ':' PE_VALUE struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, (u32)$1, $3, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, NULL)); $$ = list; }
@@ -416,8 +414,7 @@ PE_RAW struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - PERF_TYPE_RAW, $1, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, NULL)); $$ = list; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add symbolic events support for parse_events_error
perf tools: Add symbolic events support for parse_events_error
Commit-ID: 87d650be1dcc9bd9bb200e73b985ddb740d067bc Gitweb: http://git.kernel.org/tip/87d650be1dcc9bd9bb200e73b985ddb740d067bc Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 22 Apr 2015 21:10:24 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:02 -0300
perf tools: Add symbolic events support for parse_events_error
Allowing symbolic events processing to report back error.
$ perf record -e 'cycles/period=krava/' ls
event syntax error: '../period=krava/'
\___ expected numeric value $ perf record -e 'cycles/name=1/' ls
event syntax error: '..es/name=1/'
\___ expected string value--- tools/perf/util/parse-events.c | 7 ++++--- tools/perf/util/parse-events.h | 3 ++- tools/perf/util/parse-events.y | 11 ++++------- 3 files changed, 10 insertions(+), 11 deletions(-)
tools/perf/util/parse-events.c +4 -3
@@ -625,7 +625,8 @@ static int config_attr(struct perf_event_attr *attr,return 0 ; } -int parse_events_add_numeric (struct list_head *list,int *idx, +int parse_events_add_numeric (struct parse_events_evlist *data, +struct list_head *list,u32 type,u64 config,struct list_head *head_config) {
@@ -636,10 +637,10 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config,NULL )) +config_attr (&attr, head_config, data->error))return -EINVAL ; -return add_event (list, idx, &attr,NULL ); +return add_event (list, &data->idx, &attr,NULL ); }static int parse_events__is_name_term (struct parse_events_term *term)
tools/perf/util/parse-events.h +2 -1
@@ -108,7 +108,8 @@ int parse_events__modifier_group(struct list_head *list, char *event_mod);int parse_events_name (struct list_head *list,char *name);int parse_events_add_tracepoint (struct list_head *list,int *idx,char *sys,char *event); -int parse_events_add_numeric (struct list_head *list,int *idx, +int parse_events_add_numeric (struct parse_events_evlist *data, +struct list_head *list,u32 type,u64 config,struct list_head *head_config); int parse_events_add_cache(struct list_head *list, int *idx,
tools/perf/util/parse-events.y +4 -7
@@ -274,8 +274,7 @@ value_sym '/' event_config '/' int config = $1 & 255; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - type, config, $3)); + ABORT_ON(parse_events_add_numeric(data, list, type, config, $3)); parse_events__free_terms($3); $$ = list; }
@@ -288,8 +287,7 @@ value_sym sep_slash_dc int config = $1 & 255; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - type, config, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL)); $$ = list; }
@@ -405,7 +403,7 @@ PE_VALUE ':' PE_VALUE struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, (u32)$1, $3, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, NULL)); $$ = list; }
@@ -416,8 +414,7 @@ PE_RAW struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - PERF_TYPE_RAW, $1, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, NULL)); $$ = list; }
Arnaldo Carvalho de Melo
maintainerEm Wed, Apr 22, 2015 at 09:10:15PM +0200, Jiri Olsa escreveu:
Quoted 8 lines
hi,
adding support to report error from event string parsing.v1 changes (from RFC):
- display list of allowed terms for pmu event error [Ingo]
- changing 'invalid or unsupported event' string into 'event syntax error' for cases we know the precise error
Quoted 8 lines
This patchset contains support for standard parsing errors and more logic to recognize tracepoint and 'pmu//' terms, like:
$ sudo perf record -e 'sched:krava' ls event syntax error: 'sched:krava' \___ unknown tracepoint ...
Thanks, applied and tested each of these patches.
- Arnaldo