event-parse.h 21 KB

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