trace-event.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #ifndef _TRACE_EVENTS_H
  2. #define _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. };
  22. struct format_field {
  23. struct format_field *next;
  24. char *type;
  25. char *name;
  26. int offset;
  27. int size;
  28. unsigned long flags;
  29. };
  30. struct format {
  31. int nr_common;
  32. int nr_fields;
  33. struct format_field *common_fields;
  34. struct format_field *fields;
  35. };
  36. struct print_arg_atom {
  37. char *atom;
  38. };
  39. struct print_arg_string {
  40. char *string;
  41. };
  42. struct print_arg_field {
  43. char *name;
  44. struct format_field *field;
  45. };
  46. struct print_flag_sym {
  47. struct print_flag_sym *next;
  48. char *value;
  49. char *str;
  50. };
  51. struct print_arg_typecast {
  52. char *type;
  53. struct print_arg *item;
  54. };
  55. struct print_arg_flags {
  56. struct print_arg *field;
  57. char *delim;
  58. struct print_flag_sym *flags;
  59. };
  60. struct print_arg_symbol {
  61. struct print_arg *field;
  62. struct print_flag_sym *symbols;
  63. };
  64. struct print_arg;
  65. struct print_arg_op {
  66. char *op;
  67. int prio;
  68. struct print_arg *left;
  69. struct print_arg *right;
  70. };
  71. struct print_arg_func {
  72. char *name;
  73. struct print_arg *args;
  74. };
  75. enum print_arg_type {
  76. PRINT_NULL,
  77. PRINT_ATOM,
  78. PRINT_FIELD,
  79. PRINT_FLAGS,
  80. PRINT_SYMBOL,
  81. PRINT_TYPE,
  82. PRINT_STRING,
  83. PRINT_OP,
  84. };
  85. struct print_arg {
  86. struct print_arg *next;
  87. enum print_arg_type type;
  88. union {
  89. struct print_arg_atom atom;
  90. struct print_arg_field field;
  91. struct print_arg_typecast typecast;
  92. struct print_arg_flags flags;
  93. struct print_arg_symbol symbol;
  94. struct print_arg_func func;
  95. struct print_arg_string string;
  96. struct print_arg_op op;
  97. };
  98. };
  99. struct print_fmt {
  100. char *format;
  101. struct print_arg *args;
  102. };
  103. struct event {
  104. struct event *next;
  105. char *name;
  106. int id;
  107. int flags;
  108. struct format format;
  109. struct print_fmt print_fmt;
  110. };
  111. enum {
  112. EVENT_FL_ISFTRACE = 1,
  113. EVENT_FL_ISPRINT = 2,
  114. EVENT_FL_ISBPRINT = 4,
  115. EVENT_FL_ISFUNC = 8,
  116. EVENT_FL_ISFUNCENT = 16,
  117. EVENT_FL_ISFUNCRET = 32,
  118. };
  119. struct record {
  120. unsigned long long ts;
  121. int size;
  122. void *data;
  123. };
  124. struct record *trace_peek_data(int cpu);
  125. struct record *trace_read_data(int cpu);
  126. void parse_set_info(int nr_cpus, int long_sz);
  127. void trace_report(void);
  128. void *malloc_or_die(unsigned int size);
  129. void parse_cmdlines(char *file, int size);
  130. void parse_proc_kallsyms(char *file, unsigned int size);
  131. void parse_ftrace_printk(char *file, unsigned int size);
  132. void print_funcs(void);
  133. void print_printk(void);
  134. int parse_ftrace_file(char *buf, unsigned long size);
  135. int parse_event_file(char *buf, unsigned long size, char *system);
  136. void print_event(int cpu, void *data, int size, unsigned long long nsecs,
  137. char *comm);
  138. extern int file_bigendian;
  139. extern int host_bigendian;
  140. int bigendian(void);
  141. static inline unsigned short __data2host2(unsigned short data)
  142. {
  143. unsigned short swap;
  144. if (host_bigendian == file_bigendian)
  145. return data;
  146. swap = ((data & 0xffULL) << 8) |
  147. ((data & (0xffULL << 8)) >> 8);
  148. return swap;
  149. }
  150. static inline unsigned int __data2host4(unsigned int data)
  151. {
  152. unsigned int swap;
  153. if (host_bigendian == file_bigendian)
  154. return data;
  155. swap = ((data & 0xffULL) << 24) |
  156. ((data & (0xffULL << 8)) << 8) |
  157. ((data & (0xffULL << 16)) >> 8) |
  158. ((data & (0xffULL << 24)) >> 24);
  159. return swap;
  160. }
  161. static inline unsigned long long __data2host8(unsigned long long data)
  162. {
  163. unsigned long long swap;
  164. if (host_bigendian == file_bigendian)
  165. return data;
  166. swap = ((data & 0xffULL) << 56) |
  167. ((data & (0xffULL << 8)) << 40) |
  168. ((data & (0xffULL << 16)) << 24) |
  169. ((data & (0xffULL << 24)) << 8) |
  170. ((data & (0xffULL << 32)) >> 8) |
  171. ((data & (0xffULL << 40)) >> 24) |
  172. ((data & (0xffULL << 48)) >> 40) |
  173. ((data & (0xffULL << 56)) >> 56);
  174. return swap;
  175. }
  176. #define data2host2(ptr) __data2host2(*(unsigned short *)ptr)
  177. #define data2host4(ptr) __data2host4(*(unsigned int *)ptr)
  178. #define data2host8(ptr) __data2host8(*(unsigned long long *)ptr)
  179. extern int header_page_ts_offset;
  180. extern int header_page_ts_size;
  181. extern int header_page_size_offset;
  182. extern int header_page_size_size;
  183. extern int header_page_data_offset;
  184. extern int header_page_data_size;
  185. int parse_header_page(char *buf, unsigned long size);
  186. void read_tracing_data(struct perf_counter_attr *pattrs, int nb_counters);
  187. #endif /* _TRACE_EVENTS_H */