session.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 flush_limit;
  15. struct list_head samples_head;
  16. struct sample_queue *last_inserted;
  17. };
  18. struct perf_session {
  19. struct perf_header header;
  20. unsigned long size;
  21. unsigned long mmap_window;
  22. struct rb_root threads;
  23. struct thread *last_match;
  24. struct machine host_machine;
  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. typedef int (*event_op)(event_t *self, struct perf_session *session);
  41. struct perf_event_ops {
  42. event_op sample,
  43. mmap,
  44. comm,
  45. fork,
  46. exit,
  47. lost,
  48. read,
  49. throttle,
  50. unthrottle,
  51. attr,
  52. event_type,
  53. tracing_data,
  54. build_id;
  55. bool ordered_samples;
  56. };
  57. struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
  58. void perf_session__delete(struct perf_session *self);
  59. void perf_event_header__bswap(struct perf_event_header *self);
  60. int __perf_session__process_events(struct perf_session *self,
  61. u64 data_offset, u64 data_size, u64 size,
  62. struct perf_event_ops *ops);
  63. int perf_session__process_events(struct perf_session *self,
  64. struct perf_event_ops *event_ops);
  65. struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
  66. struct thread *thread,
  67. struct ip_callchain *chain,
  68. struct symbol **parent);
  69. bool perf_session__has_traces(struct perf_session *self, const char *msg);
  70. int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
  71. const char *symbol_name,
  72. u64 addr);
  73. void mem_bswap_64(void *src, int byte_size);
  74. int perf_session__create_kernel_maps(struct perf_session *self);
  75. int do_read(int fd, void *buf, size_t size);
  76. void perf_session__update_sample_type(struct perf_session *self);
  77. #ifdef NO_NEWT_SUPPORT
  78. static inline int perf_session__browse_hists(struct rb_root *hists __used,
  79. u64 nr_hists __used,
  80. u64 session_total __used,
  81. const char *helpline __used,
  82. const char *input_name __used)
  83. {
  84. return 0;
  85. }
  86. #else
  87. int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
  88. u64 session_total, const char *helpline,
  89. const char *input_name);
  90. #endif
  91. static inline
  92. struct machine *perf_session__find_host_machine(struct perf_session *self)
  93. {
  94. return &self->host_machine;
  95. }
  96. static inline
  97. struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
  98. {
  99. if (pid == HOST_KERNEL_ID)
  100. return &self->host_machine;
  101. return machines__find(&self->machines, pid);
  102. }
  103. static inline
  104. struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
  105. {
  106. if (pid == HOST_KERNEL_ID)
  107. return &self->host_machine;
  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. process(&self->host_machine, self);
  115. return machines__process(&self->machines, process, self);
  116. }
  117. size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
  118. static inline
  119. size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
  120. bool with_hits)
  121. {
  122. return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
  123. }
  124. #endif /* __PERF_SESSION_H */