trace-event.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #ifndef __PERF_TRACE_EVENTS_H
  2. #define __PERF_TRACE_EVENTS_H
  3. #include <stdbool.h>
  4. #include "parse-events.h"
  5. #include "session.h"
  6. #define __unused __attribute__((unused))
  7. #ifndef PAGE_MASK
  8. #define PAGE_MASK (page_size - 1)
  9. #endif
  10. enum {
  11. RINGBUF_TYPE_PADDING = 29,
  12. RINGBUF_TYPE_TIME_EXTEND = 30,
  13. RINGBUF_TYPE_TIME_STAMP = 31,
  14. };
  15. #ifndef TS_SHIFT
  16. #define TS_SHIFT 27
  17. #endif
  18. #define NSECS_PER_SEC 1000000000ULL
  19. #define NSECS_PER_USEC 1000ULL
  20. enum format_flags {
  21. FIELD_IS_ARRAY = 1,
  22. FIELD_IS_POINTER = 2,
  23. FIELD_IS_SIGNED = 4,
  24. FIELD_IS_STRING = 8,
  25. FIELD_IS_DYNAMIC = 16,
  26. FIELD_IS_FLAG = 32,
  27. FIELD_IS_SYMBOLIC = 64,
  28. };
  29. struct format_field {
  30. struct format_field *next;
  31. char *type;
  32. char *name;
  33. int offset;
  34. int size;
  35. unsigned long flags;
  36. };
  37. struct format {
  38. int nr_common;
  39. int nr_fields;
  40. struct format_field *common_fields;
  41. struct format_field *fields;
  42. };
  43. struct print_arg_atom {
  44. char *atom;
  45. };
  46. struct print_arg_string {
  47. char *string;
  48. int offset;
  49. };
  50. struct print_arg_field {
  51. char *name;
  52. struct format_field *field;
  53. };
  54. struct print_flag_sym {
  55. struct print_flag_sym *next;
  56. char *value;
  57. char *str;
  58. };
  59. struct print_arg_typecast {
  60. char *type;
  61. struct print_arg *item;
  62. };
  63. struct print_arg_flags {
  64. struct print_arg *field;
  65. char *delim;
  66. struct print_flag_sym *flags;
  67. };
  68. struct print_arg_symbol {
  69. struct print_arg *field;
  70. struct print_flag_sym *symbols;
  71. };
  72. struct print_arg;
  73. struct print_arg_op {
  74. char *op;
  75. int prio;
  76. struct print_arg *left;
  77. struct print_arg *right;
  78. };
  79. struct print_arg_func {
  80. char *name;
  81. struct print_arg *args;
  82. };
  83. enum print_arg_type {
  84. PRINT_NULL,
  85. PRINT_ATOM,
  86. PRINT_FIELD,
  87. PRINT_FLAGS,
  88. PRINT_SYMBOL,
  89. PRINT_TYPE,
  90. PRINT_STRING,
  91. PRINT_OP,
  92. };
  93. struct print_arg {
  94. struct print_arg *next;
  95. enum print_arg_type type;
  96. union {
  97. struct print_arg_atom atom;
  98. struct print_arg_field field;
  99. struct print_arg_typecast typecast;
  100. struct print_arg_flags flags;
  101. struct print_arg_symbol symbol;
  102. struct print_arg_func func;
  103. struct print_arg_string string;
  104. struct print_arg_op op;
  105. };
  106. };
  107. struct print_fmt {
  108. char *format;
  109. struct print_arg *args;
  110. };
  111. struct event {
  112. struct event *next;
  113. char *name;
  114. int id;
  115. int flags;
  116. struct format format;
  117. struct print_fmt print_fmt;
  118. char *system;
  119. };
  120. enum {
  121. EVENT_FL_ISFTRACE = 0x01,
  122. EVENT_FL_ISPRINT = 0x02,
  123. EVENT_FL_ISBPRINT = 0x04,
  124. EVENT_FL_ISFUNC = 0x08,
  125. EVENT_FL_ISFUNCENT = 0x10,
  126. EVENT_FL_ISFUNCRET = 0x20,
  127. EVENT_FL_FAILED = 0x80000000
  128. };
  129. struct record {
  130. unsigned long long ts;
  131. int size;
  132. void *data;
  133. };
  134. struct record *trace_peek_data(int cpu);
  135. struct record *trace_read_data(int cpu);
  136. void parse_set_info(int nr_cpus, int long_sz);
  137. ssize_t trace_report(int fd, bool repipe);
  138. void *malloc_or_die(unsigned int size);
  139. void parse_cmdlines(char *file, int size);
  140. void parse_proc_kallsyms(char *file, unsigned int size);
  141. void parse_ftrace_printk(char *file, unsigned int size);
  142. void print_funcs(void);
  143. void print_printk(void);
  144. int parse_ftrace_file(char *buf, unsigned long size);
  145. int parse_event_file(char *buf, unsigned long size, char *sys);
  146. void print_trace_event(int cpu, void *data, int size);
  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 list_head *pattrs);
  213. ssize_t read_tracing_data_size(int fd, struct list_head *pattrs);
  214. /* taken from kernel/trace/trace.h */
  215. enum trace_flag_type {
  216. TRACE_FLAG_IRQS_OFF = 0x01,
  217. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  218. TRACE_FLAG_NEED_RESCHED = 0x04,
  219. TRACE_FLAG_HARDIRQ = 0x08,
  220. TRACE_FLAG_SOFTIRQ = 0x10,
  221. };
  222. struct scripting_ops {
  223. const char *name;
  224. int (*start_script) (const char *script, int argc, const char **argv);
  225. int (*stop_script) (void);
  226. void (*process_event) (union perf_event *event,
  227. struct perf_sample *sample,
  228. struct perf_evsel *evsel,
  229. struct perf_session *session,
  230. struct thread *thread);
  231. int (*generate_script) (const char *outfile);
  232. };
  233. int script_spec_register(const char *spec, struct scripting_ops *ops);
  234. void setup_perl_scripting(void);
  235. void setup_python_scripting(void);
  236. struct scripting_context {
  237. void *event_data;
  238. };
  239. int common_pc(struct scripting_context *context);
  240. int common_flags(struct scripting_context *context);
  241. int common_lock_depth(struct scripting_context *context);
  242. #endif /* __PERF_TRACE_EVENTS_H */