blob: a066894742108521d55129c37800ee8ae6ea8fd1 [file] [log] [blame]
Jiri Olsa89812fc2012-03-15 20:09:15 +01001
Zheng Yanac20de6f2012-06-15 14:31:39 +08002%option reentrant
3%option bison-bridge
Jiri Olsa89812fc2012-03-15 20:09:15 +01004%option prefix="parse_events_"
Jiri Olsa08d2f762012-05-21 09:12:52 +02005%option stack
Jiri Olsa89812fc2012-03-15 20:09:15 +01006
7%{
8#include <errno.h>
9#include "../perf.h"
10#include "parse-events-bison.h"
Jiri Olsa8f707d82012-03-15 20:09:16 +010011#include "parse-events.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010012
Zheng Yanac20de6f2012-06-15 14:31:39 +080013char *parse_events_get_text(yyscan_t yyscanner);
14YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
15
16static int __value(YYSTYPE *yylval, char *str, int base, int token)
Jiri Olsa89812fc2012-03-15 20:09:15 +010017{
18 long num;
19
20 errno = 0;
21 num = strtoul(str, NULL, base);
22 if (errno)
23 return PE_ERROR;
24
Zheng Yanac20de6f2012-06-15 14:31:39 +080025 yylval->num = num;
Jiri Olsa89812fc2012-03-15 20:09:15 +010026 return token;
27}
28
Zheng Yanac20de6f2012-06-15 14:31:39 +080029static int value(yyscan_t scanner, int base)
Jiri Olsa89812fc2012-03-15 20:09:15 +010030{
Zheng Yanac20de6f2012-06-15 14:31:39 +080031 YYSTYPE *yylval = parse_events_get_lval(scanner);
32 char *text = parse_events_get_text(scanner);
33
34 return __value(yylval, text, base, PE_VALUE);
Jiri Olsa89812fc2012-03-15 20:09:15 +010035}
36
Zheng Yanac20de6f2012-06-15 14:31:39 +080037static int raw(yyscan_t scanner)
Jiri Olsa89812fc2012-03-15 20:09:15 +010038{
Zheng Yanac20de6f2012-06-15 14:31:39 +080039 YYSTYPE *yylval = parse_events_get_lval(scanner);
40 char *text = parse_events_get_text(scanner);
41
42 return __value(yylval, text + 1, 16, PE_RAW);
Jiri Olsa89812fc2012-03-15 20:09:15 +010043}
44
Zheng Yanac20de6f2012-06-15 14:31:39 +080045static int str(yyscan_t scanner, int token)
Jiri Olsa89812fc2012-03-15 20:09:15 +010046{
Zheng Yanac20de6f2012-06-15 14:31:39 +080047 YYSTYPE *yylval = parse_events_get_lval(scanner);
48 char *text = parse_events_get_text(scanner);
49
50 yylval->str = strdup(text);
Jiri Olsa89812fc2012-03-15 20:09:15 +010051 return token;
52}
53
Zheng Yanac20de6f2012-06-15 14:31:39 +080054static int sym(yyscan_t scanner, int type, int config)
Jiri Olsa89812fc2012-03-15 20:09:15 +010055{
Zheng Yanac20de6f2012-06-15 14:31:39 +080056 YYSTYPE *yylval = parse_events_get_lval(scanner);
57
58 yylval->num = (type << 16) + config;
Jiri Olsa89812fc2012-03-15 20:09:15 +010059 return PE_VALUE_SYM;
60}
61
Zheng Yanac20de6f2012-06-15 14:31:39 +080062static int term(yyscan_t scanner, int type)
Jiri Olsa8f707d82012-03-15 20:09:16 +010063{
Zheng Yanac20de6f2012-06-15 14:31:39 +080064 YYSTYPE *yylval = parse_events_get_lval(scanner);
65
66 yylval->num = type;
Jiri Olsa8f707d82012-03-15 20:09:16 +010067 return PE_TERM;
68}
69
Jiri Olsa89812fc2012-03-15 20:09:15 +010070%}
71
Jiri Olsa08d2f762012-05-21 09:12:52 +020072%x mem
73
Jiri Olsa89812fc2012-03-15 20:09:15 +010074num_dec [0-9]+
75num_hex 0x[a-fA-F0-9]+
76num_raw_hex [a-fA-F0-9]+
77name [a-zA-Z_*?][a-zA-Z0-9_*?]*
Gleb Natapove7c72d82012-04-17 14:13:45 +030078modifier_event [ukhpGH]{1,8}
Jiri Olsa75827322012-06-29 09:22:54 +020079modifier_bp [rwx]{1,3}
Jiri Olsa89812fc2012-03-15 20:09:15 +010080
81%%
Jiri Olsa90e2b222012-06-15 14:31:40 +080082
83%{
84 {
85 int start_token;
86
87 start_token = (int) parse_events_get_extra(yyscanner);
88 if (start_token) {
89 parse_events_set_extra(NULL, yyscanner);
90 return start_token;
91 }
92 }
93%}
94
Zheng Yanac20de6f2012-06-15 14:31:39 +080095cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
96stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
97stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
98instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
99cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
100cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
101branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
102branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
103bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
104ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
105cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
106task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
107page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
108minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
109major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
110context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
111cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
112alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
113emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100114
115L1-dcache|l1-d|l1d|L1-data |
116L1-icache|l1-i|l1i|L1-instruction |
117LLC|L2 |
118dTLB|d-tlb|Data-TLB |
119iTLB|i-tlb|Instruction-TLB |
120branch|branches|bpu|btb|bpc |
Zheng Yanac20de6f2012-06-15 14:31:39 +0800121node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100122
123load|loads|read |
124store|stores|write |
125prefetch|prefetches |
126speculative-read|speculative-load |
127refs|Reference|ops|access |
Zheng Yanac20de6f2012-06-15 14:31:39 +0800128misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100129
Jiri Olsa8f707d82012-03-15 20:09:16 +0100130 /*
131 * These are event config hardcoded term names to be specified
132 * within xxx/.../ syntax. So far we dont clash with other names,
133 * so we can put them here directly. In case the we have a conflict
134 * in future, this needs to go into '//' condition block.
135 */
Zheng Yanac20de6f2012-06-15 14:31:39 +0800136config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
137config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
138config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
139name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
140period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
141branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
Jiri Olsa8f707d82012-03-15 20:09:16 +0100142
Jiri Olsa08d2f762012-05-21 09:12:52 +0200143mem: { BEGIN(mem); return PE_PREFIX_MEM; }
Zheng Yanac20de6f2012-06-15 14:31:39 +0800144r{num_raw_hex} { return raw(yyscanner); }
145{num_dec} { return value(yyscanner, 10); }
146{num_hex} { return value(yyscanner, 16); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100147
Zheng Yanac20de6f2012-06-15 14:31:39 +0800148{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
149{name} { return str(yyscanner, PE_NAME); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100150"/" { return '/'; }
151- { return '-'; }
152, { return ','; }
153: { return ':'; }
154= { return '='; }
155
Jiri Olsa08d2f762012-05-21 09:12:52 +0200156<mem>{
Zheng Yanac20de6f2012-06-15 14:31:39 +0800157{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200158: { return ':'; }
Zheng Yanac20de6f2012-06-15 14:31:39 +0800159{num_dec} { return value(yyscanner, 10); }
160{num_hex} { return value(yyscanner, 16); }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200161 /*
162 * We need to separate 'mem:' scanner part, in order to get specific
163 * modifier bits parsed out. Otherwise we would need to handle PE_NAME
164 * and we'd need to parse it manually. During the escape from <mem>
165 * state we need to put the escaping char back, so we dont miss it.
166 */
Zheng Yanac20de6f2012-06-15 14:31:39 +0800167. { unput(*yytext); BEGIN(INITIAL); }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200168 /*
169 * We destroy the scanner after reaching EOF,
170 * but anyway just to be sure get back to INIT state.
171 */
172<<EOF>> { BEGIN(INITIAL); }
173}
174
Jiri Olsa89812fc2012-03-15 20:09:15 +0100175%%
176
Zheng Yanac20de6f2012-06-15 14:31:39 +0800177int parse_events_wrap(void *scanner __used)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100178{
179 return 1;
180}