Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 2 | %option reentrant |
| 3 | %option bison-bridge |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 4 | %option prefix="parse_events_" |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 5 | %option stack |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 6 | %option bison-locations |
| 7 | %option yylineno |
Jiri Olsa | b6af53b | 2017-11-08 16:43:09 +0100 | [diff] [blame] | 8 | %option reject |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 9 | |
| 10 | %{ |
| 11 | #include <errno.h> |
Jiri Olsa | 29479bf | 2017-10-13 10:37:35 +0200 | [diff] [blame] | 12 | #include <sys/types.h> |
| 13 | #include <sys/stat.h> |
| 14 | #include <unistd.h> |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 15 | #include "parse-events.h" |
Wang Nan | e571e02 | 2016-02-22 09:10:35 +0000 | [diff] [blame] | 16 | #include "parse-events-bison.h" |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 17 | #include "evsel.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 18 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 19 | char *parse_events_get_text(yyscan_t yyscanner); |
| 20 | YYSTYPE *parse_events_get_lval(yyscan_t yyscanner); |
| 21 | |
| 22 | static int __value(YYSTYPE *yylval, char *str, int base, int token) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 23 | { |
Robert Richter | b527bab | 2012-08-07 19:43:13 +0200 | [diff] [blame] | 24 | u64 num; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 25 | |
| 26 | errno = 0; |
Robert Richter | b527bab | 2012-08-07 19:43:13 +0200 | [diff] [blame] | 27 | num = strtoull(str, NULL, base); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 28 | if (errno) |
| 29 | return PE_ERROR; |
| 30 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 31 | yylval->num = num; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 32 | return token; |
| 33 | } |
| 34 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 35 | static int value(yyscan_t scanner, int base) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 36 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 37 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 38 | char *text = parse_events_get_text(scanner); |
| 39 | |
| 40 | return __value(yylval, text, base, PE_VALUE); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 41 | } |
| 42 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 43 | static int str(yyscan_t scanner, int token) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 44 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 45 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 46 | char *text = parse_events_get_text(scanner); |
| 47 | |
Alexey Budankov | f92da71 | 2018-06-04 09:50:56 +0300 | [diff] [blame] | 48 | if (text[0] != '\'') { |
| 49 | yylval->str = strdup(text); |
| 50 | } else { |
| 51 | /* |
| 52 | * If a text tag specified on the command line |
| 53 | * contains opening single quite ' then it is |
| 54 | * expected that the tag ends with single quote |
| 55 | * as well, like this: |
| 56 | * name=\'CPU_CLK_UNHALTED.THREAD:cmask=1\' |
| 57 | * quotes need to be escaped to bypass shell |
| 58 | * processing. |
| 59 | */ |
| 60 | yylval->str = strndup(&text[1], strlen(text) - 2); |
| 61 | } |
| 62 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 63 | return token; |
| 64 | } |
| 65 | |
Jiri Olsa | 4929e95 | 2020-07-26 09:52:44 +0200 | [diff] [blame] | 66 | static int raw(yyscan_t scanner) |
| 67 | { |
| 68 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 69 | char *text = parse_events_get_text(scanner); |
| 70 | |
| 71 | if (perf_pmu__parse_check(text) == PMU_EVENT_SYMBOL) |
| 72 | return str(scanner, PE_NAME); |
| 73 | |
| 74 | return __value(yylval, text + 1, 16, PE_RAW); |
| 75 | } |
| 76 | |
Jiri Olsa | 29479bf | 2017-10-13 10:37:35 +0200 | [diff] [blame] | 77 | static bool isbpf_suffix(char *text) |
Andi Kleen | 77d0871 | 2017-08-11 16:26:19 -0700 | [diff] [blame] | 78 | { |
Andi Kleen | 77d0871 | 2017-08-11 16:26:19 -0700 | [diff] [blame] | 79 | int len = strlen(text); |
| 80 | |
| 81 | if (len < 2) |
| 82 | return false; |
| 83 | if ((text[len - 1] == 'c' || text[len - 1] == 'o') && |
| 84 | text[len - 2] == '.') |
| 85 | return true; |
| 86 | if (len > 4 && !strcmp(text + len - 4, ".obj")) |
| 87 | return true; |
| 88 | return false; |
| 89 | } |
| 90 | |
Jiri Olsa | 29479bf | 2017-10-13 10:37:35 +0200 | [diff] [blame] | 91 | static bool isbpf(yyscan_t scanner) |
| 92 | { |
| 93 | char *text = parse_events_get_text(scanner); |
| 94 | struct stat st; |
| 95 | |
| 96 | if (!isbpf_suffix(text)) |
| 97 | return false; |
| 98 | |
| 99 | return stat(text, &st) == 0; |
| 100 | } |
| 101 | |
Mathieu Poirier | dd60fba | 2016-09-06 10:37:15 -0600 | [diff] [blame] | 102 | /* |
| 103 | * This function is called when the parser gets two kind of input: |
| 104 | * |
| 105 | * @cfg1 or @cfg2=config |
| 106 | * |
| 107 | * The leading '@' is stripped off before 'cfg1' and 'cfg2=config' are given to |
| 108 | * bison. In the latter case it is necessary to keep the string intact so that |
| 109 | * the PMU kernel driver can determine what configurable is associated to |
| 110 | * 'config'. |
| 111 | */ |
| 112 | static int drv_str(yyscan_t scanner, int token) |
| 113 | { |
| 114 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 115 | char *text = parse_events_get_text(scanner); |
| 116 | |
| 117 | /* Strip off the '@' */ |
| 118 | yylval->str = strdup(text + 1); |
| 119 | return token; |
| 120 | } |
| 121 | |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 122 | #define REWIND(__alloc) \ |
| 123 | do { \ |
| 124 | YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ |
| 125 | char *text = parse_events_get_text(yyscanner); \ |
| 126 | \ |
| 127 | if (__alloc) \ |
| 128 | __yylval->str = strdup(text); \ |
| 129 | \ |
| 130 | yycolumn -= strlen(text); \ |
| 131 | yyless(0); \ |
| 132 | } while (0) |
| 133 | |
Jiri Olsa | 387ad33 | 2020-06-02 23:47:29 +0200 | [diff] [blame] | 134 | static int pmu_str_check(yyscan_t scanner, struct parse_events_state *parse_state) |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 135 | { |
| 136 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 137 | char *text = parse_events_get_text(scanner); |
| 138 | |
| 139 | yylval->str = strdup(text); |
Jiri Olsa | 387ad33 | 2020-06-02 23:47:29 +0200 | [diff] [blame] | 140 | |
Ian Rogers | ec5c5b3 | 2021-10-15 10:21:27 -0700 | [diff] [blame] | 141 | /* |
| 142 | * If we're not testing then parse check determines the PMU event type |
| 143 | * which if it isn't a PMU returns PE_NAME. When testing the result of |
| 144 | * parse check can't be trusted so we return PE_PMU_EVENT_FAKE unless |
| 145 | * an '!' is present in which case the text can't be a PMU name. |
| 146 | */ |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 147 | switch (perf_pmu__parse_check(text)) { |
| 148 | case PMU_EVENT_SYMBOL_PREFIX: |
| 149 | return PE_PMU_EVENT_PRE; |
| 150 | case PMU_EVENT_SYMBOL_SUFFIX: |
| 151 | return PE_PMU_EVENT_SUF; |
John Garry | 864bc8c | 2022-01-17 23:10:13 +0800 | [diff] [blame] | 152 | case PMU_EVENT_SYMBOL_SUFFIX2: |
| 153 | return PE_PMU_EVENT_SUF2; |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 154 | case PMU_EVENT_SYMBOL: |
Ian Rogers | ec5c5b3 | 2021-10-15 10:21:27 -0700 | [diff] [blame] | 155 | return parse_state->fake_pmu |
| 156 | ? PE_PMU_EVENT_FAKE : PE_KERNEL_PMU_EVENT; |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 157 | default: |
Ian Rogers | ec5c5b3 | 2021-10-15 10:21:27 -0700 | [diff] [blame] | 158 | return parse_state->fake_pmu && !strchr(text,'!') |
| 159 | ? PE_PMU_EVENT_FAKE : PE_NAME; |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 163 | static int sym(yyscan_t scanner, int type, int config) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 164 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 165 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 166 | |
| 167 | yylval->num = (type << 16) + config; |
Jiri Olsa | cf3506d | 2012-07-04 00:00:43 +0200 | [diff] [blame] | 168 | return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 171 | static int tool(yyscan_t scanner, enum perf_tool_event event) |
| 172 | { |
| 173 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 174 | |
| 175 | yylval->num = event; |
| 176 | return PE_VALUE_SYM_TOOL; |
| 177 | } |
| 178 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 179 | static int term(yyscan_t scanner, int type) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 180 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 181 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 182 | |
| 183 | yylval->num = type; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 184 | return PE_TERM; |
| 185 | } |
| 186 | |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 187 | #define YY_USER_ACTION \ |
| 188 | do { \ |
| 189 | yylloc->last_column = yylloc->first_column; \ |
| 190 | yylloc->first_column = yycolumn; \ |
| 191 | yycolumn += yyleng; \ |
| 192 | } while (0); |
| 193 | |
Jiri Olsa | 9445464 | 2017-10-12 17:03:38 +0200 | [diff] [blame] | 194 | #define USER_REJECT \ |
| 195 | yycolumn -= yyleng; \ |
| 196 | REJECT |
| 197 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 198 | %} |
| 199 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 200 | %x mem |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 201 | %s config |
| 202 | %x event |
Wang Nan | e571e02 | 2016-02-22 09:10:35 +0000 | [diff] [blame] | 203 | %x array |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 204 | |
| 205 | group [^,{}/]*[{][^}]*[}][^,{}/]* |
| 206 | event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* |
| 207 | event [^,{}/]+ |
Andi Kleen | 77d0871 | 2017-08-11 16:26:19 -0700 | [diff] [blame] | 208 | bpf_object [^,{}]+\.(o|bpf)[a-zA-Z0-9._]* |
| 209 | bpf_source [^,{}]+\.c[a-zA-Z0-9._]* |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 210 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 211 | num_dec [0-9]+ |
| 212 | num_hex 0x[a-fA-F0-9]+ |
| 213 | num_raw_hex [a-fA-F0-9]+ |
Ian Rogers | ec5c5b3 | 2021-10-15 10:21:27 -0700 | [diff] [blame] | 214 | name [a-zA-Z_*?\[\]][a-zA-Z0-9_*?.\[\]!]* |
Alexey Budankov | f92da71 | 2018-06-04 09:50:56 +0300 | [diff] [blame] | 215 | name_tag [\'][a-zA-Z_*?\[\]][a-zA-Z0-9_*?\-,\.\[\]:=]*[\'] |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 216 | name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* |
Mathieu Poirier | dd60fba | 2016-09-06 10:37:15 -0600 | [diff] [blame] | 217 | drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 218 | /* If you add a modifier you need to update check_modifier() */ |
Song Liu | 01bd8efc | 2021-04-25 14:43:32 -0700 | [diff] [blame] | 219 | modifier_event [ukhpPGHSDIWeb]+ |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 220 | modifier_bp [rwx]{1,3} |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 221 | |
| 222 | %% |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 223 | |
| 224 | %{ |
Jiri Olsa | 1244a32 | 2020-05-25 00:42:08 +0200 | [diff] [blame] | 225 | struct parse_events_state *_parse_state = parse_events_get_extra(yyscanner); |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 226 | |
Jiri Olsa | 1244a32 | 2020-05-25 00:42:08 +0200 | [diff] [blame] | 227 | { |
| 228 | int start_token = _parse_state->stoken; |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 229 | |
| 230 | if (start_token == PE_START_TERMS) |
| 231 | BEGIN(config); |
| 232 | else if (start_token == PE_START_EVENTS) |
| 233 | BEGIN(event); |
| 234 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 235 | if (start_token) { |
Jiri Olsa | 1244a32 | 2020-05-25 00:42:08 +0200 | [diff] [blame] | 236 | _parse_state->stoken = 0; |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 237 | /* |
| 238 | * The flex parser does not init locations variable |
| 239 | * via the scan_string interface, so we need do the |
| 240 | * init in here. |
| 241 | */ |
| 242 | yycolumn = 0; |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 243 | return start_token; |
| 244 | } |
| 245 | } |
| 246 | %} |
| 247 | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 248 | <event>{ |
| 249 | |
| 250 | {group} { |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 251 | BEGIN(INITIAL); |
| 252 | REWIND(0); |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | {event_pmu} | |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 256 | {bpf_object} | |
Wang Nan | d509db0 | 2015-10-14 12:41:20 +0000 | [diff] [blame] | 257 | {bpf_source} | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 258 | {event} { |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 259 | BEGIN(INITIAL); |
| 260 | REWIND(1); |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 261 | return PE_EVENT_NAME; |
| 262 | } |
| 263 | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 264 | <<EOF>> { |
Jiri Olsa | 6297d42 | 2015-04-22 21:10:17 +0200 | [diff] [blame] | 265 | BEGIN(INITIAL); |
| 266 | REWIND(0); |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 267 | } |
Jiri Olsa | ae76264 | 2020-05-20 09:40:50 +0200 | [diff] [blame] | 268 | , { |
| 269 | return ','; |
| 270 | } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Wang Nan | e571e02 | 2016-02-22 09:10:35 +0000 | [diff] [blame] | 273 | <array>{ |
| 274 | "]" { BEGIN(config); return ']'; } |
| 275 | {num_dec} { return value(yyscanner, 10); } |
| 276 | {num_hex} { return value(yyscanner, 16); } |
| 277 | , { return ','; } |
| 278 | "\.\.\." { return PE_ARRAY_RANGE; } |
| 279 | } |
| 280 | |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 281 | <config>{ |
Jiri Olsa | e64b020 | 2015-04-22 21:10:21 +0200 | [diff] [blame] | 282 | /* |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 283 | * Please update config_term_names when new static term is added. |
Jiri Olsa | e64b020 | 2015-04-22 21:10:21 +0200 | [diff] [blame] | 284 | */ |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 285 | config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } |
| 286 | config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } |
| 287 | config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); } |
| 288 | name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); } |
| 289 | period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } |
Namhyung Kim | 09af2a5 | 2015-08-09 15:45:23 +0900 | [diff] [blame] | 290 | freq { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ); } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 291 | branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } |
Kan Liang | 3206771 | 2015-08-04 04:30:19 -0400 | [diff] [blame] | 292 | time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); } |
Kan Liang | d457c96 | 2015-08-11 06:30:47 -0400 | [diff] [blame] | 293 | call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); } |
| 294 | stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); } |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 295 | max-stack { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_MAX_STACK); } |
Arnaldo Carvalho de Melo | 2fda5ad | 2018-10-19 15:47:34 -0300 | [diff] [blame] | 296 | nr { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_MAX_EVENTS); } |
Wang Nan | 374ce93 | 2015-10-28 10:55:02 +0000 | [diff] [blame] | 297 | inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); } |
| 298 | no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); } |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 299 | overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); } |
| 300 | no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); } |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 301 | percore { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_PERCORE); } |
Adrian Hunter | 1b99215 | 2019-08-06 11:46:05 +0300 | [diff] [blame] | 302 | aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); } |
Adrian Hunter | eb7a52d | 2019-11-15 14:42:17 +0200 | [diff] [blame] | 303 | aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE); } |
Ian Rogers | 2b62b3a | 2021-10-15 10:21:25 -0700 | [diff] [blame] | 304 | metric-id { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } |
Jiri Olsa | 3a6c51e | 2020-04-17 00:14:05 +0200 | [diff] [blame] | 305 | r{num_raw_hex} { return raw(yyscanner); } |
Jiri Olsa | c33cdf5 | 2020-07-25 14:19:58 +0200 | [diff] [blame] | 306 | r0x{num_raw_hex} { return raw(yyscanner); } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 307 | , { return ','; } |
| 308 | "/" { BEGIN(INITIAL); return '/'; } |
| 309 | {name_minus} { return str(yyscanner, PE_NAME); } |
Wang Nan | e571e02 | 2016-02-22 09:10:35 +0000 | [diff] [blame] | 310 | \[all\] { return PE_ARRAY_ALL; } |
| 311 | "[" { BEGIN(array); return '['; } |
Mathieu Poirier | dd60fba | 2016-09-06 10:37:15 -0600 | [diff] [blame] | 312 | @{drv_cfg_term} { return drv_str(yyscanner, PE_DRV_CFG_TERM); } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | <mem>{ |
| 316 | {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); } |
| 317 | : { return ':'; } |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 318 | "/" { return '/'; } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 319 | {num_dec} { return value(yyscanner, 10); } |
| 320 | {num_hex} { return value(yyscanner, 16); } |
| 321 | /* |
| 322 | * We need to separate 'mem:' scanner part, in order to get specific |
| 323 | * modifier bits parsed out. Otherwise we would need to handle PE_NAME |
| 324 | * and we'd need to parse it manually. During the escape from <mem> |
| 325 | * state we need to put the escaping char back, so we dont miss it. |
| 326 | */ |
| 327 | . { unput(*yytext); BEGIN(INITIAL); } |
| 328 | /* |
| 329 | * We destroy the scanner after reaching EOF, |
| 330 | * but anyway just to be sure get back to INIT state. |
| 331 | */ |
| 332 | <<EOF>> { BEGIN(INITIAL); } |
| 333 | } |
| 334 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 335 | cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } |
| 336 | stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } |
| 337 | stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } |
| 338 | instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } |
| 339 | cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } |
| 340 | cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } |
| 341 | branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } |
| 342 | branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } |
| 343 | bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } |
| 344 | ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } |
| 345 | cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } |
| 346 | task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } |
| 347 | page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } |
| 348 | minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } |
| 349 | major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } |
| 350 | context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } |
| 351 | cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } |
| 352 | alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } |
| 353 | emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } |
Adrian Hunter | d22d1a2 | 2013-08-31 21:50:52 +0300 | [diff] [blame] | 354 | dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 355 | duration_time { return tool(yyscanner, PERF_TOOL_DURATION_TIME); } |
Wang Nan | 03e0a7d | 2016-02-22 09:10:37 +0000 | [diff] [blame] | 356 | bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); } |
Namhyung Kim | fb6c79d | 2021-02-10 17:33:27 +0900 | [diff] [blame] | 357 | cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CGROUP_SWITCHES); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 358 | |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 359 | /* |
| 360 | * We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately. |
| 361 | * Because the prefix cycles is mixed up with cpu-cycles. |
| 362 | * loads and stores are mixed up with cache event |
| 363 | */ |
Adrian Hunter | 47327f56 | 2020-03-26 10:01:47 +0200 | [diff] [blame] | 364 | cycles-ct | |
| 365 | cycles-t | |
| 366 | mem-loads | |
Kan Liang | 2a57d40 | 2021-02-02 12:09:06 -0800 | [diff] [blame] | 367 | mem-loads-aux | |
Adrian Hunter | 47327f56 | 2020-03-26 10:01:47 +0200 | [diff] [blame] | 368 | mem-stores | |
| 369 | topdown-[a-z-]+ | |
| 370 | tx-capacity-[a-z-]+ | |
| 371 | el-capacity-[a-z-]+ { return str(yyscanner, PE_KERNEL_PMU_EVENT); } |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 372 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 373 | L1-dcache|l1-d|l1d|L1-data | |
| 374 | L1-icache|l1-i|l1i|L1-instruction | |
| 375 | LLC|L2 | |
| 376 | dTLB|d-tlb|Data-TLB | |
| 377 | iTLB|i-tlb|Instruction-TLB | |
| 378 | branch|branches|bpu|btb|bpc | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 379 | node { return str(yyscanner, PE_NAME_CACHE_TYPE); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 380 | |
| 381 | load|loads|read | |
| 382 | store|stores|write | |
| 383 | prefetch|prefetches | |
| 384 | speculative-read|speculative-load | |
| 385 | refs|Reference|ops|access | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 386 | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 387 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 388 | mem: { BEGIN(mem); return PE_PREFIX_MEM; } |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 389 | r{num_raw_hex} { return raw(yyscanner); } |
| 390 | {num_dec} { return value(yyscanner, 10); } |
| 391 | {num_hex} { return value(yyscanner, 16); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 392 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 393 | {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } |
Jiri Olsa | a271bfa | 2017-11-09 10:02:10 +0100 | [diff] [blame] | 394 | {bpf_object} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_OBJECT); } |
| 395 | {bpf_source} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_SOURCE); } |
Jiri Olsa | 387ad33 | 2020-06-02 23:47:29 +0200 | [diff] [blame] | 396 | {name} { return pmu_str_check(yyscanner, _parse_state); } |
Alexey Budankov | f92da71 | 2018-06-04 09:50:56 +0300 | [diff] [blame] | 397 | {name_tag} { return str(yyscanner, PE_NAME); } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 398 | "/" { BEGIN(config); return '/'; } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 399 | - { return '-'; } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 400 | , { BEGIN(event); return ','; } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 401 | : { return ':'; } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 402 | "{" { BEGIN(event); return '{'; } |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 403 | "}" { return '}'; } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 404 | = { return '='; } |
Jiri Olsa | 8c5f0a8 | 2012-07-04 00:00:39 +0200 | [diff] [blame] | 405 | \n { } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 406 | . { } |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 407 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 408 | %% |
| 409 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 410 | int parse_events_wrap(void *scanner __maybe_unused) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 411 | { |
| 412 | return 1; |
| 413 | } |