header.h 4.3 KB

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