session.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 sample_size;
  43. int fd;
  44. bool fd_pipe;
  45. bool repipe;
  46. bool sample_id_all;
  47. u16 id_hdr_size;
  48. int cwdlen;
  49. char *cwd;
  50. struct ordered_samples ordered_samples;
  51. struct callchain_cursor callchain_cursor;
  52. char filename[0];
  53. };
  54. struct perf_evsel;
  55. struct perf_event_ops;
  56. typedef int (*event_sample)(union perf_event *event, struct perf_sample *sample,
  57. struct perf_evsel *evsel, struct perf_session *session);
  58. typedef int (*event_op)(union perf_event *self, struct perf_sample *sample,
  59. struct perf_session *session);
  60. typedef int (*event_synth_op)(union perf_event *self,
  61. struct perf_session *session);
  62. typedef int (*event_op2)(union perf_event *self, struct perf_session *session,
  63. struct perf_event_ops *ops);
  64. struct perf_event_ops {
  65. event_sample sample;
  66. event_op mmap,
  67. comm,
  68. fork,
  69. exit,
  70. lost,
  71. read,
  72. throttle,
  73. unthrottle;
  74. event_synth_op attr,
  75. event_type,
  76. tracing_data,
  77. build_id;
  78. event_op2 finished_round;
  79. bool ordered_samples;
  80. bool ordering_requires_timestamps;
  81. };
  82. struct perf_session *perf_session__new(const char *filename, int mode,
  83. bool force, bool repipe,
  84. struct perf_event_ops *ops);
  85. void perf_session__delete(struct perf_session *self);
  86. void perf_event_header__bswap(struct perf_event_header *self);
  87. int __perf_session__process_events(struct perf_session *self,
  88. u64 data_offset, u64 data_size, u64 size,
  89. struct perf_event_ops *ops);
  90. int perf_session__process_events(struct perf_session *self,
  91. struct perf_event_ops *event_ops);
  92. int perf_session__resolve_callchain(struct perf_session *self,
  93. struct thread *thread,
  94. struct ip_callchain *chain,
  95. struct symbol **parent);
  96. bool perf_session__has_traces(struct perf_session *self, const char *msg);
  97. int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
  98. const char *symbol_name,
  99. u64 addr);
  100. void mem_bswap_64(void *src, int byte_size);
  101. void perf_event__attr_swap(struct perf_event_attr *attr);
  102. int perf_session__create_kernel_maps(struct perf_session *self);
  103. void perf_session__update_sample_type(struct perf_session *self);
  104. void perf_session__remove_thread(struct perf_session *self, struct thread *th);
  105. static inline
  106. struct machine *perf_session__find_host_machine(struct perf_session *self)
  107. {
  108. return &self->host_machine;
  109. }
  110. static inline
  111. struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
  112. {
  113. if (pid == HOST_KERNEL_ID)
  114. return &self->host_machine;
  115. return machines__find(&self->machines, pid);
  116. }
  117. static inline
  118. struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
  119. {
  120. if (pid == HOST_KERNEL_ID)
  121. return &self->host_machine;
  122. return machines__findnew(&self->machines, pid);
  123. }
  124. static inline
  125. void perf_session__process_machines(struct perf_session *self,
  126. machine__process_t process)
  127. {
  128. process(&self->host_machine, self);
  129. return machines__process(&self->machines, process, self);
  130. }
  131. size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
  132. size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
  133. FILE *fp, bool with_hits);
  134. size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
  135. static inline int perf_session__parse_sample(struct perf_session *session,
  136. const union perf_event *event,
  137. struct perf_sample *sample)
  138. {
  139. return perf_event__parse_sample(event, session->sample_type,
  140. session->sample_size,
  141. session->sample_id_all, sample);
  142. }
  143. struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
  144. unsigned int type);
  145. void perf_session__print_symbols(union perf_event *event,
  146. struct perf_sample *sample,
  147. struct perf_session *session);
  148. #endif /* __PERF_SESSION_H */