trace-event.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #ifndef __PERF_TRACE_EVENTS_H
  2. #define __PERF_TRACE_EVENTS_H
  3. #include <stdbool.h>
  4. #include "parse-events.h"
  5. #define __unused __attribute__((unused))
  6. #ifndef PAGE_MASK
  7. #define PAGE_MASK (page_size - 1)
  8. #endif
  9. enum {
  10. RINGBUF_TYPE_PADDING = 29,
  11. RINGBUF_TYPE_TIME_EXTEND = 30,
  12. RINGBUF_TYPE_TIME_STAMP = 31,
  13. };
  14. #ifndef TS_SHIFT
  15. #define TS_SHIFT 27
  16. #endif
  17. #define NSECS_PER_SEC 1000000000ULL
  18. #define NSECS_PER_USEC 1000ULL
  19. enum format_flags {
  20. FIELD_IS_ARRAY = 1,
  21. FIELD_IS_POINTER = 2,
  22. FIELD_IS_SIGNED = 4,
  23. FIELD_IS_STRING = 8,
  24. FIELD_IS_DYNAMIC = 16,
  25. FIELD_IS_FLAG = 32,
  26. FIELD_IS_SYMBOLIC = 64,
  27. };
  28. struct format_field {
  29. struct format_field *next;
  30. char *type;
  31. char *name;
  32. int offset;
  33. int size;
  34. unsigned long flags;
  35. };
  36. struct format {
  37. int nr_common;
  38. int nr_fields;
  39. struct format_field *common_fields;
  40. struct format_field *fields;
  41. };
  42. struct print_arg_atom {
  43. char *atom;
  44. };
  45. struct print_arg_string {
  46. char *string;
  47. int offset;
  48. };
  49. struct print_arg_field {
  50. char *name;
  51. struct format_field *field;
  52. };
  53. struct print_flag_sym {
  54. struct print_flag_sym *next;
  55. char *value;
  56. char *str;
  57. };
  58. struct print_arg_typecast {
  59. char *type;
  60. struct print_arg *item;
  61. };
  62. struct print_arg_flags {
  63. struct print_arg *field;
  64. char *delim;
  65. struct print_flag_sym *flags;
  66. };
  67. struct print_arg_symbol {
  68. struct print_arg *field;
  69. struct print_flag_sym *symbols;
  70. };
  71. struct print_arg;
  72. struct print_arg_op {
  73. char *op;
  74. int prio;
  75. struct print_arg *left;
  76. struct print_arg *right;
  77. };
  78. struct print_arg_func {
  79. char *name;
  80. struct print_arg *args;
  81. };
  82. enum print_arg_type {
  83. PRINT_NULL,
  84. PRINT_ATOM,
  85. PRINT_FIELD,
  86. PRINT_FLAGS,
  87. PRINT_SYMBOL,
  88. PRINT_TYPE,
  89. PRINT_STRING,
  90. PRINT_OP,
  91. };
  92. struct print_arg {
  93. struct print_arg *next;
  94. enum print_arg_type type;
  95. union {
  96. struct print_arg_atom atom;
  97. struct print_arg_field field;
  98. struct print_arg_typecast typecast;
  99. struct print_arg_flags flags;
  100. struct print_arg_symbol symbol;
  101. struct print_arg_func func;
  102. struct print_arg_string string;
  103. struct print_arg_op op;
  104. };
  105. };
  106. struct print_fmt {
  107. char *format;
  108. struct print_arg *args;
  109. };
  110. struct event {
  111. struct event *next;
  112. char *name;
  113. int id;
  114. int flags;
  115. struct format format;
  116. struct print_fmt print_fmt;
  117. char *system;
  118. };
  119. enum {
  120. EVENT_FL_ISFTRACE = 0x01,
  121. EVENT_FL_ISPRINT = 0x02,
  122. EVENT_FL_ISBPRINT = 0x04,
  123. EVENT_FL_ISFUNC = 0x08,
  124. EVENT_FL_ISFUNCENT = 0x10,
  125. EVENT_FL_ISFUNCRET = 0x20,
  126. EVENT_FL_FAILED = 0x80000000
  127. };
  128. struct record {
  129. unsigned long long ts;
  130. int size;
  131. void *data;
  132. };
  133. struct record *trace_peek_data(int cpu);
  134. struct record *trace_read_data(int cpu);
  135. void parse_set_info(int nr_cpus, int long_sz);
  136. ssize_t trace_report(int fd, bool repipe);
  137. void *malloc_or_die(unsigned int size);
  138. void parse_cmdlines(char *file, int size);
  139. void parse_proc_kallsyms(char *file, unsigned int size);
  140. void parse_ftrace_printk(char *file, unsigned int size);
  141. void print_funcs(void);
  142. void print_printk(void);
  143. int parse_ftrace_file(char *buf, unsigned long size);
  144. int parse_event_file(char *buf, unsigned long size, char *sys);
  145. void print_event(int cpu, void *data, int size, unsigned long long nsecs,
  146. char *comm);
  147. extern int file_bigendian;
  148. extern int host_bigendian;
  149. int bigendian(void);
  150. static inline unsigned short __data2host2(unsigned short data)
  151. {
  152. unsigned short swap;
  153. if (host_bigendian == file_bigendian)
  154. return data;
  155. swap = ((data & 0xffULL) << 8) |
  156. ((data & (0xffULL << 8)) >> 8);
  157. return swap;
  158. }
  159. static inline unsigned int __data2host4(unsigned int data)
  160. {
  161. unsigned int swap;
  162. if (host_bigendian == file_bigendian)
  163. return data;
  164. swap = ((data & 0xffULL) << 24) |
  165. ((data & (0xffULL << 8)) << 8) |
  166. ((data & (0xffULL << 16)) >> 8) |
  167. ((data & (0xffULL << 24)) >> 24);
  168. return swap;
  169. }
  170. static inline unsigned long long __data2host8(unsigned long long data)
  171. {
  172. unsigned long long swap;
  173. if (host_bigendian == file_bigendian)
  174. return data;
  175. swap = ((data & 0xffULL) << 56) |
  176. ((data & (0xffULL << 8)) << 40) |
  177. ((data & (0xffULL << 16)) << 24) |
  178. ((data & (0xffULL << 24)) << 8) |
  179. ((data & (0xffULL << 32)) >> 8) |
  180. ((data & (0xffULL << 40)) >> 24) |
  181. ((data & (0xffULL << 48)) >> 40) |
  182. ((data & (0xffULL << 56)) >> 56);
  183. return swap;
  184. }
  185. #define data2host2(ptr) __data2host2(*(unsigned short *)ptr)
  186. #define data2host4(ptr) __data2host4(*(unsigned int *)ptr)
  187. #define data2host8(ptr) ({ \
  188. unsigned long long __val; \
  189. \
  190. memcpy(&__val, (ptr), sizeof(unsigned long long)); \
  191. __data2host8(__val); \
  192. })
  193. extern int header_page_ts_offset;
  194. extern int header_page_ts_size;
  195. extern int header_page_size_offset;
  196. extern int header_page_size_size;
  197. extern int header_page_data_offset;
  198. extern int header_page_data_size;
  199. extern bool latency_format;
  200. int trace_parse_common_type(void *data);
  201. int trace_parse_common_pid(void *data);
  202. int parse_common_pc(void *data);
  203. int parse_common_flags(void *data);
  204. int parse_common_lock_depth(void *data);
  205. struct event *trace_find_event(int id);
  206. struct event *trace_find_next_event(struct event *event);
  207. unsigned long long read_size(void *ptr, int size);
  208. unsigned long long
  209. raw_field_value(struct event *event, const char *name, void *data);
  210. void *raw_field_ptr(struct event *event, const char *name, void *data);
  211. unsigned long long eval_flag(const char *flag);
  212. int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events);
  213. ssize_t read_tracing_data_size(int fd, struct perf_event_attr *pattrs,
  214. int nb_events);
  215. /* taken from kernel/trace/trace.h */
  216. enum trace_flag_type {
  217. TRACE_FLAG_IRQS_OFF = 0x01,
  218. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  219. TRACE_FLAG_NEED_RESCHED = 0x04,
  220. TRACE_FLAG_HARDIRQ = 0x08,
  221. TRACE_FLAG_SOFTIRQ = 0x10,
  222. };
  223. struct scripting_ops {
  224. const char *name;
  225. int (*start_script) (const char *script, int argc, const char **argv);
  226. int (*stop_script) (void);
  227. void (*process_event) (int cpu, void *data, int size,
  228. unsigned long long nsecs, char *comm);
  229. int (*generate_script) (const char *outfile);
  230. };
  231. int script_spec_register(const char *spec, struct scripting_ops *ops);
  232. void setup_perl_scripting(void);
  233. void setup_python_scripting(void);
  234. struct scripting_context {
  235. void *event_data;
  236. };
  237. int common_pc(struct scripting_context *context);
  238. int common_flags(struct scripting_context *context);
  239. int common_lock_depth(struct scripting_context *context);
  240. #endif /* __PERF_TRACE_EVENTS_H */