header.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_HEADER_H
  3. #define __PERF_HEADER_H
  4. #include <linux/stddef.h>
  5. #include <linux/perf_event.h>
  6. #include <sys/types.h>
  7. #include <stdbool.h>
  8. #include <linux/bitmap.h>
  9. #include <linux/types.h>
  10. #include "event.h"
  11. #include "env.h"
  12. #include "pmu.h"
  13. enum {
  14. HEADER_RESERVED = 0, /* always cleared */
  15. HEADER_FIRST_FEATURE = 1,
  16. HEADER_TRACING_DATA = 1,
  17. HEADER_BUILD_ID,
  18. HEADER_HOSTNAME,
  19. HEADER_OSRELEASE,
  20. HEADER_VERSION,
  21. HEADER_ARCH,
  22. HEADER_NRCPUS,
  23. HEADER_CPUDESC,
  24. HEADER_CPUID,
  25. HEADER_TOTAL_MEM,
  26. HEADER_CMDLINE,
  27. HEADER_EVENT_DESC,
  28. HEADER_CPU_TOPOLOGY,
  29. HEADER_NUMA_TOPOLOGY,
  30. HEADER_BRANCH_STACK,
  31. HEADER_PMU_MAPPINGS,
  32. HEADER_GROUP_DESC,
  33. HEADER_AUXTRACE,
  34. HEADER_STAT,
  35. HEADER_CACHE,
  36. HEADER_SAMPLE_TIME,
  37. HEADER_MEM_TOPOLOGY,
  38. HEADER_LAST_FEATURE,
  39. HEADER_FEAT_BITS = 256,
  40. };
  41. enum perf_header_version {
  42. PERF_HEADER_VERSION_1,
  43. PERF_HEADER_VERSION_2,
  44. };
  45. struct perf_file_section {
  46. u64 offset;
  47. u64 size;
  48. };
  49. struct perf_file_header {
  50. u64 magic;
  51. u64 size;
  52. u64 attr_size;
  53. struct perf_file_section attrs;
  54. struct perf_file_section data;
  55. /* event_types is ignored */
  56. struct perf_file_section event_types;
  57. DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
  58. };
  59. struct perf_pipe_file_header {
  60. u64 magic;
  61. u64 size;
  62. };
  63. struct perf_header;
  64. int perf_file_header__read(struct perf_file_header *header,
  65. struct perf_header *ph, int fd);
  66. struct perf_header {
  67. enum perf_header_version version;
  68. bool needs_swap;
  69. u64 data_offset;
  70. u64 data_size;
  71. u64 feat_offset;
  72. DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
  73. struct perf_env env;
  74. };
  75. struct perf_evlist;
  76. struct perf_session;
  77. int perf_session__read_header(struct perf_session *session);
  78. int perf_session__write_header(struct perf_session *session,
  79. struct perf_evlist *evlist,
  80. int fd, bool at_exit);
  81. int perf_header__write_pipe(int fd);
  82. void perf_header__set_feat(struct perf_header *header, int feat);
  83. void perf_header__clear_feat(struct perf_header *header, int feat);
  84. bool perf_header__has_feat(const struct perf_header *header, int feat);
  85. int perf_header__set_cmdline(int argc, const char **argv);
  86. int perf_header__process_sections(struct perf_header *header, int fd,
  87. void *data,
  88. int (*process)(struct perf_file_section *section,
  89. struct perf_header *ph,
  90. int feat, int fd, void *data));
  91. int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
  92. int perf_event__synthesize_features(struct perf_tool *tool,
  93. struct perf_session *session,
  94. struct perf_evlist *evlist,
  95. perf_event__handler_t process);
  96. int perf_event__synthesize_extra_attr(struct perf_tool *tool,
  97. struct perf_evlist *evsel_list,
  98. perf_event__handler_t process,
  99. bool is_pipe);
  100. int perf_event__process_feature(struct perf_tool *tool,
  101. union perf_event *event,
  102. struct perf_session *session);
  103. int perf_event__synthesize_attr(struct perf_tool *tool,
  104. struct perf_event_attr *attr, u32 ids, u64 *id,
  105. perf_event__handler_t process);
  106. int perf_event__synthesize_attrs(struct perf_tool *tool,
  107. struct perf_session *session,
  108. perf_event__handler_t process);
  109. int perf_event__synthesize_event_update_unit(struct perf_tool *tool,
  110. struct perf_evsel *evsel,
  111. perf_event__handler_t process);
  112. int perf_event__synthesize_event_update_scale(struct perf_tool *tool,
  113. struct perf_evsel *evsel,
  114. perf_event__handler_t process);
  115. int perf_event__synthesize_event_update_name(struct perf_tool *tool,
  116. struct perf_evsel *evsel,
  117. perf_event__handler_t process);
  118. int perf_event__synthesize_event_update_cpus(struct perf_tool *tool,
  119. struct perf_evsel *evsel,
  120. perf_event__handler_t process);
  121. int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
  122. struct perf_evlist **pevlist);
  123. int perf_event__process_event_update(struct perf_tool *tool,
  124. union perf_event *event,
  125. struct perf_evlist **pevlist);
  126. size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
  127. int perf_event__synthesize_tracing_data(struct perf_tool *tool,
  128. int fd, struct perf_evlist *evlist,
  129. perf_event__handler_t process);
  130. int perf_event__process_tracing_data(struct perf_tool *tool,
  131. union perf_event *event,
  132. struct perf_session *session);
  133. int perf_event__synthesize_build_id(struct perf_tool *tool,
  134. struct dso *pos, u16 misc,
  135. perf_event__handler_t process,
  136. struct machine *machine);
  137. int perf_event__process_build_id(struct perf_tool *tool,
  138. union perf_event *event,
  139. struct perf_session *session);
  140. bool is_perf_magic(u64 magic);
  141. #define NAME_ALIGN 64
  142. struct feat_fd;
  143. int do_write(struct feat_fd *fd, const void *buf, size_t size);
  144. int write_padded(struct feat_fd *fd, const void *bf,
  145. size_t count, size_t count_aligned);
  146. /*
  147. * arch specific callback
  148. */
  149. int get_cpuid(char *buffer, size_t sz);
  150. char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused);
  151. int strcmp_cpuid_str(const char *s1, const char *s2);
  152. #endif /* __PERF_HEADER_H */