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 | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 6 | |
| 7 | %{ |
| 8 | #include <errno.h> |
| 9 | #include "../perf.h" |
| 10 | #include "parse-events-bison.h" |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 11 | #include "parse-events.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 12 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 13 | char *parse_events_get_text(yyscan_t yyscanner); |
| 14 | YYSTYPE *parse_events_get_lval(yyscan_t yyscanner); |
| 15 | |
| 16 | static int __value(YYSTYPE *yylval, char *str, int base, int token) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 17 | { |
| 18 | long num; |
| 19 | |
| 20 | errno = 0; |
| 21 | num = strtoul(str, NULL, base); |
| 22 | if (errno) |
| 23 | return PE_ERROR; |
| 24 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 25 | yylval->num = num; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 26 | return token; |
| 27 | } |
| 28 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 29 | static int value(yyscan_t scanner, int base) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 30 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 31 | 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 Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 37 | static int raw(yyscan_t scanner) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 38 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 39 | 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 Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 45 | static int str(yyscan_t scanner, int token) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 46 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 47 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 48 | char *text = parse_events_get_text(scanner); |
| 49 | |
| 50 | yylval->str = strdup(text); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 51 | return token; |
| 52 | } |
| 53 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 54 | static int sym(yyscan_t scanner, int type, int config) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 55 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 56 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 57 | |
| 58 | yylval->num = (type << 16) + config; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 59 | return PE_VALUE_SYM; |
| 60 | } |
| 61 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 62 | static int term(yyscan_t scanner, int type) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 63 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 64 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 65 | |
| 66 | yylval->num = type; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 67 | return PE_TERM; |
| 68 | } |
| 69 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 70 | %} |
| 71 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 72 | %x mem |
| 73 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 74 | num_dec [0-9]+ |
| 75 | num_hex 0x[a-fA-F0-9]+ |
| 76 | num_raw_hex [a-fA-F0-9]+ |
| 77 | name [a-zA-Z_*?][a-zA-Z0-9_*?]* |
Gleb Natapov | e7c72d8 | 2012-04-17 14:13:45 +0300 | [diff] [blame] | 78 | modifier_event [ukhpGH]{1,8} |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame^] | 79 | modifier_bp [rwx]{1,3} |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 80 | |
| 81 | %% |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 82 | |
| 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 Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 95 | cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } |
| 96 | stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } |
| 97 | stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } |
| 98 | instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } |
| 99 | cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } |
| 100 | cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } |
| 101 | branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } |
| 102 | branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } |
| 103 | bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } |
| 104 | ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } |
| 105 | cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } |
| 106 | task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } |
| 107 | page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } |
| 108 | minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } |
| 109 | major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } |
| 110 | context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } |
| 111 | cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } |
| 112 | alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } |
| 113 | emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 114 | |
| 115 | L1-dcache|l1-d|l1d|L1-data | |
| 116 | L1-icache|l1-i|l1i|L1-instruction | |
| 117 | LLC|L2 | |
| 118 | dTLB|d-tlb|Data-TLB | |
| 119 | iTLB|i-tlb|Instruction-TLB | |
| 120 | branch|branches|bpu|btb|bpc | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 121 | node { return str(yyscanner, PE_NAME_CACHE_TYPE); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 122 | |
| 123 | load|loads|read | |
| 124 | store|stores|write | |
| 125 | prefetch|prefetches | |
| 126 | speculative-read|speculative-load | |
| 127 | refs|Reference|ops|access | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 128 | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 129 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 130 | /* |
| 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 Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 136 | config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } |
| 137 | config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } |
| 138 | config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); } |
| 139 | name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); } |
| 140 | period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } |
| 141 | branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 142 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 143 | mem: { BEGIN(mem); return PE_PREFIX_MEM; } |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 144 | r{num_raw_hex} { return raw(yyscanner); } |
| 145 | {num_dec} { return value(yyscanner, 10); } |
| 146 | {num_hex} { return value(yyscanner, 16); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 147 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 148 | {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } |
| 149 | {name} { return str(yyscanner, PE_NAME); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 150 | "/" { return '/'; } |
| 151 | - { return '-'; } |
| 152 | , { return ','; } |
| 153 | : { return ':'; } |
| 154 | = { return '='; } |
| 155 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 156 | <mem>{ |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 157 | {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); } |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 158 | : { return ':'; } |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 159 | {num_dec} { return value(yyscanner, 10); } |
| 160 | {num_hex} { return value(yyscanner, 16); } |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 161 | /* |
| 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 Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 167 | . { unput(*yytext); BEGIN(INITIAL); } |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 168 | /* |
| 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 Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 175 | %% |
| 176 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 177 | int parse_events_wrap(void *scanner __used) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 178 | { |
| 179 | return 1; |
| 180 | } |