parse-events.y 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. %pure-parser
  2. %name-prefix "parse_events_"
  3. %parse-param {void *_data}
  4. %parse-param {void *scanner}
  5. %lex-param {void* scanner}
  6. %{
  7. #define YYDEBUG 1
  8. #include <linux/compiler.h>
  9. #include <linux/list.h>
  10. #include "types.h"
  11. #include "util.h"
  12. #include "parse-events.h"
  13. #include "parse-events-bison.h"
  14. extern int parse_events_lex (YYSTYPE* lvalp, void* scanner);
  15. #define ABORT_ON(val) \
  16. do { \
  17. if (val) \
  18. YYABORT; \
  19. } while (0)
  20. %}
  21. %token PE_START_EVENTS PE_START_TERMS
  22. %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
  23. %token PE_NAME
  24. %token PE_MODIFIER_EVENT PE_MODIFIER_BP
  25. %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
  26. %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
  27. %token PE_ERROR
  28. %type <num> PE_VALUE
  29. %type <num> PE_VALUE_SYM_HW
  30. %type <num> PE_VALUE_SYM_SW
  31. %type <num> PE_RAW
  32. %type <num> PE_TERM
  33. %type <str> PE_NAME
  34. %type <str> PE_NAME_CACHE_TYPE
  35. %type <str> PE_NAME_CACHE_OP_RESULT
  36. %type <str> PE_MODIFIER_EVENT
  37. %type <str> PE_MODIFIER_BP
  38. %type <num> value_sym
  39. %type <head> event_config
  40. %type <term> event_term
  41. %type <head> event_pmu
  42. %type <head> event_legacy_symbol
  43. %type <head> event_legacy_cache
  44. %type <head> event_legacy_mem
  45. %type <head> event_legacy_tracepoint
  46. %type <head> event_legacy_numeric
  47. %type <head> event_legacy_raw
  48. %type <head> event_def
  49. %type <head> event
  50. %type <head> events
  51. %type <head> group_def
  52. %type <head> group
  53. %type <head> groups
  54. %union
  55. {
  56. char *str;
  57. u64 num;
  58. struct list_head *head;
  59. struct parse_events__term *term;
  60. }
  61. %%
  62. start:
  63. PE_START_EVENTS start_events
  64. |
  65. PE_START_TERMS start_terms
  66. start_events: groups
  67. {
  68. struct parse_events_data__events *data = _data;
  69. parse_events_update_lists($1, &data->list);
  70. }
  71. groups:
  72. groups ',' group
  73. {
  74. struct list_head *list = $1;
  75. struct list_head *group = $3;
  76. parse_events_update_lists(group, list);
  77. $$ = list;
  78. }
  79. |
  80. groups ',' event
  81. {
  82. struct list_head *list = $1;
  83. struct list_head *event = $3;
  84. parse_events_update_lists(event, list);
  85. $$ = list;
  86. }
  87. |
  88. group
  89. |
  90. event
  91. group:
  92. group_def ':' PE_MODIFIER_EVENT
  93. {
  94. struct list_head *list = $1;
  95. ABORT_ON(parse_events__modifier_group(list, $3));
  96. $$ = list;
  97. }
  98. |
  99. group_def
  100. group_def:
  101. PE_NAME '{' events '}'
  102. {
  103. struct list_head *list = $3;
  104. parse_events__group($1, list);
  105. $$ = list;
  106. }
  107. |
  108. '{' events '}'
  109. {
  110. struct list_head *list = $2;
  111. parse_events__group(NULL, list);
  112. $$ = list;
  113. }
  114. events:
  115. events ',' event
  116. {
  117. struct list_head *event = $3;
  118. struct list_head *list = $1;
  119. parse_events_update_lists(event, list);
  120. $$ = list;
  121. }
  122. |
  123. event
  124. event:
  125. event_def PE_MODIFIER_EVENT
  126. {
  127. struct list_head *list = $1;
  128. /*
  129. * Apply modifier on all events added by single event definition
  130. * (there could be more events added for multiple tracepoint
  131. * definitions via '*?'.
  132. */
  133. ABORT_ON(parse_events__modifier_event(list, $2, false));
  134. $$ = list;
  135. }
  136. |
  137. event_def
  138. event_def: event_pmu |
  139. event_legacy_symbol |
  140. event_legacy_cache sep_dc |
  141. event_legacy_mem |
  142. event_legacy_tracepoint sep_dc |
  143. event_legacy_numeric sep_dc |
  144. event_legacy_raw sep_dc
  145. event_pmu:
  146. PE_NAME '/' event_config '/'
  147. {
  148. struct parse_events_data__events *data = _data;
  149. struct list_head *list = NULL;
  150. ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
  151. parse_events__free_terms($3);
  152. $$ = list;
  153. }
  154. value_sym:
  155. PE_VALUE_SYM_HW
  156. |
  157. PE_VALUE_SYM_SW
  158. event_legacy_symbol:
  159. value_sym '/' event_config '/'
  160. {
  161. struct parse_events_data__events *data = _data;
  162. struct list_head *list = NULL;
  163. int type = $1 >> 16;
  164. int config = $1 & 255;
  165. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  166. type, config, $3));
  167. parse_events__free_terms($3);
  168. $$ = list;
  169. }
  170. |
  171. value_sym sep_slash_dc
  172. {
  173. struct parse_events_data__events *data = _data;
  174. struct list_head *list = NULL;
  175. int type = $1 >> 16;
  176. int config = $1 & 255;
  177. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  178. type, config, NULL));
  179. $$ = list;
  180. }
  181. event_legacy_cache:
  182. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
  183. {
  184. struct parse_events_data__events *data = _data;
  185. struct list_head *list = NULL;
  186. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
  187. $$ = list;
  188. }
  189. |
  190. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
  191. {
  192. struct parse_events_data__events *data = _data;
  193. struct list_head *list = NULL;
  194. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
  195. $$ = list;
  196. }
  197. |
  198. PE_NAME_CACHE_TYPE
  199. {
  200. struct parse_events_data__events *data = _data;
  201. struct list_head *list = NULL;
  202. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
  203. $$ = list;
  204. }
  205. event_legacy_mem:
  206. PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
  207. {
  208. struct parse_events_data__events *data = _data;
  209. struct list_head *list = NULL;
  210. ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
  211. (void *) $2, $4));
  212. $$ = list;
  213. }
  214. |
  215. PE_PREFIX_MEM PE_VALUE sep_dc
  216. {
  217. struct parse_events_data__events *data = _data;
  218. struct list_head *list = NULL;
  219. ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
  220. (void *) $2, NULL));
  221. $$ = list;
  222. }
  223. event_legacy_tracepoint:
  224. PE_NAME ':' PE_NAME
  225. {
  226. struct parse_events_data__events *data = _data;
  227. struct list_head *list = NULL;
  228. ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
  229. $$ = list;
  230. }
  231. event_legacy_numeric:
  232. PE_VALUE ':' PE_VALUE
  233. {
  234. struct parse_events_data__events *data = _data;
  235. struct list_head *list = NULL;
  236. ABORT_ON(parse_events_add_numeric(&list, &data->idx, (u32)$1, $3, NULL));
  237. $$ = list;
  238. }
  239. event_legacy_raw:
  240. PE_RAW
  241. {
  242. struct parse_events_data__events *data = _data;
  243. struct list_head *list = NULL;
  244. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  245. PERF_TYPE_RAW, $1, NULL));
  246. $$ = list;
  247. }
  248. start_terms: event_config
  249. {
  250. struct parse_events_data__terms *data = _data;
  251. data->terms = $1;
  252. }
  253. event_config:
  254. event_config ',' event_term
  255. {
  256. struct list_head *head = $1;
  257. struct parse_events__term *term = $3;
  258. ABORT_ON(!head);
  259. list_add_tail(&term->list, head);
  260. $$ = $1;
  261. }
  262. |
  263. event_term
  264. {
  265. struct list_head *head = malloc(sizeof(*head));
  266. struct parse_events__term *term = $1;
  267. ABORT_ON(!head);
  268. INIT_LIST_HEAD(head);
  269. list_add_tail(&term->list, head);
  270. $$ = head;
  271. }
  272. event_term:
  273. PE_NAME '=' PE_NAME
  274. {
  275. struct parse_events__term *term;
  276. ABORT_ON(parse_events__term_str(&term, PARSE_EVENTS__TERM_TYPE_USER,
  277. $1, $3));
  278. $$ = term;
  279. }
  280. |
  281. PE_NAME '=' PE_VALUE
  282. {
  283. struct parse_events__term *term;
  284. ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
  285. $1, $3));
  286. $$ = term;
  287. }
  288. |
  289. PE_NAME
  290. {
  291. struct parse_events__term *term;
  292. ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
  293. $1, 1));
  294. $$ = term;
  295. }
  296. |
  297. PE_TERM '=' PE_NAME
  298. {
  299. struct parse_events__term *term;
  300. ABORT_ON(parse_events__term_str(&term, (int)$1, NULL, $3));
  301. $$ = term;
  302. }
  303. |
  304. PE_TERM '=' PE_VALUE
  305. {
  306. struct parse_events__term *term;
  307. ABORT_ON(parse_events__term_num(&term, (int)$1, NULL, $3));
  308. $$ = term;
  309. }
  310. |
  311. PE_TERM
  312. {
  313. struct parse_events__term *term;
  314. ABORT_ON(parse_events__term_num(&term, (int)$1, NULL, 1));
  315. $$ = term;
  316. }
  317. sep_dc: ':' |
  318. sep_slash_dc: '/' | ':' |
  319. %%
  320. void parse_events_error(void *data __used, void *scanner __used,
  321. char const *msg __used)
  322. {
  323. }