event.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef __PERF_RECORD_H
  2. #define __PERF_RECORD_H
  3. #include "../perf.h"
  4. #include "util.h"
  5. #include <linux/list.h>
  6. #include <linux/rbtree.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. struct sample_event {
  52. struct perf_event_header header;
  53. u64 array[];
  54. };
  55. struct sample_data {
  56. u64 ip;
  57. u32 pid, tid;
  58. u64 time;
  59. u64 addr;
  60. u64 id;
  61. u64 stream_id;
  62. u32 cpu;
  63. u64 period;
  64. struct ip_callchain *callchain;
  65. u32 raw_size;
  66. void *raw_data;
  67. };
  68. #define BUILD_ID_SIZE 20
  69. struct build_id_event {
  70. struct perf_event_header header;
  71. u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  72. char filename[];
  73. };
  74. typedef union event_union {
  75. struct perf_event_header header;
  76. struct ip_event ip;
  77. struct mmap_event mmap;
  78. struct comm_event comm;
  79. struct fork_event fork;
  80. struct lost_event lost;
  81. struct read_event read;
  82. struct sample_event sample;
  83. } event_t;
  84. struct events_stats {
  85. u64 total;
  86. u64 lost;
  87. };
  88. void event__print_totals(void);
  89. enum map_type {
  90. MAP__FUNCTION = 0,
  91. MAP__VARIABLE,
  92. };
  93. #define MAP__NR_TYPES (MAP__VARIABLE + 1)
  94. struct map {
  95. union {
  96. struct rb_node rb_node;
  97. struct list_head node;
  98. };
  99. u64 start;
  100. u64 end;
  101. enum map_type type;
  102. u64 pgoff;
  103. u64 (*map_ip)(struct map *, u64);
  104. u64 (*unmap_ip)(struct map *, u64);
  105. struct dso *dso;
  106. };
  107. static inline u64 map__map_ip(struct map *map, u64 ip)
  108. {
  109. return ip - map->start + map->pgoff;
  110. }
  111. static inline u64 map__unmap_ip(struct map *map, u64 ip)
  112. {
  113. return ip + map->start - map->pgoff;
  114. }
  115. static inline u64 identity__map_ip(struct map *map __used, u64 ip)
  116. {
  117. return ip;
  118. }
  119. struct symbol;
  120. typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
  121. void map__init(struct map *self, enum map_type type,
  122. u64 start, u64 end, u64 pgoff, struct dso *dso);
  123. struct map *map__new(struct mmap_event *event, enum map_type,
  124. char *cwd, int cwdlen);
  125. void map__delete(struct map *self);
  126. struct map *map__clone(struct map *self);
  127. int map__overlap(struct map *l, struct map *r);
  128. size_t map__fprintf(struct map *self, FILE *fp);
  129. struct perf_session;
  130. int map__load(struct map *self, struct perf_session *session,
  131. symbol_filter_t filter);
  132. struct symbol *map__find_symbol(struct map *self, struct perf_session *session,
  133. u64 addr, symbol_filter_t filter);
  134. struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
  135. struct perf_session *session,
  136. symbol_filter_t filter);
  137. void map__fixup_start(struct map *self);
  138. void map__fixup_end(struct map *self);
  139. int event__synthesize_thread(pid_t pid,
  140. int (*process)(event_t *event,
  141. struct perf_session *session),
  142. struct perf_session *session);
  143. void event__synthesize_threads(int (*process)(event_t *event,
  144. struct perf_session *session),
  145. struct perf_session *session);
  146. int event__process_comm(event_t *self, struct perf_session *session);
  147. int event__process_lost(event_t *self, struct perf_session *session);
  148. int event__process_mmap(event_t *self, struct perf_session *session);
  149. int event__process_task(event_t *self, struct perf_session *session);
  150. struct addr_location;
  151. int event__preprocess_sample(const event_t *self, struct perf_session *session,
  152. struct addr_location *al, symbol_filter_t filter);
  153. int event__parse_sample(event_t *event, u64 type, struct sample_data *data);
  154. #endif /* __PERF_RECORD_H */