event-parse.h 25 KB

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