event-parse.h 20 KB

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