session.h 3.6 KB

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