event-parse.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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 plugin_option {
  90. struct 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 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_field {
  183. char *name;
  184. struct format_field *field;
  185. };
  186. struct print_flag_sym {
  187. struct print_flag_sym *next;
  188. char *value;
  189. char *str;
  190. };
  191. struct print_arg_typecast {
  192. char *type;
  193. struct print_arg *item;
  194. };
  195. struct print_arg_flags {
  196. struct print_arg *field;
  197. char *delim;
  198. struct print_flag_sym *flags;
  199. };
  200. struct print_arg_symbol {
  201. struct print_arg *field;
  202. struct print_flag_sym *symbols;
  203. };
  204. struct print_arg_hex {
  205. struct print_arg *field;
  206. struct print_arg *size;
  207. };
  208. struct print_arg_dynarray {
  209. struct format_field *field;
  210. struct print_arg *index;
  211. };
  212. struct print_arg;
  213. struct print_arg_op {
  214. char *op;
  215. int prio;
  216. struct print_arg *left;
  217. struct print_arg *right;
  218. };
  219. struct pevent_function_handler;
  220. struct print_arg_func {
  221. struct pevent_function_handler *func;
  222. struct print_arg *args;
  223. };
  224. enum print_arg_type {
  225. PRINT_NULL,
  226. PRINT_ATOM,
  227. PRINT_FIELD,
  228. PRINT_FLAGS,
  229. PRINT_SYMBOL,
  230. PRINT_HEX,
  231. PRINT_TYPE,
  232. PRINT_STRING,
  233. PRINT_BSTRING,
  234. PRINT_DYNAMIC_ARRAY,
  235. PRINT_OP,
  236. PRINT_FUNC,
  237. };
  238. struct print_arg {
  239. struct print_arg *next;
  240. enum print_arg_type type;
  241. union {
  242. struct print_arg_atom atom;
  243. struct print_arg_field field;
  244. struct print_arg_typecast typecast;
  245. struct print_arg_flags flags;
  246. struct print_arg_symbol symbol;
  247. struct print_arg_hex hex;
  248. struct print_arg_func func;
  249. struct print_arg_string string;
  250. struct print_arg_op op;
  251. struct print_arg_dynarray dynarray;
  252. };
  253. };
  254. struct print_fmt {
  255. char *format;
  256. struct print_arg *args;
  257. };
  258. struct event_format {
  259. struct pevent *pevent;
  260. char *name;
  261. int id;
  262. int flags;
  263. struct format format;
  264. struct print_fmt print_fmt;
  265. char *system;
  266. pevent_event_handler_func handler;
  267. void *context;
  268. };
  269. enum {
  270. EVENT_FL_ISFTRACE = 0x01,
  271. EVENT_FL_ISPRINT = 0x02,
  272. EVENT_FL_ISBPRINT = 0x04,
  273. EVENT_FL_ISFUNCENT = 0x10,
  274. EVENT_FL_ISFUNCRET = 0x20,
  275. EVENT_FL_NOHANDLE = 0x40,
  276. EVENT_FL_PRINTRAW = 0x80,
  277. EVENT_FL_FAILED = 0x80000000
  278. };
  279. enum event_sort_type {
  280. EVENT_SORT_ID,
  281. EVENT_SORT_NAME,
  282. EVENT_SORT_SYSTEM,
  283. };
  284. enum event_type {
  285. EVENT_ERROR,
  286. EVENT_NONE,
  287. EVENT_SPACE,
  288. EVENT_NEWLINE,
  289. EVENT_OP,
  290. EVENT_DELIM,
  291. EVENT_ITEM,
  292. EVENT_DQUOTE,
  293. EVENT_SQUOTE,
  294. };
  295. typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s,
  296. unsigned long long *args);
  297. enum pevent_func_arg_type {
  298. PEVENT_FUNC_ARG_VOID,
  299. PEVENT_FUNC_ARG_INT,
  300. PEVENT_FUNC_ARG_LONG,
  301. PEVENT_FUNC_ARG_STRING,
  302. PEVENT_FUNC_ARG_PTR,
  303. PEVENT_FUNC_ARG_MAX_TYPES
  304. };
  305. enum pevent_flag {
  306. PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
  307. };
  308. #define PEVENT_ERRORS \
  309. _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \
  310. _PE(PARSE_EVENT_FAILED, "failed to parse event"), \
  311. _PE(READ_ID_FAILED, "failed to read event id"), \
  312. _PE(READ_FORMAT_FAILED, "failed to read event format"), \
  313. _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \
  314. _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
  315. _PE(INVALID_ARG_TYPE, "invalid argument type"), \
  316. _PE(INVALID_EXP_TYPE, "invalid expression type"), \
  317. _PE(INVALID_OP_TYPE, "invalid operator type"), \
  318. _PE(INVALID_EVENT_NAME, "invalid event name"), \
  319. _PE(EVENT_NOT_FOUND, "no event found"), \
  320. _PE(SYNTAX_ERROR, "syntax error"), \
  321. _PE(ILLEGAL_RVALUE, "illegal rvalue"), \
  322. _PE(ILLEGAL_LVALUE, "illegal lvalue for string comparison"), \
  323. _PE(INVALID_REGEX, "regex did not compute"), \
  324. _PE(ILLEGAL_STRING_CMP, "illegal comparison for string"), \
  325. _PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"), \
  326. _PE(REPARENT_NOT_OP, "cannot reparent other than OP"), \
  327. _PE(REPARENT_FAILED, "failed to reparent filter OP"), \
  328. _PE(BAD_FILTER_ARG, "bad arg in filter tree"), \
  329. _PE(UNEXPECTED_TYPE, "unexpected type (not a value)"), \
  330. _PE(ILLEGAL_TOKEN, "illegal token"), \
  331. _PE(INVALID_PAREN, "open parenthesis cannot come here"), \
  332. _PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \
  333. _PE(UNKNOWN_TOKEN, "unknown token"), \
  334. _PE(FILTER_NOT_FOUND, "no filter found"), \
  335. _PE(NOT_A_NUMBER, "must have number field"), \
  336. _PE(NO_FILTER, "no filters exists"), \
  337. _PE(FILTER_MISS, "record does not match to filter")
  338. #undef _PE
  339. #define _PE(__code, __str) PEVENT_ERRNO__ ## __code
  340. enum pevent_errno {
  341. PEVENT_ERRNO__SUCCESS = 0,
  342. PEVENT_ERRNO__FILTER_MATCH = PEVENT_ERRNO__SUCCESS,
  343. /*
  344. * Choose an arbitrary negative big number not to clash with standard
  345. * errno since SUS requires the errno has distinct positive values.
  346. * See 'Issue 6' in the link below.
  347. *
  348. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  349. */
  350. __PEVENT_ERRNO__START = -100000,
  351. PEVENT_ERRORS,
  352. __PEVENT_ERRNO__END,
  353. };
  354. #undef _PE
  355. struct plugin_list;
  356. struct plugin_list *traceevent_load_plugins(struct pevent *pevent);
  357. void traceevent_unload_plugins(struct plugin_list *plugin_list,
  358. struct pevent *pevent);
  359. struct cmdline;
  360. struct cmdline_list;
  361. struct func_map;
  362. struct func_list;
  363. struct event_handler;
  364. struct pevent {
  365. int ref_count;
  366. int header_page_ts_offset;
  367. int header_page_ts_size;
  368. int header_page_size_offset;
  369. int header_page_size_size;
  370. int header_page_data_offset;
  371. int header_page_data_size;
  372. int header_page_overwrite;
  373. int file_bigendian;
  374. int host_bigendian;
  375. int latency_format;
  376. int old_format;
  377. int cpus;
  378. int long_size;
  379. int page_size;
  380. struct cmdline *cmdlines;
  381. struct cmdline_list *cmdlist;
  382. int cmdline_count;
  383. struct func_map *func_map;
  384. struct func_list *funclist;
  385. unsigned int func_count;
  386. struct printk_map *printk_map;
  387. struct printk_list *printklist;
  388. unsigned int printk_count;
  389. struct event_format **events;
  390. int nr_events;
  391. struct event_format **sort_events;
  392. enum event_sort_type last_type;
  393. int type_offset;
  394. int type_size;
  395. int pid_offset;
  396. int pid_size;
  397. int pc_offset;
  398. int pc_size;
  399. int flags_offset;
  400. int flags_size;
  401. int ld_offset;
  402. int ld_size;
  403. int print_raw;
  404. int test_filters;
  405. int flags;
  406. struct format_field *bprint_ip_field;
  407. struct format_field *bprint_fmt_field;
  408. struct format_field *bprint_buf_field;
  409. struct event_handler *handlers;
  410. struct pevent_function_handler *func_handlers;
  411. /* cache */
  412. struct event_format *last_event;
  413. char *trace_clock;
  414. };
  415. static inline void pevent_set_flag(struct pevent *pevent, int flag)
  416. {
  417. pevent->flags |= flag;
  418. }
  419. static inline unsigned short
  420. __data2host2(struct pevent *pevent, unsigned short data)
  421. {
  422. unsigned short swap;
  423. if (pevent->host_bigendian == pevent->file_bigendian)
  424. return data;
  425. swap = ((data & 0xffULL) << 8) |
  426. ((data & (0xffULL << 8)) >> 8);
  427. return swap;
  428. }
  429. static inline unsigned int
  430. __data2host4(struct pevent *pevent, unsigned int data)
  431. {
  432. unsigned int swap;
  433. if (pevent->host_bigendian == pevent->file_bigendian)
  434. return data;
  435. swap = ((data & 0xffULL) << 24) |
  436. ((data & (0xffULL << 8)) << 8) |
  437. ((data & (0xffULL << 16)) >> 8) |
  438. ((data & (0xffULL << 24)) >> 24);
  439. return swap;
  440. }
  441. static inline unsigned long long
  442. __data2host8(struct pevent *pevent, unsigned long long data)
  443. {
  444. unsigned long long swap;
  445. if (pevent->host_bigendian == pevent->file_bigendian)
  446. return data;
  447. swap = ((data & 0xffULL) << 56) |
  448. ((data & (0xffULL << 8)) << 40) |
  449. ((data & (0xffULL << 16)) << 24) |
  450. ((data & (0xffULL << 24)) << 8) |
  451. ((data & (0xffULL << 32)) >> 8) |
  452. ((data & (0xffULL << 40)) >> 24) |
  453. ((data & (0xffULL << 48)) >> 40) |
  454. ((data & (0xffULL << 56)) >> 56);
  455. return swap;
  456. }
  457. #define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr))
  458. #define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr))
  459. #define data2host8(pevent, ptr) \
  460. ({ \
  461. unsigned long long __val; \
  462. \
  463. memcpy(&__val, (ptr), sizeof(unsigned long long)); \
  464. __data2host8(pevent, __val); \
  465. })
  466. static inline int traceevent_host_bigendian(void)
  467. {
  468. unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
  469. unsigned int val;
  470. memcpy(&val, str, 4);
  471. return val == 0x01020304;
  472. }
  473. /* taken from kernel/trace/trace.h */
  474. enum trace_flag_type {
  475. TRACE_FLAG_IRQS_OFF = 0x01,
  476. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  477. TRACE_FLAG_NEED_RESCHED = 0x04,
  478. TRACE_FLAG_HARDIRQ = 0x08,
  479. TRACE_FLAG_SOFTIRQ = 0x10,
  480. };
  481. int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
  482. void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
  483. int pevent_register_function(struct pevent *pevent, char *name,
  484. unsigned long long addr, char *mod);
  485. int pevent_register_print_string(struct pevent *pevent, const char *fmt,
  486. unsigned long long addr);
  487. int pevent_pid_is_registered(struct pevent *pevent, int pid);
  488. void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
  489. struct pevent_record *record, bool use_trace_clock);
  490. int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
  491. int long_size);
  492. enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
  493. unsigned long size, const char *sys);
  494. enum pevent_errno pevent_parse_format(struct pevent *pevent,
  495. struct event_format **eventp,
  496. const char *buf,
  497. unsigned long size, const char *sys);
  498. void pevent_free_format(struct event_format *event);
  499. void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
  500. const char *name, struct pevent_record *record,
  501. int *len, int err);
  502. int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
  503. const char *name, struct pevent_record *record,
  504. unsigned long long *val, int err);
  505. int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
  506. const char *name, struct pevent_record *record,
  507. unsigned long long *val, int err);
  508. int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
  509. const char *name, struct pevent_record *record,
  510. unsigned long long *val, int err);
  511. int pevent_print_num_field(struct trace_seq *s, const char *fmt,
  512. struct event_format *event, const char *name,
  513. struct pevent_record *record, int err);
  514. int pevent_print_func_field(struct trace_seq *s, const char *fmt,
  515. struct event_format *event, const char *name,
  516. struct pevent_record *record, int err);
  517. int pevent_register_event_handler(struct pevent *pevent, int id,
  518. const char *sys_name, const char *event_name,
  519. pevent_event_handler_func func, void *context);
  520. int pevent_unregister_event_handler(struct pevent *pevent, int id,
  521. const char *sys_name, const char *event_name,
  522. pevent_event_handler_func func, void *context);
  523. int pevent_register_print_function(struct pevent *pevent,
  524. pevent_func_handler func,
  525. enum pevent_func_arg_type ret_type,
  526. char *name, ...);
  527. int pevent_unregister_print_function(struct pevent *pevent,
  528. pevent_func_handler func, char *name);
  529. struct format_field *pevent_find_common_field(struct event_format *event, const char *name);
  530. struct format_field *pevent_find_field(struct event_format *event, const char *name);
  531. struct format_field *pevent_find_any_field(struct event_format *event, const char *name);
  532. const char *pevent_find_function(struct pevent *pevent, unsigned long long addr);
  533. unsigned long long
  534. pevent_find_function_address(struct pevent *pevent, unsigned long long addr);
  535. unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size);
  536. int pevent_read_number_field(struct format_field *field, const void *data,
  537. unsigned long long *value);
  538. struct event_format *pevent_find_event(struct pevent *pevent, int id);
  539. struct event_format *
  540. pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name);
  541. void pevent_data_lat_fmt(struct pevent *pevent,
  542. struct trace_seq *s, struct pevent_record *record);
  543. int pevent_data_type(struct pevent *pevent, struct pevent_record *rec);
  544. struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type);
  545. int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec);
  546. const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid);
  547. void pevent_event_info(struct trace_seq *s, struct event_format *event,
  548. struct pevent_record *record);
  549. int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum,
  550. char *buf, size_t buflen);
  551. struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type);
  552. struct format_field **pevent_event_common_fields(struct event_format *event);
  553. struct format_field **pevent_event_fields(struct event_format *event);
  554. static inline int pevent_get_cpus(struct pevent *pevent)
  555. {
  556. return pevent->cpus;
  557. }
  558. static inline void pevent_set_cpus(struct pevent *pevent, int cpus)
  559. {
  560. pevent->cpus = cpus;
  561. }
  562. static inline int pevent_get_long_size(struct pevent *pevent)
  563. {
  564. return pevent->long_size;
  565. }
  566. static inline void pevent_set_long_size(struct pevent *pevent, int long_size)
  567. {
  568. pevent->long_size = long_size;
  569. }
  570. static inline int pevent_get_page_size(struct pevent *pevent)
  571. {
  572. return pevent->page_size;
  573. }
  574. static inline void pevent_set_page_size(struct pevent *pevent, int _page_size)
  575. {
  576. pevent->page_size = _page_size;
  577. }
  578. static inline int pevent_is_file_bigendian(struct pevent *pevent)
  579. {
  580. return pevent->file_bigendian;
  581. }
  582. static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian)
  583. {
  584. pevent->file_bigendian = endian;
  585. }
  586. static inline int pevent_is_host_bigendian(struct pevent *pevent)
  587. {
  588. return pevent->host_bigendian;
  589. }
  590. static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian)
  591. {
  592. pevent->host_bigendian = endian;
  593. }
  594. static inline int pevent_is_latency_format(struct pevent *pevent)
  595. {
  596. return pevent->latency_format;
  597. }
  598. static inline void pevent_set_latency_format(struct pevent *pevent, int lat)
  599. {
  600. pevent->latency_format = lat;
  601. }
  602. struct pevent *pevent_alloc(void);
  603. void pevent_free(struct pevent *pevent);
  604. void pevent_ref(struct pevent *pevent);
  605. void pevent_unref(struct pevent *pevent);
  606. /* access to the internal parser */
  607. void pevent_buffer_init(const char *buf, unsigned long long size);
  608. enum event_type pevent_read_token(char **tok);
  609. void pevent_free_token(char *token);
  610. int pevent_peek_char(void);
  611. const char *pevent_get_input_buf(void);
  612. unsigned long long pevent_get_input_buf_ptr(void);
  613. /* for debugging */
  614. void pevent_print_funcs(struct pevent *pevent);
  615. void pevent_print_printk(struct pevent *pevent);
  616. /* ----------------------- filtering ----------------------- */
  617. enum filter_boolean_type {
  618. FILTER_FALSE,
  619. FILTER_TRUE,
  620. };
  621. enum filter_op_type {
  622. FILTER_OP_AND = 1,
  623. FILTER_OP_OR,
  624. FILTER_OP_NOT,
  625. };
  626. enum filter_cmp_type {
  627. FILTER_CMP_NONE,
  628. FILTER_CMP_EQ,
  629. FILTER_CMP_NE,
  630. FILTER_CMP_GT,
  631. FILTER_CMP_LT,
  632. FILTER_CMP_GE,
  633. FILTER_CMP_LE,
  634. FILTER_CMP_MATCH,
  635. FILTER_CMP_NOT_MATCH,
  636. FILTER_CMP_REGEX,
  637. FILTER_CMP_NOT_REGEX,
  638. };
  639. enum filter_exp_type {
  640. FILTER_EXP_NONE,
  641. FILTER_EXP_ADD,
  642. FILTER_EXP_SUB,
  643. FILTER_EXP_MUL,
  644. FILTER_EXP_DIV,
  645. FILTER_EXP_MOD,
  646. FILTER_EXP_RSHIFT,
  647. FILTER_EXP_LSHIFT,
  648. FILTER_EXP_AND,
  649. FILTER_EXP_OR,
  650. FILTER_EXP_XOR,
  651. FILTER_EXP_NOT,
  652. };
  653. enum filter_arg_type {
  654. FILTER_ARG_NONE,
  655. FILTER_ARG_BOOLEAN,
  656. FILTER_ARG_VALUE,
  657. FILTER_ARG_FIELD,
  658. FILTER_ARG_EXP,
  659. FILTER_ARG_OP,
  660. FILTER_ARG_NUM,
  661. FILTER_ARG_STR,
  662. };
  663. enum filter_value_type {
  664. FILTER_NUMBER,
  665. FILTER_STRING,
  666. FILTER_CHAR
  667. };
  668. struct fliter_arg;
  669. struct filter_arg_boolean {
  670. enum filter_boolean_type value;
  671. };
  672. struct filter_arg_field {
  673. struct format_field *field;
  674. };
  675. struct filter_arg_value {
  676. enum filter_value_type type;
  677. union {
  678. char *str;
  679. unsigned long long val;
  680. };
  681. };
  682. struct filter_arg_op {
  683. enum filter_op_type type;
  684. struct filter_arg *left;
  685. struct filter_arg *right;
  686. };
  687. struct filter_arg_exp {
  688. enum filter_exp_type type;
  689. struct filter_arg *left;
  690. struct filter_arg *right;
  691. };
  692. struct filter_arg_num {
  693. enum filter_cmp_type type;
  694. struct filter_arg *left;
  695. struct filter_arg *right;
  696. };
  697. struct filter_arg_str {
  698. enum filter_cmp_type type;
  699. struct format_field *field;
  700. char *val;
  701. char *buffer;
  702. regex_t reg;
  703. };
  704. struct filter_arg {
  705. enum filter_arg_type type;
  706. union {
  707. struct filter_arg_boolean boolean;
  708. struct filter_arg_field field;
  709. struct filter_arg_value value;
  710. struct filter_arg_op op;
  711. struct filter_arg_exp exp;
  712. struct filter_arg_num num;
  713. struct filter_arg_str str;
  714. };
  715. };
  716. struct filter_type {
  717. int event_id;
  718. struct event_format *event;
  719. struct filter_arg *filter;
  720. };
  721. #define PEVENT_FILTER_ERROR_BUFSZ 1024
  722. struct event_filter {
  723. struct pevent *pevent;
  724. int filters;
  725. struct filter_type *event_filters;
  726. char error_buffer[PEVENT_FILTER_ERROR_BUFSZ];
  727. };
  728. struct event_filter *pevent_filter_alloc(struct pevent *pevent);
  729. /* for backward compatibility */
  730. #define FILTER_NONE PEVENT_ERRNO__NO_FILTER
  731. #define FILTER_NOEXIST PEVENT_ERRNO__FILTER_NOT_FOUND
  732. #define FILTER_MISS PEVENT_ERRNO__FILTER_MISS
  733. #define FILTER_MATCH PEVENT_ERRNO__FILTER_MATCH
  734. enum filter_trivial_type {
  735. FILTER_TRIVIAL_FALSE,
  736. FILTER_TRIVIAL_TRUE,
  737. FILTER_TRIVIAL_BOTH,
  738. };
  739. enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
  740. const char *filter_str);
  741. enum pevent_errno pevent_filter_match(struct event_filter *filter,
  742. struct pevent_record *record);
  743. int pevent_filter_strerror(struct event_filter *filter, enum pevent_errno err,
  744. char *buf, size_t buflen);
  745. int pevent_event_filtered(struct event_filter *filter,
  746. int event_id);
  747. void pevent_filter_reset(struct event_filter *filter);
  748. int pevent_filter_clear_trivial(struct event_filter *filter,
  749. enum filter_trivial_type type);
  750. void pevent_filter_free(struct event_filter *filter);
  751. char *pevent_filter_make_string(struct event_filter *filter, int event_id);
  752. int pevent_filter_remove_event(struct event_filter *filter,
  753. int event_id);
  754. int pevent_filter_event_has_trivial(struct event_filter *filter,
  755. int event_id,
  756. enum filter_trivial_type type);
  757. int pevent_filter_copy(struct event_filter *dest, struct event_filter *source);
  758. int pevent_update_trivial(struct event_filter *dest, struct event_filter *source,
  759. enum filter_trivial_type type);
  760. int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
  761. #endif /* _PARSE_EVENTS_H */