Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1 | |
| 2 | %option prefix="parse_events_" |
| 3 | |
| 4 | %{ |
| 5 | #include <errno.h> |
| 6 | #include "../perf.h" |
| 7 | #include "parse-events-bison.h" |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 8 | #include "parse-events.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 9 | |
| 10 | static int __value(char *str, int base, int token) |
| 11 | { |
| 12 | long num; |
| 13 | |
| 14 | errno = 0; |
| 15 | num = strtoul(str, NULL, base); |
| 16 | if (errno) |
| 17 | return PE_ERROR; |
| 18 | |
| 19 | parse_events_lval.num = num; |
| 20 | return token; |
| 21 | } |
| 22 | |
| 23 | static int value(int base) |
| 24 | { |
| 25 | return __value(parse_events_text, base, PE_VALUE); |
| 26 | } |
| 27 | |
| 28 | static int raw(void) |
| 29 | { |
| 30 | return __value(parse_events_text + 1, 16, PE_RAW); |
| 31 | } |
| 32 | |
| 33 | static int str(int token) |
| 34 | { |
| 35 | parse_events_lval.str = strdup(parse_events_text); |
| 36 | return token; |
| 37 | } |
| 38 | |
| 39 | static int sym(int type, int config) |
| 40 | { |
| 41 | parse_events_lval.num = (type << 16) + config; |
| 42 | return PE_VALUE_SYM; |
| 43 | } |
| 44 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 45 | static int term(int type) |
| 46 | { |
| 47 | parse_events_lval.num = type; |
| 48 | return PE_TERM; |
| 49 | } |
| 50 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 51 | %} |
| 52 | |
| 53 | num_dec [0-9]+ |
| 54 | num_hex 0x[a-fA-F0-9]+ |
| 55 | num_raw_hex [a-fA-F0-9]+ |
| 56 | name [a-zA-Z_*?][a-zA-Z0-9_*?]* |
Gleb Natapov | e7c72d8 | 2012-04-17 14:13:45 +0300 | [diff] [blame] | 57 | modifier_event [ukhpGH]{1,8} |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 58 | modifier_bp [rwx] |
| 59 | |
| 60 | %% |
| 61 | cpu-cycles|cycles { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } |
| 62 | stalled-cycles-frontend|idle-cycles-frontend { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } |
| 63 | stalled-cycles-backend|idle-cycles-backend { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } |
| 64 | instructions { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } |
| 65 | cache-references { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } |
| 66 | cache-misses { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } |
| 67 | branch-instructions|branches { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } |
| 68 | branch-misses { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } |
| 69 | bus-cycles { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } |
Namhyung Kim | cc96aa7 | 2012-03-29 19:21:57 +0900 | [diff] [blame] | 70 | ref-cycles { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 71 | cpu-clock { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } |
| 72 | task-clock { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } |
| 73 | page-faults|faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } |
| 74 | minor-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } |
| 75 | major-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } |
| 76 | context-switches|cs { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } |
| 77 | cpu-migrations|migrations { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } |
| 78 | alignment-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } |
| 79 | emulation-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } |
| 80 | |
| 81 | L1-dcache|l1-d|l1d|L1-data | |
| 82 | L1-icache|l1-i|l1i|L1-instruction | |
| 83 | LLC|L2 | |
| 84 | dTLB|d-tlb|Data-TLB | |
| 85 | iTLB|i-tlb|Instruction-TLB | |
| 86 | branch|branches|bpu|btb|bpc | |
| 87 | node { return str(PE_NAME_CACHE_TYPE); } |
| 88 | |
| 89 | load|loads|read | |
| 90 | store|stores|write | |
| 91 | prefetch|prefetches | |
| 92 | speculative-read|speculative-load | |
| 93 | refs|Reference|ops|access | |
| 94 | misses|miss { return str(PE_NAME_CACHE_OP_RESULT); } |
| 95 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 96 | /* |
| 97 | * These are event config hardcoded term names to be specified |
| 98 | * within xxx/.../ syntax. So far we dont clash with other names, |
| 99 | * so we can put them here directly. In case the we have a conflict |
| 100 | * in future, this needs to go into '//' condition block. |
| 101 | */ |
| 102 | config { return term(PARSE_EVENTS__TERM_TYPE_CONFIG); } |
| 103 | config1 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG1); } |
| 104 | config2 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG2); } |
| 105 | period { return term(PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } |
| 106 | branch_type { return term(PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } |
| 107 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 108 | mem: { return PE_PREFIX_MEM; } |
| 109 | r{num_raw_hex} { return raw(); } |
| 110 | {num_dec} { return value(10); } |
| 111 | {num_hex} { return value(16); } |
| 112 | |
| 113 | {modifier_event} { return str(PE_MODIFIER_EVENT); } |
| 114 | {modifier_bp} { return str(PE_MODIFIER_BP); } |
| 115 | {name} { return str(PE_NAME); } |
| 116 | "/" { return '/'; } |
| 117 | - { return '-'; } |
| 118 | , { return ','; } |
| 119 | : { return ':'; } |
| 120 | = { return '='; } |
| 121 | |
| 122 | %% |
| 123 | |
| 124 | int parse_events_wrap(void) |
| 125 | { |
| 126 | return 1; |
| 127 | } |