event-parse.h 24 KB

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