event.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #ifndef __PERF_RECORD_H
  2. #define __PERF_RECORD_H
  3. #include <limits.h>
  4. #include <stdio.h>
  5. #include "../perf.h"
  6. #include "map.h"
  7. #include "build-id.h"
  8. struct mmap_event {
  9. struct perf_event_header header;
  10. u32 pid, tid;
  11. u64 start;
  12. u64 len;
  13. u64 pgoff;
  14. char filename[PATH_MAX];
  15. };
  16. struct mmap2_event {
  17. struct perf_event_header header;
  18. u32 pid, tid;
  19. u64 start;
  20. u64 len;
  21. u64 pgoff;
  22. u32 maj;
  23. u32 min;
  24. u64 ino;
  25. u64 ino_generation;
  26. char filename[PATH_MAX];
  27. };
  28. struct comm_event {
  29. struct perf_event_header header;
  30. u32 pid, tid;
  31. char comm[16];
  32. };
  33. struct fork_event {
  34. struct perf_event_header header;
  35. u32 pid, ppid;
  36. u32 tid, ptid;
  37. u64 time;
  38. };
  39. struct lost_event {
  40. struct perf_event_header header;
  41. u64 id;
  42. u64 lost;
  43. };
  44. /*
  45. * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
  46. */
  47. struct read_event {
  48. struct perf_event_header header;
  49. u32 pid, tid;
  50. u64 value;
  51. u64 time_enabled;
  52. u64 time_running;
  53. u64 id;
  54. };
  55. #define PERF_SAMPLE_MASK \
  56. (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
  57. PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
  58. PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
  59. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
  60. PERF_SAMPLE_IDENTIFIER)
  61. struct sample_event {
  62. struct perf_event_header header;
  63. u64 array[];
  64. };
  65. struct regs_dump {
  66. u64 abi;
  67. u64 *regs;
  68. };
  69. struct stack_dump {
  70. u16 offset;
  71. u64 size;
  72. char *data;
  73. };
  74. struct sample_read_value {
  75. u64 value;
  76. u64 id;
  77. };
  78. struct sample_read {
  79. u64 time_enabled;
  80. u64 time_running;
  81. union {
  82. struct {
  83. u64 nr;
  84. struct sample_read_value *values;
  85. } group;
  86. struct sample_read_value one;
  87. };
  88. };
  89. struct perf_sample {
  90. u64 ip;
  91. u32 pid, tid;
  92. u64 time;
  93. u64 addr;
  94. u64 id;
  95. u64 stream_id;
  96. u64 period;
  97. u64 weight;
  98. u32 cpu;
  99. u32 raw_size;
  100. u64 data_src;
  101. void *raw_data;
  102. struct ip_callchain *callchain;
  103. struct branch_stack *branch_stack;
  104. struct regs_dump user_regs;
  105. struct stack_dump user_stack;
  106. struct sample_read read;
  107. };
  108. #define PERF_MEM_DATA_SRC_NONE \
  109. (PERF_MEM_S(OP, NA) |\
  110. PERF_MEM_S(LVL, NA) |\
  111. PERF_MEM_S(SNOOP, NA) |\
  112. PERF_MEM_S(LOCK, NA) |\
  113. PERF_MEM_S(TLB, NA))
  114. struct build_id_event {
  115. struct perf_event_header header;
  116. pid_t pid;
  117. u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  118. char filename[];
  119. };
  120. enum perf_user_event_type { /* above any possible kernel type */
  121. PERF_RECORD_USER_TYPE_START = 64,
  122. PERF_RECORD_HEADER_ATTR = 64,
  123. PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
  124. PERF_RECORD_HEADER_TRACING_DATA = 66,
  125. PERF_RECORD_HEADER_BUILD_ID = 67,
  126. PERF_RECORD_FINISHED_ROUND = 68,
  127. PERF_RECORD_HEADER_MAX
  128. };
  129. struct attr_event {
  130. struct perf_event_header header;
  131. struct perf_event_attr attr;
  132. u64 id[];
  133. };
  134. #define MAX_EVENT_NAME 64
  135. struct perf_trace_event_type {
  136. u64 event_id;
  137. char name[MAX_EVENT_NAME];
  138. };
  139. struct event_type_event {
  140. struct perf_event_header header;
  141. struct perf_trace_event_type event_type;
  142. };
  143. struct tracing_data_event {
  144. struct perf_event_header header;
  145. u32 size;
  146. };
  147. union perf_event {
  148. struct perf_event_header header;
  149. struct mmap_event mmap;
  150. struct mmap2_event mmap2;
  151. struct comm_event comm;
  152. struct fork_event fork;
  153. struct lost_event lost;
  154. struct read_event read;
  155. struct sample_event sample;
  156. struct attr_event attr;
  157. struct event_type_event event_type;
  158. struct tracing_data_event tracing_data;
  159. struct build_id_event build_id;
  160. };
  161. void perf_event__print_totals(void);
  162. struct perf_tool;
  163. struct thread_map;
  164. typedef int (*perf_event__handler_t)(struct perf_tool *tool,
  165. union perf_event *event,
  166. struct perf_sample *sample,
  167. struct machine *machine);
  168. int perf_event__synthesize_thread_map(struct perf_tool *tool,
  169. struct thread_map *threads,
  170. perf_event__handler_t process,
  171. struct machine *machine);
  172. int perf_event__synthesize_threads(struct perf_tool *tool,
  173. perf_event__handler_t process,
  174. struct machine *machine);
  175. int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
  176. perf_event__handler_t process,
  177. struct machine *machine,
  178. const char *symbol_name);
  179. int perf_event__synthesize_modules(struct perf_tool *tool,
  180. perf_event__handler_t process,
  181. struct machine *machine);
  182. int perf_event__process_comm(struct perf_tool *tool,
  183. union perf_event *event,
  184. struct perf_sample *sample,
  185. struct machine *machine);
  186. int perf_event__process_lost(struct perf_tool *tool,
  187. union perf_event *event,
  188. struct perf_sample *sample,
  189. struct machine *machine);
  190. int perf_event__process_mmap(struct perf_tool *tool,
  191. union perf_event *event,
  192. struct perf_sample *sample,
  193. struct machine *machine);
  194. int perf_event__process_mmap2(struct perf_tool *tool,
  195. union perf_event *event,
  196. struct perf_sample *sample,
  197. struct machine *machine);
  198. int perf_event__process_fork(struct perf_tool *tool,
  199. union perf_event *event,
  200. struct perf_sample *sample,
  201. struct machine *machine);
  202. int perf_event__process_exit(struct perf_tool *tool,
  203. union perf_event *event,
  204. struct perf_sample *sample,
  205. struct machine *machine);
  206. int perf_event__process(struct perf_tool *tool,
  207. union perf_event *event,
  208. struct perf_sample *sample,
  209. struct machine *machine);
  210. struct addr_location;
  211. int perf_event__preprocess_sample(const union perf_event *self,
  212. struct machine *machine,
  213. struct addr_location *al,
  214. struct perf_sample *sample);
  215. const char *perf_event__name(unsigned int id);
  216. size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
  217. u64 sample_regs_user, u64 read_format);
  218. int perf_event__synthesize_sample(union perf_event *event, u64 type,
  219. u64 sample_regs_user, u64 read_format,
  220. const struct perf_sample *sample,
  221. bool swapped);
  222. size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
  223. size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
  224. size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
  225. size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
  226. size_t perf_event__fprintf(union perf_event *event, FILE *fp);
  227. #endif /* __PERF_RECORD_H */