header.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <stdio.h> // FILE
  8. #include <stdbool.h>
  9. #include <linux/bitmap.h>
  10. #include <linux/types.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_CLOCKID,
  39. HEADER_DIR_FORMAT,
  40. HEADER_BPF_PROG_INFO,
  41. HEADER_BPF_BTF,
  42. HEADER_COMPRESSED,
  43. HEADER_LAST_FEATURE,
  44. HEADER_FEAT_BITS = 256,
  45. };
  46. enum perf_header_version {
  47. PERF_HEADER_VERSION_1,
  48. PERF_HEADER_VERSION_2,
  49. };
  50. enum perf_dir_version {
  51. PERF_DIR_VERSION = 1,
  52. };
  53. struct perf_file_section {
  54. u64 offset;
  55. u64 size;
  56. };
  57. struct perf_file_header {
  58. u64 magic;
  59. u64 size;
  60. u64 attr_size;
  61. struct perf_file_section attrs;
  62. struct perf_file_section data;
  63. /* event_types is ignored */
  64. struct perf_file_section event_types;
  65. DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
  66. };
  67. struct perf_pipe_file_header {
  68. u64 magic;
  69. u64 size;
  70. };
  71. struct perf_header;
  72. int perf_file_header__read(struct perf_file_header *header,
  73. struct perf_header *ph, int fd);
  74. struct perf_header {
  75. enum perf_header_version version;
  76. bool needs_swap;
  77. u64 data_offset;
  78. u64 data_size;
  79. u64 feat_offset;
  80. DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
  81. struct perf_env env;
  82. };
  83. struct feat_fd {
  84. struct perf_header *ph;
  85. int fd;
  86. void *buf; /* Either buf != NULL or fd >= 0 */
  87. ssize_t offset;
  88. size_t size;
  89. struct evsel *events;
  90. };
  91. struct perf_header_feature_ops {
  92. int (*write)(struct feat_fd *ff, struct evlist *evlist);
  93. void (*print)(struct feat_fd *ff, FILE *fp);
  94. int (*process)(struct feat_fd *ff, void *data);
  95. const char *name;
  96. bool full_only;
  97. bool synthesize;
  98. };
  99. struct evlist;
  100. struct perf_session;
  101. struct perf_tool;
  102. union perf_event;
  103. int perf_session__read_header(struct perf_session *session);
  104. int perf_session__write_header(struct perf_session *session,
  105. struct evlist *evlist,
  106. int fd, bool at_exit);
  107. int perf_header__write_pipe(int fd);
  108. void perf_header__set_feat(struct perf_header *header, int feat);
  109. void perf_header__clear_feat(struct perf_header *header, int feat);
  110. bool perf_header__has_feat(const struct perf_header *header, int feat);
  111. int perf_header__set_cmdline(int argc, const char **argv);
  112. int perf_header__process_sections(struct perf_header *header, int fd,
  113. void *data,
  114. int (*process)(struct perf_file_section *section,
  115. struct perf_header *ph,
  116. int feat, int fd, void *data));
  117. int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
  118. int perf_event__process_feature(struct perf_session *session,
  119. union perf_event *event);
  120. int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
  121. struct evlist **pevlist);
  122. int perf_event__process_event_update(struct perf_tool *tool,
  123. union perf_event *event,
  124. struct evlist **pevlist);
  125. size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
  126. int perf_event__process_tracing_data(struct perf_session *session,
  127. union perf_event *event);
  128. int perf_event__process_build_id(struct perf_session *session,
  129. union perf_event *event);
  130. bool is_perf_magic(u64 magic);
  131. #define NAME_ALIGN 64
  132. struct feat_fd;
  133. int do_write(struct feat_fd *fd, const void *buf, size_t size);
  134. int write_padded(struct feat_fd *fd, const void *bf,
  135. size_t count, size_t count_aligned);
  136. /*
  137. * arch specific callback
  138. */
  139. int get_cpuid(char *buffer, size_t sz);
  140. char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused);
  141. int strcmp_cpuid_str(const char *s1, const char *s2);
  142. #endif /* __PERF_HEADER_H */