event.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. };
  73. #define BUILD_ID_SIZE 20
  74. struct build_id_event {
  75. struct perf_event_header header;
  76. pid_t pid;
  77. u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  78. char filename[];
  79. };
  80. enum perf_user_event_type { /* above any possible kernel type */
  81. PERF_RECORD_USER_TYPE_START = 64,
  82. PERF_RECORD_HEADER_ATTR = 64,
  83. PERF_RECORD_HEADER_EVENT_TYPE = 65,
  84. PERF_RECORD_HEADER_TRACING_DATA = 66,
  85. PERF_RECORD_HEADER_BUILD_ID = 67,
  86. PERF_RECORD_FINISHED_ROUND = 68,
  87. PERF_RECORD_HEADER_MAX
  88. };
  89. struct attr_event {
  90. struct perf_event_header header;
  91. struct perf_event_attr attr;
  92. u64 id[];
  93. };
  94. #define MAX_EVENT_NAME 64
  95. struct perf_trace_event_type {
  96. u64 event_id;
  97. char name[MAX_EVENT_NAME];
  98. };
  99. struct event_type_event {
  100. struct perf_event_header header;
  101. struct perf_trace_event_type event_type;
  102. };
  103. struct tracing_data_event {
  104. struct perf_event_header header;
  105. u32 size;
  106. };
  107. union perf_event {
  108. struct perf_event_header header;
  109. struct ip_event ip;
  110. struct mmap_event mmap;
  111. struct comm_event comm;
  112. struct fork_event fork;
  113. struct lost_event lost;
  114. struct read_event read;
  115. struct sample_event sample;
  116. struct attr_event attr;
  117. struct event_type_event event_type;
  118. struct tracing_data_event tracing_data;
  119. struct build_id_event build_id;
  120. };
  121. void perf_event__print_totals(void);
  122. struct perf_tool;
  123. struct thread_map;
  124. typedef int (*perf_event__handler_t)(struct perf_tool *tool,
  125. union perf_event *event,
  126. struct perf_sample *sample,
  127. struct machine *machine);
  128. int perf_event__synthesize_thread_map(struct perf_tool *tool,
  129. struct thread_map *threads,
  130. perf_event__handler_t process,
  131. struct machine *machine);
  132. int perf_event__synthesize_threads(struct perf_tool *tool,
  133. perf_event__handler_t process,
  134. struct machine *machine);
  135. int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
  136. perf_event__handler_t process,
  137. struct machine *machine,
  138. const char *symbol_name);
  139. int perf_event__synthesize_modules(struct perf_tool *tool,
  140. perf_event__handler_t process,
  141. struct machine *machine);
  142. int perf_event__process_comm(struct perf_tool *tool,
  143. union perf_event *event,
  144. struct perf_sample *sample,
  145. struct machine *machine);
  146. int perf_event__process_lost(struct perf_tool *tool,
  147. union perf_event *event,
  148. struct perf_sample *sample,
  149. struct machine *machine);
  150. int perf_event__process_mmap(struct perf_tool *tool,
  151. union perf_event *event,
  152. struct perf_sample *sample,
  153. struct machine *machine);
  154. int perf_event__process_task(struct perf_tool *tool,
  155. union perf_event *event,
  156. struct perf_sample *sample,
  157. struct machine *machine);
  158. int perf_event__process(struct perf_tool *tool,
  159. union perf_event *event,
  160. struct perf_sample *sample,
  161. struct machine *machine);
  162. struct addr_location;
  163. int perf_event__preprocess_sample(const union perf_event *self,
  164. struct machine *machine,
  165. struct addr_location *al,
  166. struct perf_sample *sample,
  167. symbol_filter_t filter);
  168. const char *perf_event__name(unsigned int id);
  169. int perf_event__parse_sample(const union perf_event *event, u64 type,
  170. int sample_size, bool sample_id_all,
  171. struct perf_sample *sample, bool swapped);
  172. int perf_event__synthesize_sample(union perf_event *event, u64 type,
  173. const struct perf_sample *sample,
  174. bool swapped);
  175. size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
  176. size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
  177. size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
  178. size_t perf_event__fprintf(union perf_event *event, FILE *fp);
  179. #endif /* __PERF_RECORD_H */