event.h 6.2 KB

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