event.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #define BUILD_ID_SIZE 20
  56. struct build_id_event {
  57. struct perf_event_header header;
  58. u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  59. char filename[];
  60. };
  61. struct build_id_list {
  62. struct build_id_event event;
  63. struct list_head list;
  64. const char *dso_name;
  65. int len;
  66. };
  67. typedef union event_union {
  68. struct perf_event_header header;
  69. struct ip_event ip;
  70. struct mmap_event mmap;
  71. struct comm_event comm;
  72. struct fork_event fork;
  73. struct lost_event lost;
  74. struct read_event read;
  75. struct sample_event sample;
  76. } event_t;
  77. struct map {
  78. union {
  79. struct rb_node rb_node;
  80. struct list_head node;
  81. };
  82. u64 start;
  83. u64 end;
  84. u64 pgoff;
  85. u64 (*map_ip)(struct map *, u64);
  86. u64 (*unmap_ip)(struct map *, u64);
  87. struct dso *dso;
  88. };
  89. static inline u64 map__map_ip(struct map *map, u64 ip)
  90. {
  91. return ip - map->start + map->pgoff;
  92. }
  93. static inline u64 map__unmap_ip(struct map *map, u64 ip)
  94. {
  95. return ip + map->start - map->pgoff;
  96. }
  97. static inline u64 identity__map_ip(struct map *map __used, u64 ip)
  98. {
  99. return ip;
  100. }
  101. struct symbol;
  102. typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
  103. void map__init(struct map *self, u64 start, u64 end, u64 pgoff,
  104. struct dso *dso);
  105. struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen);
  106. struct map *map__clone(struct map *self);
  107. int map__overlap(struct map *l, struct map *r);
  108. size_t map__fprintf(struct map *self, FILE *fp);
  109. struct symbol *map__find_symbol(struct map *self, u64 ip, symbol_filter_t filter);
  110. int event__synthesize_thread(pid_t pid, int (*process)(event_t *event));
  111. void event__synthesize_threads(int (*process)(event_t *event));
  112. #endif /* __PERF_RECORD_H */