4 %option prefix="parse_events_"
6 %option bison-locations
12 #include "parse-events.h"
13 #include "parse-events-bison.h"
15 char *parse_events_get_text(yyscan_t yyscanner);
16 YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
18 static int __value(YYSTYPE *yylval, char *str, int base, int token)
23 num = strtoull(str, NULL, base);
31 static int value(yyscan_t scanner, int base)
33 YYSTYPE *yylval = parse_events_get_lval(scanner);
34 char *text = parse_events_get_text(scanner);
36 return __value(yylval, text, base, PE_VALUE);
39 static int raw(yyscan_t scanner)
41 YYSTYPE *yylval = parse_events_get_lval(scanner);
42 char *text = parse_events_get_text(scanner);
44 return __value(yylval, text + 1, 16, PE_RAW);
47 static int str(yyscan_t scanner, int token)
49 YYSTYPE *yylval = parse_events_get_lval(scanner);
50 char *text = parse_events_get_text(scanner);
52 yylval->str = strdup(text);
56 #define REWIND(__alloc) \
58 YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \
59 char *text = parse_events_get_text(yyscanner); \
62 __yylval->str = strdup(text); \
64 yycolumn -= strlen(text); \
68 static int pmu_str_check(yyscan_t scanner)
70 YYSTYPE *yylval = parse_events_get_lval(scanner);
71 char *text = parse_events_get_text(scanner);
73 yylval->str = strdup(text);
74 switch (perf_pmu__parse_check(text)) {
75 case PMU_EVENT_SYMBOL_PREFIX:
76 return PE_PMU_EVENT_PRE;
77 case PMU_EVENT_SYMBOL_SUFFIX:
78 return PE_PMU_EVENT_SUF;
79 case PMU_EVENT_SYMBOL:
80 return PE_KERNEL_PMU_EVENT;
86 static int sym(yyscan_t scanner, int type, int config)
88 YYSTYPE *yylval = parse_events_get_lval(scanner);
90 yylval->num = (type << 16) + config;
91 return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
94 static int term(yyscan_t scanner, int type)
96 YYSTYPE *yylval = parse_events_get_lval(scanner);
102 #define YY_USER_ACTION \
104 yylloc->last_column = yylloc->first_column; \
105 yylloc->first_column = yycolumn; \
106 yycolumn += yyleng; \
116 group [^,{}/]*[{][^}]*[}][^,{}/]*
117 event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
119 bpf_object .*\.(o|bpf)
123 num_hex 0x[a-fA-F0-9]+
124 num_raw_hex [a-fA-F0-9]+
125 name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
126 name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*
127 /* If you add a modifier you need to update check_modifier() */
128 modifier_event [ukhpPGHSDI]+
129 modifier_bp [rwx]{1,3}
137 start_token = parse_events_get_extra(yyscanner);
139 if (start_token == PE_START_TERMS)
141 else if (start_token == PE_START_EVENTS)
145 parse_events_set_extra(NULL, yyscanner);
147 * The flex parser does not init locations variable
148 * via the scan_string interface, so we need do the
170 return PE_EVENT_NAME;
181 "]" { BEGIN(config); return ']'; }
182 {num_dec} { return value(yyscanner, 10); }
183 {num_hex} { return value(yyscanner, 16); }
185 "\.\.\." { return PE_ARRAY_RANGE; }
190 * Please update config_term_names when new static term is added.
192 config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
193 config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
194 config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
195 name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
196 period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
197 freq { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ); }
198 branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
199 time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }
200 call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
201 stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
202 max-stack { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_MAX_STACK); }
203 inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
204 no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
205 overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
206 no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
208 "/" { BEGIN(INITIAL); return '/'; }
209 {name_minus} { return str(yyscanner, PE_NAME); }
210 \[all\] { return PE_ARRAY_ALL; }
211 "[" { BEGIN(array); return '['; }
215 {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
218 {num_dec} { return value(yyscanner, 10); }
219 {num_hex} { return value(yyscanner, 16); }
221 * We need to separate 'mem:' scanner part, in order to get specific
222 * modifier bits parsed out. Otherwise we would need to handle PE_NAME
223 * and we'd need to parse it manually. During the escape from <mem>
224 * state we need to put the escaping char back, so we dont miss it.
226 . { unput(*yytext); BEGIN(INITIAL); }
228 * We destroy the scanner after reaching EOF,
229 * but anyway just to be sure get back to INIT state.
231 <<EOF>> { BEGIN(INITIAL); }
234 cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
235 stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
236 stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
237 instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
238 cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
239 cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
240 branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
241 branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
242 bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
243 ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
244 cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
245 task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
246 page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
247 minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
248 major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
249 context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
250 cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
251 alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
252 emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
253 dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
254 bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); }
257 * We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately.
258 * Because the prefix cycles is mixed up with cpu-cycles.
259 * loads and stores are mixed up with cache event
261 cycles-ct { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
262 cycles-t { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
263 mem-loads { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
264 mem-stores { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
265 topdown-[a-z-]+ { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
267 L1-dcache|l1-d|l1d|L1-data |
268 L1-icache|l1-i|l1i|L1-instruction |
270 dTLB|d-tlb|Data-TLB |
271 iTLB|i-tlb|Instruction-TLB |
272 branch|branches|bpu|btb|bpc |
273 node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
277 prefetch|prefetches |
278 speculative-read|speculative-load |
279 refs|Reference|ops|access |
280 misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
282 mem: { BEGIN(mem); return PE_PREFIX_MEM; }
283 r{num_raw_hex} { return raw(yyscanner); }
284 {num_dec} { return value(yyscanner, 10); }
285 {num_hex} { return value(yyscanner, 16); }
287 {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
288 {bpf_object} { return str(yyscanner, PE_BPF_OBJECT); }
289 {bpf_source} { return str(yyscanner, PE_BPF_SOURCE); }
290 {name} { return pmu_str_check(yyscanner); }
291 "/" { BEGIN(config); return '/'; }
293 , { BEGIN(event); return ','; }
295 "{" { BEGIN(event); return '{'; }
303 int parse_events_wrap(void *scanner __maybe_unused)