header.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef __PERF_HEADER_H
  2. #define __PERF_HEADER_H
  3. #include <linux/perf_event.h>
  4. #include <sys/types.h>
  5. #include <stdbool.h>
  6. #include "types.h"
  7. #include "event.h"
  8. #include <linux/bitmap.h>
  9. enum {
  10. HEADER_RESERVED = 0, /* always cleared */
  11. HEADER_FIRST_FEATURE = 1,
  12. HEADER_TRACING_DATA = 1,
  13. HEADER_BUILD_ID,
  14. HEADER_HOSTNAME,
  15. HEADER_OSRELEASE,
  16. HEADER_VERSION,
  17. HEADER_ARCH,
  18. HEADER_NRCPUS,
  19. HEADER_CPUDESC,
  20. HEADER_CPUID,
  21. HEADER_TOTAL_MEM,
  22. HEADER_CMDLINE,
  23. HEADER_EVENT_DESC,
  24. HEADER_CPU_TOPOLOGY,
  25. HEADER_NUMA_TOPOLOGY,
  26. HEADER_BRANCH_STACK,
  27. HEADER_PMU_MAPPINGS,
  28. HEADER_GROUP_DESC,
  29. HEADER_LAST_FEATURE,
  30. HEADER_FEAT_BITS = 256,
  31. };
  32. enum perf_header_version {
  33. PERF_HEADER_VERSION_1,
  34. PERF_HEADER_VERSION_2,
  35. };
  36. struct perf_file_section {
  37. u64 offset;
  38. u64 size;
  39. };
  40. struct perf_file_header {
  41. u64 magic;
  42. u64 size;
  43. u64 attr_size;
  44. struct perf_file_section attrs;
  45. struct perf_file_section data;
  46. /* event_types is ignored */
  47. struct perf_file_section event_types;
  48. DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
  49. };
  50. struct perf_pipe_file_header {
  51. u64 magic;
  52. u64 size;
  53. };
  54. struct perf_header;
  55. int perf_file_header__read(struct perf_file_header *header,
  56. struct perf_header *ph, int fd);
  57. struct perf_session_env {
  58. char *hostname;
  59. char *os_release;
  60. char *version;
  61. char *arch;
  62. int nr_cpus_online;
  63. int nr_cpus_avail;
  64. char *cpu_desc;
  65. char *cpuid;
  66. unsigned long long total_mem;
  67. int nr_cmdline;
  68. char *cmdline;
  69. int nr_sibling_cores;
  70. char *sibling_cores;
  71. int nr_sibling_threads;
  72. char *sibling_threads;
  73. int nr_numa_nodes;
  74. char *numa_nodes;
  75. int nr_pmu_mappings;
  76. char *pmu_mappings;
  77. int nr_groups;
  78. };
  79. struct perf_header {
  80. enum perf_header_version version;
  81. bool needs_swap;
  82. u64 data_offset;
  83. u64 data_size;
  84. u64 feat_offset;
  85. DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
  86. struct perf_session_env env;
  87. };
  88. struct perf_evlist;
  89. struct perf_session;
  90. int perf_session__read_header(struct perf_session *session);
  91. int perf_session__write_header(struct perf_session *session,
  92. struct perf_evlist *evlist,
  93. int fd, bool at_exit);
  94. int perf_header__write_pipe(int fd);
  95. void perf_header__set_feat(struct perf_header *header, int feat);
  96. void perf_header__clear_feat(struct perf_header *header, int feat);
  97. bool perf_header__has_feat(const struct perf_header *header, int feat);
  98. int perf_header__set_cmdline(int argc, const char **argv);
  99. int perf_header__process_sections(struct perf_header *header, int fd,
  100. void *data,
  101. int (*process)(struct perf_file_section *section,
  102. struct perf_header *ph,
  103. int feat, int fd, void *data));
  104. int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
  105. int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
  106. const char *name, bool is_kallsyms, bool is_vdso);
  107. int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
  108. int perf_event__synthesize_attr(struct perf_tool *tool,
  109. struct perf_event_attr *attr, u32 ids, u64 *id,
  110. perf_event__handler_t process);
  111. int perf_event__synthesize_attrs(struct perf_tool *tool,
  112. struct perf_session *session,
  113. perf_event__handler_t process);
  114. int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
  115. struct perf_evlist **pevlist);
  116. int perf_event__synthesize_tracing_data(struct perf_tool *tool,
  117. int fd, struct perf_evlist *evlist,
  118. perf_event__handler_t process);
  119. int perf_event__process_tracing_data(struct perf_tool *tool,
  120. union perf_event *event,
  121. struct perf_session *session);
  122. int perf_event__synthesize_build_id(struct perf_tool *tool,
  123. struct dso *pos, u16 misc,
  124. perf_event__handler_t process,
  125. struct machine *machine);
  126. int perf_event__process_build_id(struct perf_tool *tool,
  127. union perf_event *event,
  128. struct perf_session *session);
  129. bool is_perf_magic(u64 magic);
  130. /*
  131. * arch specific callback
  132. */
  133. int get_cpuid(char *buffer, size_t sz);
  134. #endif /* __PERF_HEADER_H */