event-parse.h 24 KB

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