event.h 5.6 KB

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