event-parse.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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 tep_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 tep_record *prev;
  50. struct tep_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 tep_handle;
  84. struct event_format;
  85. typedef int (*tep_event_handler_func)(struct trace_seq *s,
  86. struct tep_record *record,
  87. struct event_format *event,
  88. void *context);
  89. typedef int (*tep_plugin_load_func)(struct tep_handle *pevent);
  90. typedef int (*tep_plugin_unload_func)(struct tep_handle *pevent);
  91. struct tep_plugin_option {
  92. struct tep_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. * TEP_PLUGIN_LOADER: (required)
  106. * The function name to initialized the plugin.
  107. *
  108. * int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
  109. *
  110. * TEP_PLUGIN_UNLOADER: (optional)
  111. * The function called just before unloading
  112. *
  113. * int TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
  114. *
  115. * TEP_PLUGIN_OPTIONS: (optional)
  116. * Plugin options that can be set before loading
  117. *
  118. * struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
  119. * {
  120. * .name = "option-name",
  121. * .plugin_alias = "override-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. * TEP_PLUGIN_ALIAS: (optional)
  140. * The name to use for finding options (uses filename if not defined)
  141. */
  142. #define TEP_PLUGIN_LOADER tep_plugin_loader
  143. #define TEP_PLUGIN_UNLOADER tep_plugin_unloader
  144. #define TEP_PLUGIN_OPTIONS tep_plugin_options
  145. #define TEP_PLUGIN_ALIAS tep_plugin_alias
  146. #define _MAKE_STR(x) #x
  147. #define MAKE_STR(x) _MAKE_STR(x)
  148. #define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
  149. #define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
  150. #define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
  151. #define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
  152. enum format_flags {
  153. FIELD_IS_ARRAY = 1,
  154. FIELD_IS_POINTER = 2,
  155. FIELD_IS_SIGNED = 4,
  156. FIELD_IS_STRING = 8,
  157. FIELD_IS_DYNAMIC = 16,
  158. FIELD_IS_LONG = 32,
  159. FIELD_IS_FLAG = 64,
  160. FIELD_IS_SYMBOLIC = 128,
  161. };
  162. struct format_field {
  163. struct format_field *next;
  164. struct event_format *event;
  165. char *type;
  166. char *name;
  167. char *alias;
  168. int offset;
  169. int size;
  170. unsigned int arraylen;
  171. unsigned int elementsize;
  172. unsigned long flags;
  173. };
  174. struct format {
  175. int nr_common;
  176. int nr_fields;
  177. struct format_field *common_fields;
  178. struct format_field *fields;
  179. };
  180. struct print_arg_atom {
  181. char *atom;
  182. };
  183. struct print_arg_string {
  184. char *string;
  185. int offset;
  186. };
  187. struct print_arg_bitmask {
  188. char *bitmask;
  189. int offset;
  190. };
  191. struct print_arg_field {
  192. char *name;
  193. struct format_field *field;
  194. };
  195. struct print_flag_sym {
  196. struct print_flag_sym *next;
  197. char *value;
  198. char *str;
  199. };
  200. struct print_arg_typecast {
  201. char *type;
  202. struct print_arg *item;
  203. };
  204. struct print_arg_flags {
  205. struct print_arg *field;
  206. char *delim;
  207. struct print_flag_sym *flags;
  208. };
  209. struct print_arg_symbol {
  210. struct print_arg *field;
  211. struct print_flag_sym *symbols;
  212. };
  213. struct print_arg_hex {
  214. struct print_arg *field;
  215. struct print_arg *size;
  216. };
  217. struct print_arg_int_array {
  218. struct print_arg *field;
  219. struct print_arg *count;
  220. struct print_arg *el_size;
  221. };
  222. struct print_arg_dynarray {
  223. struct format_field *field;
  224. struct print_arg *index;
  225. };
  226. struct print_arg;
  227. struct print_arg_op {
  228. char *op;
  229. int prio;
  230. struct print_arg *left;
  231. struct print_arg *right;
  232. };
  233. struct tep_function_handler;
  234. struct print_arg_func {
  235. struct tep_function_handler *func;
  236. struct print_arg *args;
  237. };
  238. enum print_arg_type {
  239. PRINT_NULL,
  240. PRINT_ATOM,
  241. PRINT_FIELD,
  242. PRINT_FLAGS,
  243. PRINT_SYMBOL,
  244. PRINT_HEX,
  245. PRINT_INT_ARRAY,
  246. PRINT_TYPE,
  247. PRINT_STRING,
  248. PRINT_BSTRING,
  249. PRINT_DYNAMIC_ARRAY,
  250. PRINT_OP,
  251. PRINT_FUNC,
  252. PRINT_BITMASK,
  253. PRINT_DYNAMIC_ARRAY_LEN,
  254. PRINT_HEX_STR,
  255. };
  256. struct print_arg {
  257. struct print_arg *next;
  258. enum print_arg_type type;
  259. union {
  260. struct print_arg_atom atom;
  261. struct print_arg_field field;
  262. struct print_arg_typecast typecast;
  263. struct print_arg_flags flags;
  264. struct print_arg_symbol symbol;
  265. struct print_arg_hex hex;
  266. struct print_arg_int_array int_array;
  267. struct print_arg_func func;
  268. struct print_arg_string string;
  269. struct print_arg_bitmask bitmask;
  270. struct print_arg_op op;
  271. struct print_arg_dynarray dynarray;
  272. };
  273. };
  274. struct print_fmt {
  275. char *format;
  276. struct print_arg *args;
  277. };
  278. struct event_format {
  279. struct tep_handle *pevent;
  280. char *name;
  281. int id;
  282. int flags;
  283. struct format format;
  284. struct print_fmt print_fmt;
  285. char *system;
  286. tep_event_handler_func handler;
  287. void *context;
  288. };
  289. enum {
  290. EVENT_FL_ISFTRACE = 0x01,
  291. EVENT_FL_ISPRINT = 0x02,
  292. EVENT_FL_ISBPRINT = 0x04,
  293. EVENT_FL_ISFUNCENT = 0x10,
  294. EVENT_FL_ISFUNCRET = 0x20,
  295. EVENT_FL_NOHANDLE = 0x40,
  296. EVENT_FL_PRINTRAW = 0x80,
  297. EVENT_FL_FAILED = 0x80000000
  298. };
  299. enum event_sort_type {
  300. EVENT_SORT_ID,
  301. EVENT_SORT_NAME,
  302. EVENT_SORT_SYSTEM,
  303. };
  304. enum event_type {
  305. EVENT_ERROR,
  306. EVENT_NONE,
  307. EVENT_SPACE,
  308. EVENT_NEWLINE,
  309. EVENT_OP,
  310. EVENT_DELIM,
  311. EVENT_ITEM,
  312. EVENT_DQUOTE,
  313. EVENT_SQUOTE,
  314. };
  315. typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
  316. unsigned long long *args);
  317. enum tep_func_arg_type {
  318. TEP_FUNC_ARG_VOID,
  319. TEP_FUNC_ARG_INT,
  320. TEP_FUNC_ARG_LONG,
  321. TEP_FUNC_ARG_STRING,
  322. TEP_FUNC_ARG_PTR,
  323. TEP_FUNC_ARG_MAX_TYPES
  324. };
  325. enum tep_flag {
  326. TEP_NSEC_OUTPUT = 1, /* output in NSECS */
  327. TEP_DISABLE_SYS_PLUGINS = 1 << 1,
  328. TEP_DISABLE_PLUGINS = 1 << 2,
  329. };
  330. #define TEP_ERRORS \
  331. _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \
  332. _PE(PARSE_EVENT_FAILED, "failed to parse event"), \
  333. _PE(READ_ID_FAILED, "failed to read event id"), \
  334. _PE(READ_FORMAT_FAILED, "failed to read event format"), \
  335. _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \
  336. _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
  337. _PE(INVALID_ARG_TYPE, "invalid argument type"), \
  338. _PE(INVALID_EXP_TYPE, "invalid expression type"), \
  339. _PE(INVALID_OP_TYPE, "invalid operator type"), \
  340. _PE(INVALID_EVENT_NAME, "invalid event name"), \
  341. _PE(EVENT_NOT_FOUND, "no event found"), \
  342. _PE(SYNTAX_ERROR, "syntax error"), \
  343. _PE(ILLEGAL_RVALUE, "illegal rvalue"), \
  344. _PE(ILLEGAL_LVALUE, "illegal lvalue for string comparison"), \
  345. _PE(INVALID_REGEX, "regex did not compute"), \
  346. _PE(ILLEGAL_STRING_CMP, "illegal comparison for string"), \
  347. _PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"), \
  348. _PE(REPARENT_NOT_OP, "cannot reparent other than OP"), \
  349. _PE(REPARENT_FAILED, "failed to reparent filter OP"), \
  350. _PE(BAD_FILTER_ARG, "bad arg in filter tree"), \
  351. _PE(UNEXPECTED_TYPE, "unexpected type (not a value)"), \
  352. _PE(ILLEGAL_TOKEN, "illegal token"), \
  353. _PE(INVALID_PAREN, "open parenthesis cannot come here"), \
  354. _PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \
  355. _PE(UNKNOWN_TOKEN, "unknown token"), \
  356. _PE(FILTER_NOT_FOUND, "no filter found"), \
  357. _PE(NOT_A_NUMBER, "must have number field"), \
  358. _PE(NO_FILTER, "no filters exists"), \
  359. _PE(FILTER_MISS, "record does not match to filter")
  360. #undef _PE
  361. #define _PE(__code, __str) TEP_ERRNO__ ## __code
  362. enum tep_errno {
  363. TEP_ERRNO__SUCCESS = 0,
  364. TEP_ERRNO__FILTER_MATCH = TEP_ERRNO__SUCCESS,
  365. /*
  366. * Choose an arbitrary negative big number not to clash with standard
  367. * errno since SUS requires the errno has distinct positive values.
  368. * See 'Issue 6' in the link below.
  369. *
  370. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  371. */
  372. __TEP_ERRNO__START = -100000,
  373. TEP_ERRORS,
  374. __TEP_ERRNO__END,
  375. };
  376. #undef _PE
  377. struct plugin_list;
  378. #define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1))
  379. struct plugin_list *tep_load_plugins(struct tep_handle *pevent);
  380. void tep_unload_plugins(struct plugin_list *plugin_list,
  381. struct tep_handle *pevent);
  382. char **tep_plugin_list_options(void);
  383. void tep_plugin_free_options_list(char **list);
  384. int tep_plugin_add_options(const char *name,
  385. struct tep_plugin_option *options);
  386. void tep_plugin_remove_options(struct tep_plugin_option *options);
  387. void tep_print_plugins(struct trace_seq *s,
  388. const char *prefix, const char *suffix,
  389. const struct plugin_list *list);
  390. struct cmdline;
  391. struct cmdline_list;
  392. struct func_map;
  393. struct func_list;
  394. struct event_handler;
  395. struct func_resolver;
  396. typedef char *(tep_func_resolver_t)(void *priv,
  397. unsigned long long *addrp, char **modp);
  398. struct tep_handle {
  399. int ref_count;
  400. int header_page_ts_offset;
  401. int header_page_ts_size;
  402. int header_page_size_offset;
  403. int header_page_size_size;
  404. int header_page_data_offset;
  405. int header_page_data_size;
  406. int header_page_overwrite;
  407. int file_bigendian;
  408. int host_bigendian;
  409. int latency_format;
  410. int old_format;
  411. int cpus;
  412. int long_size;
  413. int page_size;
  414. struct cmdline *cmdlines;
  415. struct cmdline_list *cmdlist;
  416. int cmdline_count;
  417. struct func_map *func_map;
  418. struct func_resolver *func_resolver;
  419. struct func_list *funclist;
  420. unsigned int func_count;
  421. struct printk_map *printk_map;
  422. struct printk_list *printklist;
  423. unsigned int printk_count;
  424. struct event_format **events;
  425. int nr_events;
  426. struct event_format **sort_events;
  427. enum event_sort_type last_type;
  428. int type_offset;
  429. int type_size;
  430. int pid_offset;
  431. int pid_size;
  432. int pc_offset;
  433. int pc_size;
  434. int flags_offset;
  435. int flags_size;
  436. int ld_offset;
  437. int ld_size;
  438. int print_raw;
  439. int test_filters;
  440. int flags;
  441. struct format_field *bprint_ip_field;
  442. struct format_field *bprint_fmt_field;
  443. struct format_field *bprint_buf_field;
  444. struct event_handler *handlers;
  445. struct tep_function_handler *func_handlers;
  446. /* cache */
  447. struct event_format *last_event;
  448. char *trace_clock;
  449. };
  450. static inline void tep_set_flag(struct tep_handle *pevent, int flag)
  451. {
  452. pevent->flags |= flag;
  453. }
  454. static inline unsigned short
  455. __data2host2(struct tep_handle *pevent, unsigned short data)
  456. {
  457. unsigned short swap;
  458. if (pevent->host_bigendian == pevent->file_bigendian)
  459. return data;
  460. swap = ((data & 0xffULL) << 8) |
  461. ((data & (0xffULL << 8)) >> 8);
  462. return swap;
  463. }
  464. static inline unsigned int
  465. __data2host4(struct tep_handle *pevent, unsigned int data)
  466. {
  467. unsigned int swap;
  468. if (pevent->host_bigendian == pevent->file_bigendian)
  469. return data;
  470. swap = ((data & 0xffULL) << 24) |
  471. ((data & (0xffULL << 8)) << 8) |
  472. ((data & (0xffULL << 16)) >> 8) |
  473. ((data & (0xffULL << 24)) >> 24);
  474. return swap;
  475. }
  476. static inline unsigned long long
  477. __data2host8(struct tep_handle *pevent, unsigned long long data)
  478. {
  479. unsigned long long swap;
  480. if (pevent->host_bigendian == pevent->file_bigendian)
  481. return data;
  482. swap = ((data & 0xffULL) << 56) |
  483. ((data & (0xffULL << 8)) << 40) |
  484. ((data & (0xffULL << 16)) << 24) |
  485. ((data & (0xffULL << 24)) << 8) |
  486. ((data & (0xffULL << 32)) >> 8) |
  487. ((data & (0xffULL << 40)) >> 24) |
  488. ((data & (0xffULL << 48)) >> 40) |
  489. ((data & (0xffULL << 56)) >> 56);
  490. return swap;
  491. }
  492. #define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr))
  493. #define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr))
  494. #define data2host8(pevent, ptr) \
  495. ({ \
  496. unsigned long long __val; \
  497. \
  498. memcpy(&__val, (ptr), sizeof(unsigned long long)); \
  499. __data2host8(pevent, __val); \
  500. })
  501. static inline int tep_host_bigendian(void)
  502. {
  503. unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
  504. unsigned int val;
  505. memcpy(&val, str, 4);
  506. return val == 0x01020304;
  507. }
  508. /* taken from kernel/trace/trace.h */
  509. enum trace_flag_type {
  510. TRACE_FLAG_IRQS_OFF = 0x01,
  511. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  512. TRACE_FLAG_NEED_RESCHED = 0x04,
  513. TRACE_FLAG_HARDIRQ = 0x08,
  514. TRACE_FLAG_SOFTIRQ = 0x10,
  515. };
  516. int tep_set_function_resolver(struct tep_handle *pevent,
  517. tep_func_resolver_t *func, void *priv);
  518. void tep_reset_function_resolver(struct tep_handle *pevent);
  519. int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid);
  520. int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock);
  521. int tep_register_function(struct tep_handle *pevent, char *name,
  522. unsigned long long addr, char *mod);
  523. int tep_register_print_string(struct tep_handle *pevent, const char *fmt,
  524. unsigned long long addr);
  525. int tep_pid_is_registered(struct tep_handle *pevent, int pid);
  526. void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
  527. struct event_format *event,
  528. struct tep_record *record);
  529. void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
  530. struct event_format *event,
  531. struct tep_record *record,
  532. bool use_trace_clock);
  533. void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
  534. struct event_format *event,
  535. struct tep_record *record);
  536. void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
  537. struct tep_record *record, bool use_trace_clock);
  538. int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long size,
  539. int long_size);
  540. enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
  541. unsigned long size, const char *sys);
  542. enum tep_errno tep_parse_format(struct tep_handle *pevent,
  543. struct event_format **eventp,
  544. const char *buf,
  545. unsigned long size, const char *sys);
  546. void tep_free_format(struct event_format *event);
  547. void tep_free_format_field(struct format_field *field);
  548. void *tep_get_field_raw(struct trace_seq *s, struct event_format *event,
  549. const char *name, struct tep_record *record,
  550. int *len, int err);
  551. int tep_get_field_val(struct trace_seq *s, struct event_format *event,
  552. const char *name, struct tep_record *record,
  553. unsigned long long *val, int err);
  554. int tep_get_common_field_val(struct trace_seq *s, struct event_format *event,
  555. const char *name, struct tep_record *record,
  556. unsigned long long *val, int err);
  557. int tep_get_any_field_val(struct trace_seq *s, struct event_format *event,
  558. const char *name, struct tep_record *record,
  559. unsigned long long *val, int err);
  560. int tep_print_num_field(struct trace_seq *s, const char *fmt,
  561. struct event_format *event, const char *name,
  562. struct tep_record *record, int err);
  563. int tep_print_func_field(struct trace_seq *s, const char *fmt,
  564. struct event_format *event, const char *name,
  565. struct tep_record *record, int err);
  566. int tep_register_event_handler(struct tep_handle *pevent, int id,
  567. const char *sys_name, const char *event_name,
  568. tep_event_handler_func func, void *context);
  569. int tep_unregister_event_handler(struct tep_handle *pevent, int id,
  570. const char *sys_name, const char *event_name,
  571. tep_event_handler_func func, void *context);
  572. int tep_register_print_function(struct tep_handle *pevent,
  573. tep_func_handler func,
  574. enum tep_func_arg_type ret_type,
  575. char *name, ...);
  576. int tep_unregister_print_function(struct tep_handle *pevent,
  577. tep_func_handler func, char *name);
  578. struct format_field *tep_find_common_field(struct event_format *event, const char *name);
  579. struct format_field *tep_find_field(struct event_format *event, const char *name);
  580. struct format_field *tep_find_any_field(struct event_format *event, const char *name);
  581. const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr);
  582. unsigned long long
  583. tep_find_function_address(struct tep_handle *pevent, unsigned long long addr);
  584. unsigned long long tep_read_number(struct tep_handle *pevent, const void *ptr, int size);
  585. int tep_read_number_field(struct format_field *field, const void *data,
  586. unsigned long long *value);
  587. struct event_format *tep_find_event(struct tep_handle *pevent, int id);
  588. struct event_format *
  589. tep_find_event_by_name(struct tep_handle *pevent, const char *sys, const char *name);
  590. struct event_format *
  591. tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record);
  592. void tep_data_lat_fmt(struct tep_handle *pevent,
  593. struct trace_seq *s, struct tep_record *record);
  594. int tep_data_type(struct tep_handle *pevent, struct tep_record *rec);
  595. struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type);
  596. int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec);
  597. int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec);
  598. int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec);
  599. const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid);
  600. struct cmdline;
  601. struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm,
  602. struct cmdline *next);
  603. int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);
  604. void tep_print_field(struct trace_seq *s, void *data,
  605. struct format_field *field);
  606. void tep_print_fields(struct trace_seq *s, void *data,
  607. int size __maybe_unused, struct event_format *event);
  608. void tep_event_info(struct trace_seq *s, struct event_format *event,
  609. struct tep_record *record);
  610. int tep_strerror(struct tep_handle *pevent, enum tep_errno errnum,
  611. char *buf, size_t buflen);
  612. struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type);
  613. struct format_field **tep_event_common_fields(struct event_format *event);
  614. struct format_field **tep_event_fields(struct event_format *event);
  615. static inline int tep_get_cpus(struct tep_handle *pevent)
  616. {
  617. return pevent->cpus;
  618. }
  619. static inline void tep_set_cpus(struct tep_handle *pevent, int cpus)
  620. {
  621. pevent->cpus = cpus;
  622. }
  623. static inline int tep_get_long_size(struct tep_handle *pevent)
  624. {
  625. return pevent->long_size;
  626. }
  627. static inline void tep_set_long_size(struct tep_handle *pevent, int long_size)
  628. {
  629. pevent->long_size = long_size;
  630. }
  631. static inline int tep_get_page_size(struct tep_handle *pevent)
  632. {
  633. return pevent->page_size;
  634. }
  635. static inline void tep_set_page_size(struct tep_handle *pevent, int _page_size)
  636. {
  637. pevent->page_size = _page_size;
  638. }
  639. static inline int tep_is_file_bigendian(struct tep_handle *pevent)
  640. {
  641. return pevent->file_bigendian;
  642. }
  643. static inline void tep_set_file_bigendian(struct tep_handle *pevent, int endian)
  644. {
  645. pevent->file_bigendian = endian;
  646. }
  647. static inline int tep_is_host_bigendian(struct tep_handle *pevent)
  648. {
  649. return pevent->host_bigendian;
  650. }
  651. static inline void tep_set_host_bigendian(struct tep_handle *pevent, int endian)
  652. {
  653. pevent->host_bigendian = endian;
  654. }
  655. static inline int tep_is_latency_format(struct tep_handle *pevent)
  656. {
  657. return pevent->latency_format;
  658. }
  659. static inline void tep_set_latency_format(struct tep_handle *pevent, int lat)
  660. {
  661. pevent->latency_format = lat;
  662. }
  663. struct tep_handle *tep_alloc(void);
  664. void tep_free(struct tep_handle *pevent);
  665. void tep_ref(struct tep_handle *pevent);
  666. void tep_unref(struct tep_handle *pevent);
  667. /* access to the internal parser */
  668. void tep_buffer_init(const char *buf, unsigned long long size);
  669. enum event_type tep_read_token(char **tok);
  670. void tep_free_token(char *token);
  671. int tep_peek_char(void);
  672. const char *tep_get_input_buf(void);
  673. unsigned long long tep_get_input_buf_ptr(void);
  674. /* for debugging */
  675. void tep_print_funcs(struct tep_handle *pevent);
  676. void tep_print_printk(struct tep_handle *pevent);
  677. /* ----------------------- filtering ----------------------- */
  678. enum filter_boolean_type {
  679. FILTER_FALSE,
  680. FILTER_TRUE,
  681. };
  682. enum filter_op_type {
  683. FILTER_OP_AND = 1,
  684. FILTER_OP_OR,
  685. FILTER_OP_NOT,
  686. };
  687. enum filter_cmp_type {
  688. FILTER_CMP_NONE,
  689. FILTER_CMP_EQ,
  690. FILTER_CMP_NE,
  691. FILTER_CMP_GT,
  692. FILTER_CMP_LT,
  693. FILTER_CMP_GE,
  694. FILTER_CMP_LE,
  695. FILTER_CMP_MATCH,
  696. FILTER_CMP_NOT_MATCH,
  697. FILTER_CMP_REGEX,
  698. FILTER_CMP_NOT_REGEX,
  699. };
  700. enum filter_exp_type {
  701. FILTER_EXP_NONE,
  702. FILTER_EXP_ADD,
  703. FILTER_EXP_SUB,
  704. FILTER_EXP_MUL,
  705. FILTER_EXP_DIV,
  706. FILTER_EXP_MOD,
  707. FILTER_EXP_RSHIFT,
  708. FILTER_EXP_LSHIFT,
  709. FILTER_EXP_AND,
  710. FILTER_EXP_OR,
  711. FILTER_EXP_XOR,
  712. FILTER_EXP_NOT,
  713. };
  714. enum filter_arg_type {
  715. FILTER_ARG_NONE,
  716. FILTER_ARG_BOOLEAN,
  717. FILTER_ARG_VALUE,
  718. FILTER_ARG_FIELD,
  719. FILTER_ARG_EXP,
  720. FILTER_ARG_OP,
  721. FILTER_ARG_NUM,
  722. FILTER_ARG_STR,
  723. };
  724. enum filter_value_type {
  725. FILTER_NUMBER,
  726. FILTER_STRING,
  727. FILTER_CHAR
  728. };
  729. struct fliter_arg;
  730. struct filter_arg_boolean {
  731. enum filter_boolean_type value;
  732. };
  733. struct filter_arg_field {
  734. struct format_field *field;
  735. };
  736. struct filter_arg_value {
  737. enum filter_value_type type;
  738. union {
  739. char *str;
  740. unsigned long long val;
  741. };
  742. };
  743. struct filter_arg_op {
  744. enum filter_op_type type;
  745. struct filter_arg *left;
  746. struct filter_arg *right;
  747. };
  748. struct filter_arg_exp {
  749. enum filter_exp_type type;
  750. struct filter_arg *left;
  751. struct filter_arg *right;
  752. };
  753. struct filter_arg_num {
  754. enum filter_cmp_type type;
  755. struct filter_arg *left;
  756. struct filter_arg *right;
  757. };
  758. struct filter_arg_str {
  759. enum filter_cmp_type type;
  760. struct format_field *field;
  761. char *val;
  762. char *buffer;
  763. regex_t reg;
  764. };
  765. struct filter_arg {
  766. enum filter_arg_type type;
  767. union {
  768. struct filter_arg_boolean boolean;
  769. struct filter_arg_field field;
  770. struct filter_arg_value value;
  771. struct filter_arg_op op;
  772. struct filter_arg_exp exp;
  773. struct filter_arg_num num;
  774. struct filter_arg_str str;
  775. };
  776. };
  777. struct filter_type {
  778. int event_id;
  779. struct event_format *event;
  780. struct filter_arg *filter;
  781. };
  782. #define TEP_FILTER_ERROR_BUFSZ 1024
  783. struct event_filter {
  784. struct tep_handle *pevent;
  785. int filters;
  786. struct filter_type *event_filters;
  787. char error_buffer[TEP_FILTER_ERROR_BUFSZ];
  788. };
  789. struct event_filter *tep_filter_alloc(struct tep_handle *pevent);
  790. /* for backward compatibility */
  791. #define FILTER_NONE TEP_ERRNO__NO_FILTER
  792. #define FILTER_NOEXIST TEP_ERRNO__FILTER_NOT_FOUND
  793. #define FILTER_MISS TEP_ERRNO__FILTER_MISS
  794. #define FILTER_MATCH TEP_ERRNO__FILTER_MATCH
  795. enum filter_trivial_type {
  796. FILTER_TRIVIAL_FALSE,
  797. FILTER_TRIVIAL_TRUE,
  798. FILTER_TRIVIAL_BOTH,
  799. };
  800. enum tep_errno tep_filter_add_filter_str(struct event_filter *filter,
  801. const char *filter_str);
  802. enum tep_errno tep_filter_match(struct event_filter *filter,
  803. struct tep_record *record);
  804. int tep_filter_strerror(struct event_filter *filter, enum tep_errno err,
  805. char *buf, size_t buflen);
  806. int tep_event_filtered(struct event_filter *filter,
  807. int event_id);
  808. void tep_filter_reset(struct event_filter *filter);
  809. int tep_filter_clear_trivial(struct event_filter *filter,
  810. enum filter_trivial_type type);
  811. void tep_filter_free(struct event_filter *filter);
  812. char *tep_filter_make_string(struct event_filter *filter, int event_id);
  813. int tep_filter_remove_event(struct event_filter *filter,
  814. int event_id);
  815. int tep_filter_event_has_trivial(struct event_filter *filter,
  816. int event_id,
  817. enum filter_trivial_type type);
  818. int tep_filter_copy(struct event_filter *dest, struct event_filter *source);
  819. int tep_update_trivial(struct event_filter *dest, struct event_filter *source,
  820. enum filter_trivial_type type);
  821. int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
  822. #endif /* _PARSE_EVENTS_H */