blob: 0790452658b3ab84b667d644b11f31373c57fbaa [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{
Robert Richterb527bab2012-08-07 19:43:13 +020018 u64 num;
Jiri Olsa89812fc2012-03-15 20:09:15 +010019
20 errno = 0;
Robert Richterb527bab2012-08-07 19:43:13 +020021 num = strtoull(str, NULL, base);
Jiri Olsa89812fc2012-03-15 20:09:15 +010022 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 Olsacf3506d2012-07-04 00:00:43 +020059 return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
Jiri Olsa89812fc2012-03-15 20:09:15 +010060}
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
Robert Richterac2ba9f2012-08-16 21:10:21 +020073%s config
74%x event
75
76group [^,{}/]*[{][^}]*[}][^,{}/]*
77event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
78event [^,{}/]+
Jiri Olsa08d2f762012-05-21 09:12:52 +020079
Jiri Olsa89812fc2012-03-15 20:09:15 +010080num_dec [0-9]+
81num_hex 0x[a-fA-F0-9]+
82num_raw_hex [a-fA-F0-9]+
83name [a-zA-Z_*?][a-zA-Z0-9_*?]*
Andi Kleeneef9ba92012-11-05 14:50:52 +010084name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]*
Michael Ellermane9a7c412013-08-06 23:28:05 +100085/* If you add a modifier you need to update check_modifier() */
86modifier_event [ukhpGHSD]+
Jiri Olsa75827322012-06-29 09:22:54 +020087modifier_bp [rwx]{1,3}
Jiri Olsa89812fc2012-03-15 20:09:15 +010088
89%%
Jiri Olsa90e2b222012-06-15 14:31:40 +080090
91%{
92 {
93 int start_token;
94
Robert Richterac2ba9f2012-08-16 21:10:21 +020095 start_token = parse_events_get_extra(yyscanner);
96
97 if (start_token == PE_START_TERMS)
98 BEGIN(config);
99 else if (start_token == PE_START_EVENTS)
100 BEGIN(event);
101
Jiri Olsa90e2b222012-06-15 14:31:40 +0800102 if (start_token) {
103 parse_events_set_extra(NULL, yyscanner);
104 return start_token;
105 }
106 }
107%}
108
Robert Richterac2ba9f2012-08-16 21:10:21 +0200109<event>{
110
111{group} {
112 BEGIN(INITIAL); yyless(0);
113 }
114
115{event_pmu} |
116{event} {
117 str(yyscanner, PE_EVENT_NAME);
118 BEGIN(INITIAL); yyless(0);
119 return PE_EVENT_NAME;
120 }
121
122. |
123<<EOF>> {
124 BEGIN(INITIAL); yyless(0);
125 }
126
127}
128
Zheng Yanac20de6f2012-06-15 14:31:39 +0800129cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
130stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
131stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
132instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
133cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
134cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
135branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
136branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
137bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
138ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
139cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
140task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
141page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
142minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
143major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
144context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
145cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
146alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
147emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100148
149L1-dcache|l1-d|l1d|L1-data |
150L1-icache|l1-i|l1i|L1-instruction |
151LLC|L2 |
152dTLB|d-tlb|Data-TLB |
153iTLB|i-tlb|Instruction-TLB |
154branch|branches|bpu|btb|bpc |
Zheng Yanac20de6f2012-06-15 14:31:39 +0800155node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100156
157load|loads|read |
158store|stores|write |
159prefetch|prefetches |
160speculative-read|speculative-load |
161refs|Reference|ops|access |
Zheng Yanac20de6f2012-06-15 14:31:39 +0800162misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100163
Robert Richterac2ba9f2012-08-16 21:10:21 +0200164<config>{
Zheng Yanac20de6f2012-06-15 14:31:39 +0800165config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
166config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
167config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
168name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
169period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
170branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200171, { return ','; }
172"/" { BEGIN(INITIAL); return '/'; }
Andi Kleeneef9ba92012-11-05 14:50:52 +0100173{name_minus} { return str(yyscanner, PE_NAME); }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200174}
Jiri Olsa8f707d82012-03-15 20:09:16 +0100175
Jiri Olsa08d2f762012-05-21 09:12:52 +0200176mem: { BEGIN(mem); return PE_PREFIX_MEM; }
Zheng Yanac20de6f2012-06-15 14:31:39 +0800177r{num_raw_hex} { return raw(yyscanner); }
178{num_dec} { return value(yyscanner, 10); }
179{num_hex} { return value(yyscanner, 16); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100180
Zheng Yanac20de6f2012-06-15 14:31:39 +0800181{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
182{name} { return str(yyscanner, PE_NAME); }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200183"/" { BEGIN(config); return '/'; }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100184- { return '-'; }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200185, { BEGIN(event); return ','; }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100186: { return ':'; }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200187"{" { BEGIN(event); return '{'; }
Jiri Olsa89efb022012-08-08 12:14:14 +0200188"}" { return '}'; }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100189= { return '='; }
Jiri Olsa8c5f0a82012-07-04 00:00:39 +0200190\n { }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100191
Jiri Olsa08d2f762012-05-21 09:12:52 +0200192<mem>{
Zheng Yanac20de6f2012-06-15 14:31:39 +0800193{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200194: { return ':'; }
Zheng Yanac20de6f2012-06-15 14:31:39 +0800195{num_dec} { return value(yyscanner, 10); }
196{num_hex} { return value(yyscanner, 16); }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200197 /*
198 * We need to separate 'mem:' scanner part, in order to get specific
199 * modifier bits parsed out. Otherwise we would need to handle PE_NAME
200 * and we'd need to parse it manually. During the escape from <mem>
201 * state we need to put the escaping char back, so we dont miss it.
202 */
Zheng Yanac20de6f2012-06-15 14:31:39 +0800203. { unput(*yytext); BEGIN(INITIAL); }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200204 /*
205 * We destroy the scanner after reaching EOF,
206 * but anyway just to be sure get back to INIT state.
207 */
208<<EOF>> { BEGIN(INITIAL); }
209}
210
Jiri Olsa89812fc2012-03-15 20:09:15 +0100211%%
212
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300213int parse_events_wrap(void *scanner __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100214{
215 return 1;
216}