trace-event.h 6.6 KB

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