session.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef __PERF_SESSION_H
  2. #define __PERF_SESSION_H
  3. #include "event.h"
  4. #include "header.h"
  5. #include "symbol.h"
  6. #include "thread.h"
  7. #include <linux/rbtree.h>
  8. #include "../../../include/linux/perf_event.h"
  9. struct sample_queue;
  10. struct ip_callchain;
  11. struct thread;
  12. struct ordered_samples {
  13. u64 last_flush;
  14. u64 next_flush;
  15. u64 max_timestamp;
  16. struct list_head samples_head;
  17. struct sample_queue *last_inserted;
  18. };
  19. struct perf_session {
  20. struct perf_header header;
  21. unsigned long size;
  22. unsigned long mmap_window;
  23. struct rb_root threads;
  24. struct thread *last_match;
  25. struct rb_root machines;
  26. struct events_stats events_stats;
  27. struct rb_root stats_by_id;
  28. unsigned long event_total[PERF_RECORD_MAX];
  29. unsigned long unknown_events;
  30. struct rb_root hists;
  31. u64 sample_type;
  32. int fd;
  33. bool fd_pipe;
  34. bool repipe;
  35. int cwdlen;
  36. char *cwd;
  37. struct ordered_samples ordered_samples;
  38. char filename[0];
  39. };
  40. struct perf_event_ops;
  41. typedef int (*event_op)(event_t *self, struct perf_session *session);
  42. typedef int (*event_op2)(event_t *self, struct perf_session *session,
  43. struct perf_event_ops *ops);
  44. struct perf_event_ops {
  45. event_op sample,
  46. mmap,
  47. comm,
  48. fork,
  49. exit,
  50. lost,
  51. read,
  52. throttle,
  53. unthrottle,
  54. attr,
  55. event_type,
  56. tracing_data,
  57. build_id;
  58. event_op2 finished_round;
  59. bool ordered_samples;
  60. };
  61. struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
  62. void perf_session__delete(struct perf_session *self);
  63. void perf_event_header__bswap(struct perf_event_header *self);
  64. int __perf_session__process_events(struct perf_session *self,
  65. u64 data_offset, u64 data_size, u64 size,
  66. struct perf_event_ops *ops);
  67. int perf_session__process_events(struct perf_session *self,
  68. struct perf_event_ops *event_ops);
  69. struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
  70. struct thread *thread,
  71. struct ip_callchain *chain,
  72. struct symbol **parent);
  73. bool perf_session__has_traces(struct perf_session *self, const char *msg);
  74. int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
  75. const char *symbol_name,
  76. u64 addr);
  77. void mem_bswap_64(void *src, int byte_size);
  78. int perf_session__create_kernel_maps(struct perf_session *self);
  79. int do_read(int fd, void *buf, size_t size);
  80. void perf_session__update_sample_type(struct perf_session *self);
  81. #ifdef NO_NEWT_SUPPORT
  82. static inline int perf_session__browse_hists(struct rb_root *hists __used,
  83. u64 nr_hists __used,
  84. u64 session_total __used,
  85. const char *helpline __used,
  86. const char *input_name __used)
  87. {
  88. return 0;
  89. }
  90. #else
  91. int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
  92. u64 session_total, const char *helpline,
  93. const char *input_name);
  94. #endif
  95. static inline
  96. struct machine *perf_session__find_host_machine(struct perf_session *self)
  97. {
  98. return machines__find_host(&self->machines);
  99. }
  100. static inline
  101. struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
  102. {
  103. return machines__find(&self->machines, pid);
  104. }
  105. static inline
  106. struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
  107. {
  108. return machines__findnew(&self->machines, pid);
  109. }
  110. static inline
  111. void perf_session__process_machines(struct perf_session *self,
  112. machine__process_t process)
  113. {
  114. return machines__process(&self->machines, process, self);
  115. }
  116. static inline
  117. size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
  118. {
  119. return machines__fprintf_dsos(&self->machines, fp);
  120. }
  121. static inline
  122. size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
  123. bool with_hits)
  124. {
  125. return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
  126. }
  127. #endif /* __PERF_SESSION_H */