event-parse.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  3. *
  4. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation;
  8. * version 2.1 of the License (not later!)
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this program; if not, see <http://www.gnu.org/licenses>
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. */
  20. #ifndef _PARSE_EVENTS_H
  21. #define _PARSE_EVENTS_H
  22. #include <stdarg.h>
  23. #include <regex.h>
  24. #ifndef __maybe_unused
  25. #define __maybe_unused __attribute__((unused))
  26. #endif
  27. /* ----------------------- trace_seq ----------------------- */
  28. #ifndef TRACE_SEQ_BUF_SIZE
  29. #define TRACE_SEQ_BUF_SIZE 4096
  30. #endif
  31. #ifndef DEBUG_RECORD
  32. #define DEBUG_RECORD 0
  33. #endif
  34. struct pevent_record {
  35. unsigned long long ts;
  36. unsigned long long offset;
  37. long long missed_events; /* buffer dropped events before */
  38. int record_size; /* size of binary record */
  39. int size; /* size of data */
  40. void *data;
  41. int cpu;
  42. int ref_count;
  43. int locked; /* Do not free, even if ref_count is zero */
  44. void *priv;
  45. #if DEBUG_RECORD
  46. struct pevent_record *prev;
  47. struct pevent_record *next;
  48. long alloc_addr;
  49. #endif
  50. };
  51. /*
  52. * Trace sequences are used to allow a function to call several other functions
  53. * to create a string of data to use (up to a max of PAGE_SIZE).
  54. */
  55. struct trace_seq {
  56. char *buffer;
  57. unsigned int buffer_size;
  58. unsigned int len;
  59. unsigned int readpos;
  60. };
  61. void trace_seq_init(struct trace_seq *s);
  62. void trace_seq_destroy(struct trace_seq *s);
  63. extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
  64. __attribute__ ((format (printf, 2, 3)));
  65. extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
  66. __attribute__ ((format (printf, 2, 0)));
  67. extern int trace_seq_puts(struct trace_seq *s, const char *str);
  68. extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
  69. extern void trace_seq_terminate(struct trace_seq *s);
  70. extern int trace_seq_do_printf(struct trace_seq *s);
  71. /* ----------------------- pevent ----------------------- */
  72. struct pevent;
  73. struct event_format;
  74. typedef int (*pevent_event_handler_func)(struct trace_seq *s,
  75. struct pevent_record *record,
  76. struct event_format *event,
  77. void *context);
  78. typedef int (*pevent_plugin_load_func)(struct pevent *pevent);
  79. typedef int (*pevent_plugin_unload_func)(void);
  80. struct plugin_option {
  81. struct plugin_option *next;
  82. void *handle;
  83. char *file;
  84. char *name;
  85. char *plugin_alias;
  86. char *description;
  87. char *value;
  88. void *priv;
  89. int set;
  90. };
  91. /*
  92. * Plugin hooks that can be called:
  93. *
  94. * PEVENT_PLUGIN_LOADER: (required)
  95. * The function name to initialized the plugin.
  96. *
  97. * int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
  98. *
  99. * PEVENT_PLUGIN_UNLOADER: (optional)
  100. * The function called just before unloading
  101. *
  102. * int PEVENT_PLUGIN_UNLOADER(void)
  103. *
  104. * PEVENT_PLUGIN_OPTIONS: (optional)
  105. * Plugin options that can be set before loading
  106. *
  107. * struct plugin_option PEVENT_PLUGIN_OPTIONS[] = {
  108. * {
  109. * .name = "option-name",
  110. * .plugin_alias = "overide-file-name", (optional)
  111. * .description = "description of option to show users",
  112. * },
  113. * {
  114. * .name = NULL,
  115. * },
  116. * };
  117. *
  118. * Array must end with .name = NULL;
  119. *
  120. *
  121. * .plugin_alias is used to give a shorter name to access
  122. * the vairable. Useful if a plugin handles more than one event.
  123. *
  124. * PEVENT_PLUGIN_ALIAS: (optional)
  125. * The name to use for finding options (uses filename if not defined)
  126. */
  127. #define PEVENT_PLUGIN_LOADER pevent_plugin_loader
  128. #define PEVENT_PLUGIN_UNLOADER pevent_plugin_unloader
  129. #define PEVENT_PLUGIN_OPTIONS pevent_plugin_options
  130. #define PEVENT_PLUGIN_ALIAS pevent_plugin_alias
  131. #define _MAKE_STR(x) #x
  132. #define MAKE_STR(x) _MAKE_STR(x)
  133. #define PEVENT_PLUGIN_LOADER_NAME MAKE_STR(PEVENT_PLUGIN_LOADER)
  134. #define PEVENT_PLUGIN_UNLOADER_NAME MAKE_STR(PEVENT_PLUGIN_UNLOADER)
  135. #define PEVENT_PLUGIN_OPTIONS_NAME MAKE_STR(PEVENT_PLUGIN_OPTIONS)
  136. #define PEVENT_PLUGIN_ALIAS_NAME MAKE_STR(PEVENT_PLUGIN_ALIAS)
  137. #define NSECS_PER_SEC 1000000000ULL
  138. #define NSECS_PER_USEC 1000ULL
  139. enum format_flags {
  140. FIELD_IS_ARRAY = 1,
  141. FIELD_IS_POINTER = 2,
  142. FIELD_IS_SIGNED = 4,
  143. FIELD_IS_STRING = 8,
  144. FIELD_IS_DYNAMIC = 16,
  145. FIELD_IS_LONG = 32,
  146. FIELD_IS_FLAG = 64,
  147. FIELD_IS_SYMBOLIC = 128,
  148. };
  149. struct format_field {
  150. struct format_field *next;
  151. struct event_format *event;
  152. char *type;
  153. char *name;
  154. int offset;
  155. int size;
  156. unsigned int arraylen;
  157. unsigned int elementsize;
  158. unsigned long flags;
  159. };
  160. struct format {
  161. int nr_common;
  162. int nr_fields;
  163. struct format_field *common_fields;
  164. struct format_field *fields;
  165. };
  166. struct print_arg_atom {
  167. char *atom;
  168. };
  169. struct print_arg_string {
  170. char *string;
  171. int offset;
  172. };
  173. struct print_arg_field {
  174. char *name;
  175. struct format_field *field;
  176. };
  177. struct print_flag_sym {
  178. struct print_flag_sym *next;
  179. char *value;
  180. char *str;
  181. };
  182. struct print_arg_typecast {
  183. char *type;
  184. struct print_arg *item;
  185. };
  186. struct print_arg_flags {
  187. struct print_arg *field;
  188. char *delim;
  189. struct print_flag_sym *flags;
  190. };
  191. struct print_arg_symbol {
  192. struct print_arg *field;
  193. struct print_flag_sym *symbols;
  194. };
  195. struct print_arg_hex {
  196. struct print_arg *field;
  197. struct print_arg *size;
  198. };
  199. struct print_arg_dynarray {
  200. struct format_field *field;
  201. struct print_arg *index;
  202. };
  203. struct print_arg;
  204. struct print_arg_op {
  205. char *op;
  206. int prio;
  207. struct print_arg *left;
  208. struct print_arg *right;
  209. };
  210. struct pevent_function_handler;
  211. struct print_arg_func {
  212. struct pevent_function_handler *func;
  213. struct print_arg *args;
  214. };
  215. enum print_arg_type {
  216. PRINT_NULL,
  217. PRINT_ATOM,
  218. PRINT_FIELD,
  219. PRINT_FLAGS,
  220. PRINT_SYMBOL,
  221. PRINT_HEX,
  222. PRINT_TYPE,
  223. PRINT_STRING,
  224. PRINT_BSTRING,
  225. PRINT_DYNAMIC_ARRAY,
  226. PRINT_OP,
  227. PRINT_FUNC,
  228. };
  229. struct print_arg {
  230. struct print_arg *next;
  231. enum print_arg_type type;
  232. union {
  233. struct print_arg_atom atom;
  234. struct print_arg_field field;
  235. struct print_arg_typecast typecast;
  236. struct print_arg_flags flags;
  237. struct print_arg_symbol symbol;
  238. struct print_arg_hex hex;
  239. struct print_arg_func func;
  240. struct print_arg_string string;
  241. struct print_arg_op op;
  242. struct print_arg_dynarray dynarray;
  243. };
  244. };
  245. struct print_fmt {
  246. char *format;
  247. struct print_arg *args;
  248. };
  249. struct event_format {
  250. struct pevent *pevent;
  251. char *name;
  252. int id;
  253. int flags;
  254. struct format format;
  255. struct print_fmt print_fmt;
  256. char *system;
  257. pevent_event_handler_func handler;
  258. void *context;
  259. };
  260. enum {
  261. EVENT_FL_ISFTRACE = 0x01,
  262. EVENT_FL_ISPRINT = 0x02,
  263. EVENT_FL_ISBPRINT = 0x04,
  264. EVENT_FL_ISFUNCENT = 0x10,
  265. EVENT_FL_ISFUNCRET = 0x20,
  266. EVENT_FL_FAILED = 0x80000000
  267. };
  268. enum event_sort_type {
  269. EVENT_SORT_ID,
  270. EVENT_SORT_NAME,
  271. EVENT_SORT_SYSTEM,
  272. };
  273. enum event_type {
  274. EVENT_ERROR,
  275. EVENT_NONE,
  276. EVENT_SPACE,
  277. EVENT_NEWLINE,
  278. EVENT_OP,
  279. EVENT_DELIM,
  280. EVENT_ITEM,
  281. EVENT_DQUOTE,
  282. EVENT_SQUOTE,
  283. };
  284. typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s,
  285. unsigned long long *args);
  286. enum pevent_func_arg_type {
  287. PEVENT_FUNC_ARG_VOID,
  288. PEVENT_FUNC_ARG_INT,
  289. PEVENT_FUNC_ARG_LONG,
  290. PEVENT_FUNC_ARG_STRING,
  291. PEVENT_FUNC_ARG_PTR,
  292. PEVENT_FUNC_ARG_MAX_TYPES
  293. };
  294. enum pevent_flag {
  295. PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
  296. };
  297. #define PEVENT_ERRORS \
  298. _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \
  299. _PE(PARSE_EVENT_FAILED, "failed to parse event"), \
  300. _PE(READ_ID_FAILED, "failed to read event id"), \
  301. _PE(READ_FORMAT_FAILED, "failed to read event format"), \
  302. _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \
  303. _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
  304. _PE(INVALID_ARG_TYPE, "invalid argument type")
  305. #undef _PE
  306. #define _PE(__code, __str) PEVENT_ERRNO__ ## __code
  307. enum pevent_errno {
  308. PEVENT_ERRNO__SUCCESS = 0,
  309. /*
  310. * Choose an arbitrary negative big number not to clash with standard
  311. * errno since SUS requires the errno has distinct positive values.
  312. * See 'Issue 6' in the link below.
  313. *
  314. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  315. */
  316. __PEVENT_ERRNO__START = -100000,
  317. PEVENT_ERRORS,
  318. __PEVENT_ERRNO__END,
  319. };
  320. #undef _PE
  321. struct cmdline;
  322. struct cmdline_list;
  323. struct func_map;
  324. struct func_list;
  325. struct event_handler;
  326. struct pevent {
  327. int ref_count;
  328. int header_page_ts_offset;
  329. int header_page_ts_size;
  330. int header_page_size_offset;
  331. int header_page_size_size;
  332. int header_page_data_offset;
  333. int header_page_data_size;
  334. int header_page_overwrite;
  335. int file_bigendian;
  336. int host_bigendian;
  337. int latency_format;
  338. int old_format;
  339. int cpus;
  340. int long_size;
  341. struct cmdline *cmdlines;
  342. struct cmdline_list *cmdlist;
  343. int cmdline_count;
  344. struct func_map *func_map;
  345. struct func_list *funclist;
  346. unsigned int func_count;
  347. struct printk_map *printk_map;
  348. struct printk_list *printklist;
  349. unsigned int printk_count;
  350. struct event_format **events;
  351. int nr_events;
  352. struct event_format **sort_events;
  353. enum event_sort_type last_type;
  354. int type_offset;
  355. int type_size;
  356. int pid_offset;
  357. int pid_size;
  358. int pc_offset;
  359. int pc_size;
  360. int flags_offset;
  361. int flags_size;
  362. int ld_offset;
  363. int ld_size;
  364. int print_raw;
  365. int test_filters;
  366. int flags;
  367. struct format_field *bprint_ip_field;
  368. struct format_field *bprint_fmt_field;
  369. struct format_field *bprint_buf_field;
  370. struct event_handler *handlers;
  371. struct pevent_function_handler *func_handlers;
  372. /* cache */
  373. struct event_format *last_event;
  374. };
  375. static inline void pevent_set_flag(struct pevent *pevent, int flag)
  376. {
  377. pevent->flags |= flag;
  378. }
  379. static inline unsigned short
  380. __data2host2(struct pevent *pevent, unsigned short data)
  381. {
  382. unsigned short swap;
  383. if (pevent->host_bigendian == pevent->file_bigendian)
  384. return data;
  385. swap = ((data & 0xffULL) << 8) |
  386. ((data & (0xffULL << 8)) >> 8);
  387. return swap;
  388. }
  389. static inline unsigned int
  390. __data2host4(struct pevent *pevent, unsigned int data)
  391. {
  392. unsigned int swap;
  393. if (pevent->host_bigendian == pevent->file_bigendian)
  394. return data;
  395. swap = ((data & 0xffULL) << 24) |
  396. ((data & (0xffULL << 8)) << 8) |
  397. ((data & (0xffULL << 16)) >> 8) |
  398. ((data & (0xffULL << 24)) >> 24);
  399. return swap;
  400. }
  401. static inline unsigned long long
  402. __data2host8(struct pevent *pevent, unsigned long long data)
  403. {
  404. unsigned long long swap;
  405. if (pevent->host_bigendian == pevent->file_bigendian)
  406. return data;
  407. swap = ((data & 0xffULL) << 56) |
  408. ((data & (0xffULL << 8)) << 40) |
  409. ((data & (0xffULL << 16)) << 24) |
  410. ((data & (0xffULL << 24)) << 8) |
  411. ((data & (0xffULL << 32)) >> 8) |
  412. ((data & (0xffULL << 40)) >> 24) |
  413. ((data & (0xffULL << 48)) >> 40) |
  414. ((data & (0xffULL << 56)) >> 56);
  415. return swap;
  416. }
  417. #define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr))
  418. #define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr))
  419. #define data2host8(pevent, ptr) \
  420. ({ \
  421. unsigned long long __val; \
  422. \
  423. memcpy(&__val, (ptr), sizeof(unsigned long long)); \
  424. __data2host8(pevent, __val); \
  425. })
  426. /* taken from kernel/trace/trace.h */
  427. enum trace_flag_type {
  428. TRACE_FLAG_IRQS_OFF = 0x01,
  429. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  430. TRACE_FLAG_NEED_RESCHED = 0x04,
  431. TRACE_FLAG_HARDIRQ = 0x08,
  432. TRACE_FLAG_SOFTIRQ = 0x10,
  433. };
  434. int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
  435. int pevent_register_function(struct pevent *pevent, char *name,
  436. unsigned long long addr, char *mod);
  437. int pevent_register_print_string(struct pevent *pevent, char *fmt,
  438. unsigned long long addr);
  439. int pevent_pid_is_registered(struct pevent *pevent, int pid);
  440. void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
  441. struct pevent_record *record);
  442. int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
  443. int long_size);
  444. enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
  445. unsigned long size, const char *sys);
  446. enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
  447. unsigned long size, const char *sys);
  448. void pevent_free_format(struct event_format *event);
  449. void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
  450. const char *name, struct pevent_record *record,
  451. int *len, int err);
  452. int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
  453. const char *name, struct pevent_record *record,
  454. unsigned long long *val, int err);
  455. int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
  456. const char *name, struct pevent_record *record,
  457. unsigned long long *val, int err);
  458. int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
  459. const char *name, struct pevent_record *record,
  460. unsigned long long *val, int err);
  461. int pevent_print_num_field(struct trace_seq *s, const char *fmt,
  462. struct event_format *event, const char *name,
  463. struct pevent_record *record, int err);
  464. int pevent_register_event_handler(struct pevent *pevent, int id, char *sys_name, char *event_name,
  465. pevent_event_handler_func func, void *context);
  466. int pevent_register_print_function(struct pevent *pevent,
  467. pevent_func_handler func,
  468. enum pevent_func_arg_type ret_type,
  469. char *name, ...);
  470. struct format_field *pevent_find_common_field(struct event_format *event, const char *name);
  471. struct format_field *pevent_find_field(struct event_format *event, const char *name);
  472. struct format_field *pevent_find_any_field(struct event_format *event, const char *name);
  473. const char *pevent_find_function(struct pevent *pevent, unsigned long long addr);
  474. unsigned long long
  475. pevent_find_function_address(struct pevent *pevent, unsigned long long addr);
  476. unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size);
  477. int pevent_read_number_field(struct format_field *field, const void *data,
  478. unsigned long long *value);
  479. struct event_format *pevent_find_event(struct pevent *pevent, int id);
  480. struct event_format *
  481. pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name);
  482. void pevent_data_lat_fmt(struct pevent *pevent,
  483. struct trace_seq *s, struct pevent_record *record);
  484. int pevent_data_type(struct pevent *pevent, struct pevent_record *rec);
  485. struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type);
  486. int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec);
  487. const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid);
  488. void pevent_event_info(struct trace_seq *s, struct event_format *event,
  489. struct pevent_record *record);
  490. int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum,
  491. char *buf, size_t buflen);
  492. struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type);
  493. struct format_field **pevent_event_common_fields(struct event_format *event);
  494. struct format_field **pevent_event_fields(struct event_format *event);
  495. static inline int pevent_get_cpus(struct pevent *pevent)
  496. {
  497. return pevent->cpus;
  498. }
  499. static inline void pevent_set_cpus(struct pevent *pevent, int cpus)
  500. {
  501. pevent->cpus = cpus;
  502. }
  503. static inline int pevent_get_long_size(struct pevent *pevent)
  504. {
  505. return pevent->long_size;
  506. }
  507. static inline void pevent_set_long_size(struct pevent *pevent, int long_size)
  508. {
  509. pevent->long_size = long_size;
  510. }
  511. static inline int pevent_is_file_bigendian(struct pevent *pevent)
  512. {
  513. return pevent->file_bigendian;
  514. }
  515. static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian)
  516. {
  517. pevent->file_bigendian = endian;
  518. }
  519. static inline int pevent_is_host_bigendian(struct pevent *pevent)
  520. {
  521. return pevent->host_bigendian;
  522. }
  523. static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian)
  524. {
  525. pevent->host_bigendian = endian;
  526. }
  527. static inline int pevent_is_latency_format(struct pevent *pevent)
  528. {
  529. return pevent->latency_format;
  530. }
  531. static inline void pevent_set_latency_format(struct pevent *pevent, int lat)
  532. {
  533. pevent->latency_format = lat;
  534. }
  535. struct pevent *pevent_alloc(void);
  536. void pevent_free(struct pevent *pevent);
  537. void pevent_ref(struct pevent *pevent);
  538. void pevent_unref(struct pevent *pevent);
  539. /* access to the internal parser */
  540. void pevent_buffer_init(const char *buf, unsigned long long size);
  541. enum event_type pevent_read_token(char **tok);
  542. void pevent_free_token(char *token);
  543. int pevent_peek_char(void);
  544. const char *pevent_get_input_buf(void);
  545. unsigned long long pevent_get_input_buf_ptr(void);
  546. /* for debugging */
  547. void pevent_print_funcs(struct pevent *pevent);
  548. void pevent_print_printk(struct pevent *pevent);
  549. /* ----------------------- filtering ----------------------- */
  550. enum filter_boolean_type {
  551. FILTER_FALSE,
  552. FILTER_TRUE,
  553. };
  554. enum filter_op_type {
  555. FILTER_OP_AND = 1,
  556. FILTER_OP_OR,
  557. FILTER_OP_NOT,
  558. };
  559. enum filter_cmp_type {
  560. FILTER_CMP_NONE,
  561. FILTER_CMP_EQ,
  562. FILTER_CMP_NE,
  563. FILTER_CMP_GT,
  564. FILTER_CMP_LT,
  565. FILTER_CMP_GE,
  566. FILTER_CMP_LE,
  567. FILTER_CMP_MATCH,
  568. FILTER_CMP_NOT_MATCH,
  569. FILTER_CMP_REGEX,
  570. FILTER_CMP_NOT_REGEX,
  571. };
  572. enum filter_exp_type {
  573. FILTER_EXP_NONE,
  574. FILTER_EXP_ADD,
  575. FILTER_EXP_SUB,
  576. FILTER_EXP_MUL,
  577. FILTER_EXP_DIV,
  578. FILTER_EXP_MOD,
  579. FILTER_EXP_RSHIFT,
  580. FILTER_EXP_LSHIFT,
  581. FILTER_EXP_AND,
  582. FILTER_EXP_OR,
  583. FILTER_EXP_XOR,
  584. FILTER_EXP_NOT,
  585. };
  586. enum filter_arg_type {
  587. FILTER_ARG_NONE,
  588. FILTER_ARG_BOOLEAN,
  589. FILTER_ARG_VALUE,
  590. FILTER_ARG_FIELD,
  591. FILTER_ARG_EXP,
  592. FILTER_ARG_OP,
  593. FILTER_ARG_NUM,
  594. FILTER_ARG_STR,
  595. };
  596. enum filter_value_type {
  597. FILTER_NUMBER,
  598. FILTER_STRING,
  599. FILTER_CHAR
  600. };
  601. struct fliter_arg;
  602. struct filter_arg_boolean {
  603. enum filter_boolean_type value;
  604. };
  605. struct filter_arg_field {
  606. struct format_field *field;
  607. };
  608. struct filter_arg_value {
  609. enum filter_value_type type;
  610. union {
  611. char *str;
  612. unsigned long long val;
  613. };
  614. };
  615. struct filter_arg_op {
  616. enum filter_op_type type;
  617. struct filter_arg *left;
  618. struct filter_arg *right;
  619. };
  620. struct filter_arg_exp {
  621. enum filter_exp_type type;
  622. struct filter_arg *left;
  623. struct filter_arg *right;
  624. };
  625. struct filter_arg_num {
  626. enum filter_cmp_type type;
  627. struct filter_arg *left;
  628. struct filter_arg *right;
  629. };
  630. struct filter_arg_str {
  631. enum filter_cmp_type type;
  632. struct format_field *field;
  633. char *val;
  634. char *buffer;
  635. regex_t reg;
  636. };
  637. struct filter_arg {
  638. enum filter_arg_type type;
  639. union {
  640. struct filter_arg_boolean boolean;
  641. struct filter_arg_field field;
  642. struct filter_arg_value value;
  643. struct filter_arg_op op;
  644. struct filter_arg_exp exp;
  645. struct filter_arg_num num;
  646. struct filter_arg_str str;
  647. };
  648. };
  649. struct filter_type {
  650. int event_id;
  651. struct event_format *event;
  652. struct filter_arg *filter;
  653. };
  654. struct event_filter {
  655. struct pevent *pevent;
  656. int filters;
  657. struct filter_type *event_filters;
  658. };
  659. struct event_filter *pevent_filter_alloc(struct pevent *pevent);
  660. #define FILTER_NONE -2
  661. #define FILTER_NOEXIST -1
  662. #define FILTER_MISS 0
  663. #define FILTER_MATCH 1
  664. enum filter_trivial_type {
  665. FILTER_TRIVIAL_FALSE,
  666. FILTER_TRIVIAL_TRUE,
  667. FILTER_TRIVIAL_BOTH,
  668. };
  669. int pevent_filter_add_filter_str(struct event_filter *filter,
  670. const char *filter_str,
  671. char **error_str);
  672. int pevent_filter_match(struct event_filter *filter,
  673. struct pevent_record *record);
  674. int pevent_event_filtered(struct event_filter *filter,
  675. int event_id);
  676. void pevent_filter_reset(struct event_filter *filter);
  677. void pevent_filter_clear_trivial(struct event_filter *filter,
  678. enum filter_trivial_type type);
  679. void pevent_filter_free(struct event_filter *filter);
  680. char *pevent_filter_make_string(struct event_filter *filter, int event_id);
  681. int pevent_filter_remove_event(struct event_filter *filter,
  682. int event_id);
  683. int pevent_filter_event_has_trivial(struct event_filter *filter,
  684. int event_id,
  685. enum filter_trivial_type type);
  686. int pevent_filter_copy(struct event_filter *dest, struct event_filter *source);
  687. int pevent_update_trivial(struct event_filter *dest, struct event_filter *source,
  688. enum filter_trivial_type type);
  689. int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
  690. #endif /* _PARSE_EVENTS_H */