PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/lib/traceevent/event-parse.h

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