session.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 rb_root machines;
  25. struct events_stats events_stats;
  26. struct rb_root stats_by_id;
  27. unsigned long event_total[PERF_RECORD_MAX];
  28. unsigned long unknown_events;
  29. struct rb_root hists;
  30. u64 sample_type;
  31. int fd;
  32. bool fd_pipe;
  33. int cwdlen;
  34. char *cwd;
  35. struct ordered_samples ordered_samples;
  36. char filename[0];
  37. };
  38. typedef int (*event_op)(event_t *self, struct perf_session *session);
  39. struct perf_event_ops {
  40. event_op sample,
  41. mmap,
  42. comm,
  43. fork,
  44. exit,
  45. lost,
  46. read,
  47. throttle,
  48. unthrottle,
  49. attr,
  50. event_type,
  51. tracing_data,
  52. build_id;
  53. bool ordered_samples;
  54. };
  55. struct perf_session *perf_session__new(const char *filename, int mode, bool force);
  56. void perf_session__delete(struct perf_session *self);
  57. void perf_event_header__bswap(struct perf_event_header *self);
  58. int __perf_session__process_events(struct perf_session *self,
  59. u64 data_offset, u64 data_size, u64 size,
  60. struct perf_event_ops *ops);
  61. int perf_session__process_events(struct perf_session *self,
  62. struct perf_event_ops *event_ops);
  63. struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
  64. struct thread *thread,
  65. struct ip_callchain *chain,
  66. struct symbol **parent);
  67. bool perf_session__has_traces(struct perf_session *self, const char *msg);
  68. int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
  69. const char *symbol_name,
  70. u64 addr);
  71. void mem_bswap_64(void *src, int byte_size);
  72. int perf_session__create_kernel_maps(struct perf_session *self);
  73. int do_read(int fd, void *buf, size_t size);
  74. void perf_session__update_sample_type(struct perf_session *self);
  75. #ifdef NO_NEWT_SUPPORT
  76. static inline int perf_session__browse_hists(struct rb_root *hists __used,
  77. u64 nr_hists __used,
  78. u64 session_total __used,
  79. const char *helpline __used,
  80. const char *input_name __used)
  81. {
  82. return 0;
  83. }
  84. #else
  85. int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
  86. u64 session_total, const char *helpline,
  87. const char *input_name);
  88. #endif
  89. static inline
  90. struct machine *perf_session__find_host_machine(struct perf_session *self)
  91. {
  92. return machines__find_host(&self->machines);
  93. }
  94. static inline
  95. struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
  96. {
  97. return machines__find(&self->machines, pid);
  98. }
  99. static inline
  100. struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
  101. {
  102. return machines__findnew(&self->machines, pid);
  103. }
  104. static inline
  105. void perf_session__process_machines(struct perf_session *self,
  106. machine__process_t process)
  107. {
  108. return machines__process(&self->machines, process, self);
  109. }
  110. static inline
  111. size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
  112. {
  113. return machines__fprintf_dsos(&self->machines, fp);
  114. }
  115. static inline
  116. size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
  117. bool with_hits)
  118. {
  119. return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
  120. }
  121. #endif /* __PERF_SESSION_H */