event.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. /*
  8. * PERF_SAMPLE_IP | PERF_SAMPLE_TID | *
  9. */
  10. struct ip_event {
  11. struct perf_event_header header;
  12. u64 ip;
  13. u32 pid, tid;
  14. unsigned char __more_data[];
  15. };
  16. struct mmap_event {
  17. struct perf_event_header header;
  18. u32 pid, tid;
  19. u64 start;
  20. u64 len;
  21. u64 pgoff;
  22. char filename[PATH_MAX];
  23. };
  24. struct comm_event {
  25. struct perf_event_header header;
  26. u32 pid, tid;
  27. char comm[16];
  28. };
  29. struct fork_event {
  30. struct perf_event_header header;
  31. u32 pid, ppid;
  32. u32 tid, ptid;
  33. u64 time;
  34. };
  35. struct lost_event {
  36. struct perf_event_header header;
  37. u64 id;
  38. u64 lost;
  39. };
  40. /*
  41. * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
  42. */
  43. struct read_event {
  44. struct perf_event_header header;
  45. u32 pid, tid;
  46. u64 value;
  47. u64 time_enabled;
  48. u64 time_running;
  49. u64 id;
  50. };
  51. #define PERF_SAMPLE_MASK \
  52. (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
  53. PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
  54. PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
  55. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
  56. struct sample_event {
  57. struct perf_event_header header;
  58. u64 array[];
  59. };
  60. struct perf_sample {
  61. u64 ip;
  62. u32 pid, tid;
  63. u64 time;
  64. u64 addr;
  65. u64 id;
  66. u64 stream_id;
  67. u64 period;
  68. u32 cpu;
  69. u32 raw_size;
  70. void *raw_data;
  71. struct ip_callchain *callchain;
  72. struct branch_stack *branch_stack;
  73. };
  74. #define BUILD_ID_SIZE 20
  75. struct build_id_event {
  76. struct perf_event_header header;
  77. pid_t pid;
  78. u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  79. char filename[];
  80. };
  81. enum perf_user_event_type { /* above any possible kernel type */
  82. PERF_RECORD_USER_TYPE_START = 64,
  83. PERF_RECORD_HEADER_ATTR = 64,
  84. PERF_RECORD_HEADER_EVENT_TYPE = 65,
  85. PERF_RECORD_HEADER_TRACING_DATA = 66,
  86. PERF_RECORD_HEADER_BUILD_ID = 67,
  87. PERF_RECORD_FINISHED_ROUND = 68,
  88. PERF_RECORD_HEADER_MAX
  89. };
  90. struct attr_event {
  91. struct perf_event_header header;
  92. struct perf_event_attr attr;
  93. u64 id[];
  94. };
  95. #define MAX_EVENT_NAME 64
  96. struct perf_trace_event_type {
  97. u64 event_id;
  98. char name[MAX_EVENT_NAME];
  99. };
  100. struct event_type_event {
  101. struct perf_event_header header;
  102. struct perf_trace_event_type event_type;
  103. };
  104. struct tracing_data_event {
  105. struct perf_event_header header;
  106. u32 size;
  107. };
  108. union perf_event {
  109. struct perf_event_header header;
  110. struct ip_event ip;
  111. struct mmap_event mmap;
  112. struct comm_event comm;
  113. struct fork_event fork;
  114. struct lost_event lost;
  115. struct read_event read;
  116. struct sample_event sample;
  117. struct attr_event attr;
  118. struct event_type_event event_type;
  119. struct tracing_data_event tracing_data;
  120. struct build_id_event build_id;
  121. };
  122. void perf_event__print_totals(void);
  123. struct perf_tool;
  124. struct thread_map;
  125. typedef int (*perf_event__handler_t)(struct perf_tool *tool,
  126. union perf_event *event,
  127. struct perf_sample *sample,
  128. struct machine *machine);
  129. int perf_event__synthesize_thread_map(struct perf_tool *tool,
  130. struct thread_map *threads,
  131. perf_event__handler_t process,
  132. struct machine *machine);
  133. int perf_event__synthesize_threads(struct perf_tool *tool,
  134. perf_event__handler_t process,
  135. struct machine *machine);
  136. int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
  137. perf_event__handler_t process,
  138. struct machine *machine,
  139. const char *symbol_name);
  140. int perf_event__synthesize_modules(struct perf_tool *tool,
  141. perf_event__handler_t process,
  142. struct machine *machine);
  143. int perf_event__process_comm(struct perf_tool *tool,
  144. union perf_event *event,
  145. struct perf_sample *sample,
  146. struct machine *machine);
  147. int perf_event__process_lost(struct perf_tool *tool,
  148. union perf_event *event,
  149. struct perf_sample *sample,
  150. struct machine *machine);
  151. int perf_event__process_mmap(struct perf_tool *tool,
  152. union perf_event *event,
  153. struct perf_sample *sample,
  154. struct machine *machine);
  155. int perf_event__process_task(struct perf_tool *tool,
  156. union perf_event *event,
  157. struct perf_sample *sample,
  158. struct machine *machine);
  159. int perf_event__process(struct perf_tool *tool,
  160. union perf_event *event,
  161. struct perf_sample *sample,
  162. struct machine *machine);
  163. struct addr_location;
  164. int perf_event__preprocess_sample(const union perf_event *self,
  165. struct machine *machine,
  166. struct addr_location *al,
  167. struct perf_sample *sample,
  168. symbol_filter_t filter);
  169. const char *perf_event__name(unsigned int id);
  170. int perf_event__parse_sample(const union perf_event *event, u64 type,
  171. int sample_size, bool sample_id_all,
  172. struct perf_sample *sample, bool swapped);
  173. int perf_event__synthesize_sample(union perf_event *event, u64 type,
  174. const struct perf_sample *sample,
  175. bool swapped);
  176. size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
  177. size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
  178. size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
  179. size_t perf_event__fprintf(union perf_event *event, FILE *fp);
  180. #endif /* __PERF_RECORD_H */