session.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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;
  18. struct list_head sample_cache;
  19. struct list_head to_free;
  20. struct sample_queue *sample_buffer;
  21. struct sample_queue *last_sample;
  22. int sample_buffer_idx;
  23. };
  24. struct perf_session {
  25. struct perf_header header;
  26. unsigned long size;
  27. unsigned long mmap_window;
  28. struct rb_root threads;
  29. struct list_head dead_threads;
  30. struct thread *last_match;
  31. struct machine host_machine;
  32. struct rb_root machines;
  33. struct perf_evlist *evlist;
  34. /*
  35. * FIXME: Need to split this up further, we need global
  36. * stats + per event stats. 'perf diff' also needs
  37. * to properly support multiple events in a single
  38. * perf.data file.
  39. */
  40. struct hists hists;
  41. u64 sample_type;
  42. int fd;
  43. bool fd_pipe;
  44. bool repipe;
  45. bool sample_id_all;
  46. u16 id_hdr_size;
  47. int cwdlen;
  48. char *cwd;
  49. struct ordered_samples ordered_samples;
  50. struct callchain_cursor callchain_cursor;
  51. char filename[0];
  52. };
  53. struct perf_evsel;
  54. struct perf_event_ops;
  55. typedef int (*event_sample)(union perf_event *event, struct perf_sample *sample,
  56. struct perf_evsel *evsel, struct perf_session *session);
  57. typedef int (*event_op)(union perf_event *self, struct perf_sample *sample,
  58. struct perf_session *session);
  59. typedef int (*event_synth_op)(union perf_event *self,
  60. struct perf_session *session);
  61. typedef int (*event_op2)(union perf_event *self, struct perf_session *session,
  62. struct perf_event_ops *ops);
  63. struct perf_event_ops {
  64. event_sample sample;
  65. event_op mmap,
  66. comm,
  67. fork,
  68. exit,
  69. lost,
  70. read,
  71. throttle,
  72. unthrottle;
  73. event_synth_op attr,
  74. event_type,
  75. tracing_data,
  76. build_id;
  77. event_op2 finished_round;
  78. bool ordered_samples;
  79. bool ordering_requires_timestamps;
  80. };
  81. struct perf_session *perf_session__new(const char *filename, int mode,
  82. bool force, bool repipe,
  83. struct perf_event_ops *ops);
  84. void perf_session__delete(struct perf_session *self);
  85. void perf_event_header__bswap(struct perf_event_header *self);
  86. int __perf_session__process_events(struct perf_session *self,
  87. u64 data_offset, u64 data_size, u64 size,
  88. struct perf_event_ops *ops);
  89. int perf_session__process_events(struct perf_session *self,
  90. struct perf_event_ops *event_ops);
  91. int perf_session__resolve_callchain(struct perf_session *self,
  92. struct thread *thread,
  93. struct ip_callchain *chain,
  94. struct symbol **parent);
  95. bool perf_session__has_traces(struct perf_session *self, const char *msg);
  96. int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
  97. const char *symbol_name,
  98. u64 addr);
  99. void mem_bswap_64(void *src, int byte_size);
  100. int perf_session__create_kernel_maps(struct perf_session *self);
  101. void perf_session__update_sample_type(struct perf_session *self);
  102. void perf_session__remove_thread(struct perf_session *self, struct thread *th);
  103. static inline
  104. struct machine *perf_session__find_host_machine(struct perf_session *self)
  105. {
  106. return &self->host_machine;
  107. }
  108. static inline
  109. struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
  110. {
  111. if (pid == HOST_KERNEL_ID)
  112. return &self->host_machine;
  113. return machines__find(&self->machines, pid);
  114. }
  115. static inline
  116. struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
  117. {
  118. if (pid == HOST_KERNEL_ID)
  119. return &self->host_machine;
  120. return machines__findnew(&self->machines, pid);
  121. }
  122. static inline
  123. void perf_session__process_machines(struct perf_session *self,
  124. machine__process_t process)
  125. {
  126. process(&self->host_machine, self);
  127. return machines__process(&self->machines, process, self);
  128. }
  129. size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
  130. size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
  131. FILE *fp, bool with_hits);
  132. size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
  133. static inline int perf_session__parse_sample(struct perf_session *session,
  134. const union perf_event *event,
  135. struct perf_sample *sample)
  136. {
  137. return perf_event__parse_sample(event, session->sample_type,
  138. session->sample_id_all, sample);
  139. }
  140. void perf_session__print_symbols(union perf_event *event,
  141. struct perf_sample *sample,
  142. struct perf_session *session);
  143. #endif /* __PERF_SESSION_H */