event.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 mask;
  76. u64 *regs;
  77. };
  78. struct stack_dump {
  79. u16 offset;
  80. u64 size;
  81. char *data;
  82. };
  83. struct sample_read_value {
  84. u64 value;
  85. u64 id;
  86. };
  87. struct sample_read {
  88. u64 time_enabled;
  89. u64 time_running;
  90. union {
  91. struct {
  92. u64 nr;
  93. struct sample_read_value *values;
  94. } group;
  95. struct sample_read_value one;
  96. };
  97. };
  98. struct perf_sample {
  99. u64 ip;
  100. u32 pid, tid;
  101. u64 time;
  102. u64 addr;
  103. u64 id;
  104. u64 stream_id;
  105. u64 period;
  106. u64 weight;
  107. u64 transaction;
  108. u32 cpu;
  109. u32 raw_size;
  110. u64 data_src;
  111. void *raw_data;
  112. struct ip_callchain *callchain;
  113. struct branch_stack *branch_stack;
  114. struct regs_dump user_regs;
  115. struct stack_dump user_stack;
  116. struct sample_read read;
  117. };
  118. #define PERF_MEM_DATA_SRC_NONE \
  119. (PERF_MEM_S(OP, NA) |\
  120. PERF_MEM_S(LVL, NA) |\
  121. PERF_MEM_S(SNOOP, NA) |\
  122. PERF_MEM_S(LOCK, NA) |\
  123. PERF_MEM_S(TLB, NA))
  124. struct build_id_event {
  125. struct perf_event_header header;
  126. pid_t pid;
  127. u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  128. char filename[];
  129. };
  130. enum perf_user_event_type { /* above any possible kernel type */
  131. PERF_RECORD_USER_TYPE_START = 64,
  132. PERF_RECORD_HEADER_ATTR = 64,
  133. PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
  134. PERF_RECORD_HEADER_TRACING_DATA = 66,
  135. PERF_RECORD_HEADER_BUILD_ID = 67,
  136. PERF_RECORD_FINISHED_ROUND = 68,
  137. PERF_RECORD_HEADER_MAX
  138. };
  139. struct attr_event {
  140. struct perf_event_header header;
  141. struct perf_event_attr attr;
  142. u64 id[];
  143. };
  144. #define MAX_EVENT_NAME 64
  145. struct perf_trace_event_type {
  146. u64 event_id;
  147. char name[MAX_EVENT_NAME];
  148. };
  149. struct event_type_event {
  150. struct perf_event_header header;
  151. struct perf_trace_event_type event_type;
  152. };
  153. struct tracing_data_event {
  154. struct perf_event_header header;
  155. u32 size;
  156. };
  157. union perf_event {
  158. struct perf_event_header header;
  159. struct mmap_event mmap;
  160. struct mmap2_event mmap2;
  161. struct comm_event comm;
  162. struct fork_event fork;
  163. struct lost_event lost;
  164. struct read_event read;
  165. struct throttle_event throttle;
  166. struct sample_event sample;
  167. struct attr_event attr;
  168. struct event_type_event event_type;
  169. struct tracing_data_event tracing_data;
  170. struct build_id_event build_id;
  171. };
  172. void perf_event__print_totals(void);
  173. struct perf_tool;
  174. struct thread_map;
  175. typedef int (*perf_event__handler_t)(struct perf_tool *tool,
  176. union perf_event *event,
  177. struct perf_sample *sample,
  178. struct machine *machine);
  179. int perf_event__synthesize_thread_map(struct perf_tool *tool,
  180. struct thread_map *threads,
  181. perf_event__handler_t process,
  182. struct machine *machine, bool mmap_data);
  183. int perf_event__synthesize_threads(struct perf_tool *tool,
  184. perf_event__handler_t process,
  185. struct machine *machine, bool mmap_data);
  186. int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
  187. perf_event__handler_t process,
  188. struct machine *machine);
  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 read_format);
  228. int perf_event__synthesize_sample(union perf_event *event, u64 type,
  229. u64 read_format,
  230. const struct perf_sample *sample,
  231. bool swapped);
  232. int perf_event__synthesize_mmap_events(struct perf_tool *tool,
  233. union perf_event *event,
  234. pid_t pid, pid_t tgid,
  235. perf_event__handler_t process,
  236. struct machine *machine,
  237. bool mmap_data);
  238. size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
  239. size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
  240. size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
  241. size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
  242. size_t perf_event__fprintf(union perf_event *event, FILE *fp);
  243. u64 kallsyms__get_function_start(const char *kallsyms_filename,
  244. const char *symbol_name);
  245. #endif /* __PERF_RECORD_H */