event-parse.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 tep_print_arg_atom {
  150. char *atom;
  151. };
  152. struct tep_print_arg_string {
  153. char *string;
  154. int offset;
  155. };
  156. struct tep_print_arg_bitmask {
  157. char *bitmask;
  158. int offset;
  159. };
  160. struct tep_print_arg_field {
  161. char *name;
  162. struct tep_format_field *field;
  163. };
  164. struct tep_print_flag_sym {
  165. struct tep_print_flag_sym *next;
  166. char *value;
  167. char *str;
  168. };
  169. struct tep_print_arg_typecast {
  170. char *type;
  171. struct tep_print_arg *item;
  172. };
  173. struct tep_print_arg_flags {
  174. struct tep_print_arg *field;
  175. char *delim;
  176. struct tep_print_flag_sym *flags;
  177. };
  178. struct tep_print_arg_symbol {
  179. struct tep_print_arg *field;
  180. struct tep_print_flag_sym *symbols;
  181. };
  182. struct tep_print_arg_hex {
  183. struct tep_print_arg *field;
  184. struct tep_print_arg *size;
  185. };
  186. struct tep_print_arg_int_array {
  187. struct tep_print_arg *field;
  188. struct tep_print_arg *count;
  189. struct tep_print_arg *el_size;
  190. };
  191. struct tep_print_arg_dynarray {
  192. struct tep_format_field *field;
  193. struct tep_print_arg *index;
  194. };
  195. struct tep_print_arg;
  196. struct tep_print_arg_op {
  197. char *op;
  198. int prio;
  199. struct tep_print_arg *left;
  200. struct tep_print_arg *right;
  201. };
  202. struct tep_function_handler;
  203. struct tep_print_arg_func {
  204. struct tep_function_handler *func;
  205. struct tep_print_arg *args;
  206. };
  207. enum tep_print_arg_type {
  208. TEP_PRINT_NULL,
  209. TEP_PRINT_ATOM,
  210. TEP_PRINT_FIELD,
  211. TEP_PRINT_FLAGS,
  212. TEP_PRINT_SYMBOL,
  213. TEP_PRINT_HEX,
  214. TEP_PRINT_INT_ARRAY,
  215. TEP_PRINT_TYPE,
  216. TEP_PRINT_STRING,
  217. TEP_PRINT_BSTRING,
  218. TEP_PRINT_DYNAMIC_ARRAY,
  219. TEP_PRINT_OP,
  220. TEP_PRINT_FUNC,
  221. TEP_PRINT_BITMASK,
  222. TEP_PRINT_DYNAMIC_ARRAY_LEN,
  223. TEP_PRINT_HEX_STR,
  224. };
  225. struct tep_print_arg {
  226. struct tep_print_arg *next;
  227. enum tep_print_arg_type type;
  228. union {
  229. struct tep_print_arg_atom atom;
  230. struct tep_print_arg_field field;
  231. struct tep_print_arg_typecast typecast;
  232. struct tep_print_arg_flags flags;
  233. struct tep_print_arg_symbol symbol;
  234. struct tep_print_arg_hex hex;
  235. struct tep_print_arg_int_array int_array;
  236. struct tep_print_arg_func func;
  237. struct tep_print_arg_string string;
  238. struct tep_print_arg_bitmask bitmask;
  239. struct tep_print_arg_op op;
  240. struct tep_print_arg_dynarray dynarray;
  241. };
  242. };
  243. struct tep_print_fmt {
  244. char *format;
  245. struct tep_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 tep_print_fmt print_fmt;
  254. char *system;
  255. tep_event_handler_func handler;
  256. void *context;
  257. };
  258. enum {
  259. TEP_EVENT_FL_ISFTRACE = 0x01,
  260. TEP_EVENT_FL_ISPRINT = 0x02,
  261. TEP_EVENT_FL_ISBPRINT = 0x04,
  262. TEP_EVENT_FL_ISFUNCENT = 0x10,
  263. TEP_EVENT_FL_ISFUNCRET = 0x20,
  264. TEP_EVENT_FL_NOHANDLE = 0x40,
  265. TEP_EVENT_FL_PRINTRAW = 0x80,
  266. TEP_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 tep_plugin_list;
  347. #define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1))
  348. struct tep_plugin_list *tep_load_plugins(struct tep_handle *pevent);
  349. void tep_unload_plugins(struct tep_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 tep_plugin_list *list);
  359. /* tep_handle */
  360. typedef char *(tep_func_resolver_t)(void *priv,
  361. unsigned long long *addrp, char **modp);
  362. void tep_set_flag(struct tep_handle *tep, int flag);
  363. unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data);
  364. unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data);
  365. unsigned long long
  366. __tep_data2host8(struct tep_handle *pevent, unsigned long long data);
  367. #define tep_data2host2(pevent, ptr) __tep_data2host2(pevent, *(unsigned short *)(ptr))
  368. #define tep_data2host4(pevent, ptr) __tep_data2host4(pevent, *(unsigned int *)(ptr))
  369. #define tep_data2host8(pevent, ptr) \
  370. ({ \
  371. unsigned long long __val; \
  372. \
  373. memcpy(&__val, (ptr), sizeof(unsigned long long)); \
  374. __tep_data2host8(pevent, __val); \
  375. })
  376. static inline int tep_host_bigendian(void)
  377. {
  378. unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
  379. unsigned int val;
  380. memcpy(&val, str, 4);
  381. return val == 0x01020304;
  382. }
  383. /* taken from kernel/trace/trace.h */
  384. enum trace_flag_type {
  385. TRACE_FLAG_IRQS_OFF = 0x01,
  386. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  387. TRACE_FLAG_NEED_RESCHED = 0x04,
  388. TRACE_FLAG_HARDIRQ = 0x08,
  389. TRACE_FLAG_SOFTIRQ = 0x10,
  390. };
  391. int tep_set_function_resolver(struct tep_handle *pevent,
  392. tep_func_resolver_t *func, void *priv);
  393. void tep_reset_function_resolver(struct tep_handle *pevent);
  394. int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid);
  395. int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock);
  396. int tep_register_function(struct tep_handle *pevent, char *name,
  397. unsigned long long addr, char *mod);
  398. int tep_register_print_string(struct tep_handle *pevent, const char *fmt,
  399. unsigned long long addr);
  400. int tep_pid_is_registered(struct tep_handle *pevent, int pid);
  401. void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
  402. struct tep_event_format *event,
  403. struct tep_record *record);
  404. void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
  405. struct tep_event_format *event,
  406. struct tep_record *record,
  407. bool use_trace_clock);
  408. void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
  409. struct tep_event_format *event,
  410. struct tep_record *record);
  411. void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
  412. struct tep_record *record, bool use_trace_clock);
  413. int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long size,
  414. int long_size);
  415. enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
  416. unsigned long size, const char *sys);
  417. enum tep_errno tep_parse_format(struct tep_handle *pevent,
  418. struct tep_event_format **eventp,
  419. const char *buf,
  420. unsigned long size, const char *sys);
  421. void tep_free_format(struct tep_event_format *event);
  422. void tep_free_format_field(struct tep_format_field *field);
  423. void *tep_get_field_raw(struct trace_seq *s, struct tep_event_format *event,
  424. const char *name, struct tep_record *record,
  425. int *len, int err);
  426. int tep_get_field_val(struct trace_seq *s, struct tep_event_format *event,
  427. const char *name, struct tep_record *record,
  428. unsigned long long *val, int err);
  429. int tep_get_common_field_val(struct trace_seq *s, struct tep_event_format *event,
  430. const char *name, struct tep_record *record,
  431. unsigned long long *val, int err);
  432. int tep_get_any_field_val(struct trace_seq *s, struct tep_event_format *event,
  433. const char *name, struct tep_record *record,
  434. unsigned long long *val, int err);
  435. int tep_print_num_field(struct trace_seq *s, const char *fmt,
  436. struct tep_event_format *event, const char *name,
  437. struct tep_record *record, int err);
  438. int tep_print_func_field(struct trace_seq *s, const char *fmt,
  439. struct tep_event_format *event, const char *name,
  440. struct tep_record *record, int err);
  441. int tep_register_event_handler(struct tep_handle *pevent, int id,
  442. const char *sys_name, const char *event_name,
  443. tep_event_handler_func func, void *context);
  444. int tep_unregister_event_handler(struct tep_handle *pevent, int id,
  445. const char *sys_name, const char *event_name,
  446. tep_event_handler_func func, void *context);
  447. int tep_register_print_function(struct tep_handle *pevent,
  448. tep_func_handler func,
  449. enum tep_func_arg_type ret_type,
  450. char *name, ...);
  451. int tep_unregister_print_function(struct tep_handle *pevent,
  452. tep_func_handler func, char *name);
  453. struct tep_format_field *tep_find_common_field(struct tep_event_format *event, const char *name);
  454. struct tep_format_field *tep_find_field(struct tep_event_format *event, const char *name);
  455. struct tep_format_field *tep_find_any_field(struct tep_event_format *event, const char *name);
  456. const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr);
  457. unsigned long long
  458. tep_find_function_address(struct tep_handle *pevent, unsigned long long addr);
  459. unsigned long long tep_read_number(struct tep_handle *pevent, const void *ptr, int size);
  460. int tep_read_number_field(struct tep_format_field *field, const void *data,
  461. unsigned long long *value);
  462. struct tep_event_format *tep_get_first_event(struct tep_handle *tep);
  463. int tep_get_events_count(struct tep_handle *tep);
  464. struct tep_event_format *tep_find_event(struct tep_handle *pevent, int id);
  465. struct tep_event_format *
  466. tep_find_event_by_name(struct tep_handle *pevent, const char *sys, const char *name);
  467. struct tep_event_format *
  468. tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record);
  469. void tep_data_lat_fmt(struct tep_handle *pevent,
  470. struct trace_seq *s, struct tep_record *record);
  471. int tep_data_type(struct tep_handle *pevent, struct tep_record *rec);
  472. struct tep_event_format *tep_data_event_from_type(struct tep_handle *pevent, int type);
  473. int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec);
  474. int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec);
  475. int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec);
  476. const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid);
  477. struct cmdline;
  478. struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm,
  479. struct cmdline *next);
  480. int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);
  481. void tep_print_field(struct trace_seq *s, void *data,
  482. struct tep_format_field *field);
  483. void tep_print_fields(struct trace_seq *s, void *data,
  484. int size __maybe_unused, struct tep_event_format *event);
  485. void tep_event_info(struct trace_seq *s, struct tep_event_format *event,
  486. struct tep_record *record);
  487. int tep_strerror(struct tep_handle *pevent, enum tep_errno errnum,
  488. char *buf, size_t buflen);
  489. struct tep_event_format **tep_list_events(struct tep_handle *pevent, enum tep_event_sort_type);
  490. struct tep_format_field **tep_event_common_fields(struct tep_event_format *event);
  491. struct tep_format_field **tep_event_fields(struct tep_event_format *event);
  492. enum tep_endian {
  493. TEP_LITTLE_ENDIAN = 0,
  494. TEP_BIG_ENDIAN
  495. };
  496. int tep_get_cpus(struct tep_handle *pevent);
  497. void tep_set_cpus(struct tep_handle *pevent, int cpus);
  498. int tep_get_long_size(struct tep_handle *pevent);
  499. void tep_set_long_size(struct tep_handle *pevent, int long_size);
  500. int tep_get_page_size(struct tep_handle *pevent);
  501. void tep_set_page_size(struct tep_handle *pevent, int _page_size);
  502. int tep_is_file_bigendian(struct tep_handle *pevent);
  503. void tep_set_file_bigendian(struct tep_handle *pevent, enum tep_endian endian);
  504. int tep_is_host_bigendian(struct tep_handle *pevent);
  505. void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian);
  506. int tep_is_latency_format(struct tep_handle *pevent);
  507. void tep_set_latency_format(struct tep_handle *pevent, int lat);
  508. int tep_get_header_page_size(struct tep_handle *pevent);
  509. struct tep_handle *tep_alloc(void);
  510. void tep_free(struct tep_handle *pevent);
  511. void tep_ref(struct tep_handle *pevent);
  512. void tep_unref(struct tep_handle *pevent);
  513. /* access to the internal parser */
  514. void tep_buffer_init(const char *buf, unsigned long long size);
  515. enum tep_event_type tep_read_token(char **tok);
  516. void tep_free_token(char *token);
  517. int tep_peek_char(void);
  518. const char *tep_get_input_buf(void);
  519. unsigned long long tep_get_input_buf_ptr(void);
  520. /* for debugging */
  521. void tep_print_funcs(struct tep_handle *pevent);
  522. void tep_print_printk(struct tep_handle *pevent);
  523. /* ----------------------- filtering ----------------------- */
  524. enum tep_filter_boolean_type {
  525. TEP_FILTER_FALSE,
  526. TEP_FILTER_TRUE,
  527. };
  528. enum tep_filter_op_type {
  529. TEP_FILTER_OP_AND = 1,
  530. TEP_FILTER_OP_OR,
  531. TEP_FILTER_OP_NOT,
  532. };
  533. enum tep_filter_cmp_type {
  534. TEP_FILTER_CMP_NONE,
  535. TEP_FILTER_CMP_EQ,
  536. TEP_FILTER_CMP_NE,
  537. TEP_FILTER_CMP_GT,
  538. TEP_FILTER_CMP_LT,
  539. TEP_FILTER_CMP_GE,
  540. TEP_FILTER_CMP_LE,
  541. TEP_FILTER_CMP_MATCH,
  542. TEP_FILTER_CMP_NOT_MATCH,
  543. TEP_FILTER_CMP_REGEX,
  544. TEP_FILTER_CMP_NOT_REGEX,
  545. };
  546. enum tep_filter_exp_type {
  547. TEP_FILTER_EXP_NONE,
  548. TEP_FILTER_EXP_ADD,
  549. TEP_FILTER_EXP_SUB,
  550. TEP_FILTER_EXP_MUL,
  551. TEP_FILTER_EXP_DIV,
  552. TEP_FILTER_EXP_MOD,
  553. TEP_FILTER_EXP_RSHIFT,
  554. TEP_FILTER_EXP_LSHIFT,
  555. TEP_FILTER_EXP_AND,
  556. TEP_FILTER_EXP_OR,
  557. TEP_FILTER_EXP_XOR,
  558. TEP_FILTER_EXP_NOT,
  559. };
  560. enum tep_filter_arg_type {
  561. TEP_FILTER_ARG_NONE,
  562. TEP_FILTER_ARG_BOOLEAN,
  563. TEP_FILTER_ARG_VALUE,
  564. TEP_FILTER_ARG_FIELD,
  565. TEP_FILTER_ARG_EXP,
  566. TEP_FILTER_ARG_OP,
  567. TEP_FILTER_ARG_NUM,
  568. TEP_FILTER_ARG_STR,
  569. };
  570. enum tep_filter_value_type {
  571. TEP_FILTER_NUMBER,
  572. TEP_FILTER_STRING,
  573. TEP_FILTER_CHAR
  574. };
  575. struct tep_filter_arg;
  576. struct tep_filter_arg_boolean {
  577. enum tep_filter_boolean_type value;
  578. };
  579. struct tep_filter_arg_field {
  580. struct tep_format_field *field;
  581. };
  582. struct tep_filter_arg_value {
  583. enum tep_filter_value_type type;
  584. union {
  585. char *str;
  586. unsigned long long val;
  587. };
  588. };
  589. struct tep_filter_arg_op {
  590. enum tep_filter_op_type type;
  591. struct tep_filter_arg *left;
  592. struct tep_filter_arg *right;
  593. };
  594. struct tep_filter_arg_exp {
  595. enum tep_filter_exp_type type;
  596. struct tep_filter_arg *left;
  597. struct tep_filter_arg *right;
  598. };
  599. struct tep_filter_arg_num {
  600. enum tep_filter_cmp_type type;
  601. struct tep_filter_arg *left;
  602. struct tep_filter_arg *right;
  603. };
  604. struct tep_filter_arg_str {
  605. enum tep_filter_cmp_type type;
  606. struct tep_format_field *field;
  607. char *val;
  608. char *buffer;
  609. regex_t reg;
  610. };
  611. struct tep_filter_arg {
  612. enum tep_filter_arg_type type;
  613. union {
  614. struct tep_filter_arg_boolean boolean;
  615. struct tep_filter_arg_field field;
  616. struct tep_filter_arg_value value;
  617. struct tep_filter_arg_op op;
  618. struct tep_filter_arg_exp exp;
  619. struct tep_filter_arg_num num;
  620. struct tep_filter_arg_str str;
  621. };
  622. };
  623. struct tep_filter_type {
  624. int event_id;
  625. struct tep_event_format *event;
  626. struct tep_filter_arg *filter;
  627. };
  628. #define TEP_FILTER_ERROR_BUFSZ 1024
  629. struct tep_event_filter {
  630. struct tep_handle *pevent;
  631. int filters;
  632. struct tep_filter_type *event_filters;
  633. char error_buffer[TEP_FILTER_ERROR_BUFSZ];
  634. };
  635. struct tep_event_filter *tep_filter_alloc(struct tep_handle *pevent);
  636. /* for backward compatibility */
  637. #define FILTER_NONE TEP_ERRNO__NO_FILTER
  638. #define FILTER_NOEXIST TEP_ERRNO__FILTER_NOT_FOUND
  639. #define FILTER_MISS TEP_ERRNO__FILTER_MISS
  640. #define FILTER_MATCH TEP_ERRNO__FILTER_MATCH
  641. enum tep_filter_trivial_type {
  642. TEP_FILTER_TRIVIAL_FALSE,
  643. TEP_FILTER_TRIVIAL_TRUE,
  644. TEP_FILTER_TRIVIAL_BOTH,
  645. };
  646. enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
  647. const char *filter_str);
  648. enum tep_errno tep_filter_match(struct tep_event_filter *filter,
  649. struct tep_record *record);
  650. int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
  651. char *buf, size_t buflen);
  652. int tep_event_filtered(struct tep_event_filter *filter,
  653. int event_id);
  654. void tep_filter_reset(struct tep_event_filter *filter);
  655. int tep_filter_clear_trivial(struct tep_event_filter *filter,
  656. enum tep_filter_trivial_type type);
  657. void tep_filter_free(struct tep_event_filter *filter);
  658. char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
  659. int tep_filter_remove_event(struct tep_event_filter *filter,
  660. int event_id);
  661. int tep_filter_event_has_trivial(struct tep_event_filter *filter,
  662. int event_id,
  663. enum tep_filter_trivial_type type);
  664. int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
  665. int tep_update_trivial(struct tep_event_filter *dest, struct tep_event_filter *source,
  666. enum tep_filter_trivial_type type);
  667. int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
  668. #endif /* _PARSE_EVENTS_H */