trace-event.h 5.9 KB

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