event-parse.h 24 KB

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