4 %option prefix="parse_events_"
10 #include "parse-events-bison.h"
11 #include "parse-events.h"
13 char *parse_events_get_text(yyscan_t yyscanner);
14 YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
16 static int __value(YYSTYPE *yylval, char *str, int base, int token)
21 num = strtoull(str, NULL, base);
29 static int value(yyscan_t scanner, int base)
31 YYSTYPE *yylval = parse_events_get_lval(scanner);
32 char *text = parse_events_get_text(scanner);
34 return __value(yylval, text, base, PE_VALUE);
37 static int raw(yyscan_t scanner)
39 YYSTYPE *yylval = parse_events_get_lval(scanner);
40 char *text = parse_events_get_text(scanner);
42 return __value(yylval, text + 1, 16, PE_RAW);
45 static int str(yyscan_t scanner, int token)
47 YYSTYPE *yylval = parse_events_get_lval(scanner);
48 char *text = parse_events_get_text(scanner);
50 yylval->str = strdup(text);
54 static int sym(yyscan_t scanner, int type, int config)
56 YYSTYPE *yylval = parse_events_get_lval(scanner);
58 yylval->num = (type << 16) + config;
59 return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
62 static int term(yyscan_t scanner, int type)
64 YYSTYPE *yylval = parse_events_get_lval(scanner);
76 group [^,{}/]*[{][^}]*[}][^,{}/]*
77 event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
81 num_hex 0x[a-fA-F0-9]+
82 num_raw_hex [a-fA-F0-9]+
83 name [a-zA-Z_*?][a-zA-Z0-9_*?]*
84 name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]*
85 /* If you add a modifier you need to update check_modifier() */
86 modifier_event [ukhpGHSD]+
87 modifier_bp [rwx]{1,3}
95 start_token = parse_events_get_extra(yyscanner);
97 if (start_token == PE_START_TERMS)
99 else if (start_token == PE_START_EVENTS)
103 parse_events_set_extra(NULL, yyscanner);
112 BEGIN(INITIAL); yyless(0);
117 str(yyscanner, PE_EVENT_NAME);
118 BEGIN(INITIAL); yyless(0);
119 return PE_EVENT_NAME;
124 BEGIN(INITIAL); yyless(0);
130 config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
131 config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
132 config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
133 name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
134 period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
135 branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
137 "/" { BEGIN(INITIAL); return '/'; }
138 {name_minus} { return str(yyscanner, PE_NAME); }
142 {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
144 {num_dec} { return value(yyscanner, 10); }
145 {num_hex} { return value(yyscanner, 16); }
147 * We need to separate 'mem:' scanner part, in order to get specific
148 * modifier bits parsed out. Otherwise we would need to handle PE_NAME
149 * and we'd need to parse it manually. During the escape from <mem>
150 * state we need to put the escaping char back, so we dont miss it.
152 . { unput(*yytext); BEGIN(INITIAL); }
154 * We destroy the scanner after reaching EOF,
155 * but anyway just to be sure get back to INIT state.
157 <<EOF>> { BEGIN(INITIAL); }
160 cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
161 stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
162 stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
163 instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
164 cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
165 cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
166 branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
167 branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
168 bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
169 ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
170 cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
171 task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
172 page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
173 minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
174 major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
175 context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
176 cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
177 alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
178 emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
179 dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
181 L1-dcache|l1-d|l1d|L1-data |
182 L1-icache|l1-i|l1i|L1-instruction |
184 dTLB|d-tlb|Data-TLB |
185 iTLB|i-tlb|Instruction-TLB |
186 branch|branches|bpu|btb|bpc |
187 node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
191 prefetch|prefetches |
192 speculative-read|speculative-load |
193 refs|Reference|ops|access |
194 misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
196 mem: { BEGIN(mem); return PE_PREFIX_MEM; }
197 r{num_raw_hex} { return raw(yyscanner); }
198 {num_dec} { return value(yyscanner, 10); }
199 {num_hex} { return value(yyscanner, 16); }
201 {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
202 {name} { return str(yyscanner, PE_NAME); }
203 "/" { BEGIN(config); return '/'; }
205 , { BEGIN(event); return ','; }
207 "{" { BEGIN(event); return '{'; }
215 int parse_events_wrap(void *scanner __maybe_unused)