event.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. struct throttle_event {
  56. struct perf_event_header header;
  57. u64 time;
  58. u64 id;
  59. u64 stream_id;
  60. };
  61. #define PERF_SAMPLE_MASK \
  62. (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
  63. PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
  64. PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
  65. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
  66. PERF_SAMPLE_IDENTIFIER)
  67. /* perf sample has 16 bits size limit */
  68. #define PERF_SAMPLE_MAX_SIZE (1 << 16)
  69. struct sample_event {
  70. struct perf_event_header header;
  71. u64 array[];
  72. };
  73. struct regs_dump {
  74. u64 abi;
  75. u64 *regs;
  76. };
  77. struct stack_dump {
  78. u16 offset;
  79. u64 size;
  80. char *data;
  81. };
  82. struct sample_read_value {
  83. u64 value;
  84. u64 id;
  85. };
  86. struct sample_read {
  87. u64 time_enabled;
  88. u64 time_running;
  89. union {
  90. struct {
  91. u64 nr;
  92. struct sample_read_value *values;
  93. } group;
  94. struct sample_read_value one;
  95. };
  96. };
  97. struct perf_sample {
  98. u64 ip;
  99. u32 pid, tid;
  100. u64 time;
  101. u64 addr;
  102. u64 id;
  103. u64 stream_id;
  104. u64 period;
  105. u64 weight;
  106. u64 transaction;
  107. u32 cpu;
  108. u32 raw_size;
  109. u64 data_src;
  110. void *raw_data;
  111. struct ip_callchain *callchain;
  112. struct branch_stack *branch_stack;
  113. struct regs_dump user_regs;
  114. struct stack_dump user_stack;
  115. struct sample_read read;
  116. };
  117. #define PERF_MEM_DATA_SRC_NONE \
  118. (PERF_MEM_S(OP, NA) |\
  119. PERF_MEM_S(LVL, NA) |\
  120. PERF_MEM_S(SNOOP, NA) |\
  121. PERF_MEM_S(LOCK, NA) |\
  122. PERF_MEM_S(TLB, NA))
  123. struct build_id_event {
  124. struct perf_event_header header;
  125. pid_t pid;
  126. u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  127. char filename[];
  128. };
  129. enum perf_user_event_type { /* above any possible kernel type */
  130. PERF_RECORD_USER_TYPE_START = 64,
  131. PERF_RECORD_HEADER_ATTR = 64,
  132. PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
  133. PERF_RECORD_HEADER_TRACING_DATA = 66,
  134. PERF_RECORD_HEADER_BUILD_ID = 67,
  135. PERF_RECORD_FINISHED_ROUND = 68,
  136. PERF_RECORD_HEADER_MAX
  137. };
  138. struct attr_event {
  139. struct perf_event_header header;
  140. struct perf_event_attr attr;
  141. u64 id[];
  142. };
  143. #define MAX_EVENT_NAME 64
  144. struct perf_trace_event_type {
  145. u64 event_id;
  146. char name[MAX_EVENT_NAME];
  147. };
  148. struct event_type_event {
  149. struct perf_event_header header;
  150. struct perf_trace_event_type event_type;
  151. };
  152. struct tracing_data_event {
  153. struct perf_event_header header;
  154. u32 size;
  155. };
  156. union perf_event {
  157. struct perf_event_header header;
  158. struct mmap_event mmap;
  159. struct mmap2_event mmap2;
  160. struct comm_event comm;
  161. struct fork_event fork;
  162. struct lost_event lost;
  163. struct read_event read;
  164. struct throttle_event throttle;
  165. struct sample_event sample;
  166. struct attr_event attr;
  167. struct event_type_event event_type;
  168. struct tracing_data_event tracing_data;
  169. struct build_id_event build_id;
  170. };
  171. void perf_event__print_totals(void);
  172. struct perf_tool;
  173. struct thread_map;
  174. typedef int (*perf_event__handler_t)(struct perf_tool *tool,
  175. union perf_event *event,
  176. struct perf_sample *sample,
  177. struct machine *machine);
  178. int perf_event__synthesize_thread_map(struct perf_tool *tool,
  179. struct thread_map *threads,
  180. perf_event__handler_t process,
  181. struct machine *machine, bool mmap_data);
  182. int perf_event__synthesize_threads(struct perf_tool *tool,
  183. perf_event__handler_t process,
  184. struct machine *machine, bool mmap_data);
  185. int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
  186. perf_event__handler_t process,
  187. struct machine *machine,
  188. const char *symbol_name);
  189. int perf_event__synthesize_modules(struct perf_tool *tool,
  190. perf_event__handler_t process,
  191. struct machine *machine);
  192. int perf_event__process_comm(struct perf_tool *tool,
  193. union perf_event *event,
  194. struct perf_sample *sample,
  195. struct machine *machine);
  196. int perf_event__process_lost(struct perf_tool *tool,
  197. union perf_event *event,
  198. struct perf_sample *sample,
  199. struct machine *machine);
  200. int perf_event__process_mmap(struct perf_tool *tool,
  201. union perf_event *event,
  202. struct perf_sample *sample,
  203. struct machine *machine);
  204. int perf_event__process_mmap2(struct perf_tool *tool,
  205. union perf_event *event,
  206. struct perf_sample *sample,
  207. struct machine *machine);
  208. int perf_event__process_fork(struct perf_tool *tool,
  209. union perf_event *event,
  210. struct perf_sample *sample,
  211. struct machine *machine);
  212. int perf_event__process_exit(struct perf_tool *tool,
  213. union perf_event *event,
  214. struct perf_sample *sample,
  215. struct machine *machine);
  216. int perf_event__process(struct perf_tool *tool,
  217. union perf_event *event,
  218. struct perf_sample *sample,
  219. struct machine *machine);
  220. struct addr_location;
  221. int perf_event__preprocess_sample(const union perf_event *event,
  222. struct machine *machine,
  223. struct addr_location *al,
  224. struct perf_sample *sample);
  225. const char *perf_event__name(unsigned int id);
  226. size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
  227. u64 sample_regs_user, u64 read_format);
  228. int perf_event__synthesize_sample(union perf_event *event, u64 type,
  229. u64 sample_regs_user, u64 read_format,
  230. const struct perf_sample *sample,
  231. bool swapped);
  232. size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
  233. size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
  234. size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
  235. size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
  236. size_t perf_event__fprintf(union perf_event *event, FILE *fp);
  237. #endif /* __PERF_RECORD_H */