0001
0002 #ifndef __PERF_HEADER_H
0003 #define __PERF_HEADER_H
0004
0005 #include <linux/stddef.h>
0006 #include <linux/perf_event.h>
0007 #include <sys/types.h>
0008 #include <stdio.h> // FILE
0009 #include <stdbool.h>
0010 #include <linux/bitmap.h>
0011 #include <linux/types.h>
0012 #include "env.h"
0013 #include "pmu.h"
0014
0015 enum {
0016 HEADER_RESERVED = 0,
0017 HEADER_FIRST_FEATURE = 1,
0018 HEADER_TRACING_DATA = 1,
0019 HEADER_BUILD_ID,
0020
0021 HEADER_HOSTNAME,
0022 HEADER_OSRELEASE,
0023 HEADER_VERSION,
0024 HEADER_ARCH,
0025 HEADER_NRCPUS,
0026 HEADER_CPUDESC,
0027 HEADER_CPUID,
0028 HEADER_TOTAL_MEM,
0029 HEADER_CMDLINE,
0030 HEADER_EVENT_DESC,
0031 HEADER_CPU_TOPOLOGY,
0032 HEADER_NUMA_TOPOLOGY,
0033 HEADER_BRANCH_STACK,
0034 HEADER_PMU_MAPPINGS,
0035 HEADER_GROUP_DESC,
0036 HEADER_AUXTRACE,
0037 HEADER_STAT,
0038 HEADER_CACHE,
0039 HEADER_SAMPLE_TIME,
0040 HEADER_MEM_TOPOLOGY,
0041 HEADER_CLOCKID,
0042 HEADER_DIR_FORMAT,
0043 HEADER_BPF_PROG_INFO,
0044 HEADER_BPF_BTF,
0045 HEADER_COMPRESSED,
0046 HEADER_CPU_PMU_CAPS,
0047 HEADER_CLOCK_DATA,
0048 HEADER_HYBRID_TOPOLOGY,
0049 HEADER_PMU_CAPS,
0050 HEADER_LAST_FEATURE,
0051 HEADER_FEAT_BITS = 256,
0052 };
0053
0054 enum perf_header_version {
0055 PERF_HEADER_VERSION_1,
0056 PERF_HEADER_VERSION_2,
0057 };
0058
0059 struct perf_file_section {
0060 u64 offset;
0061 u64 size;
0062 };
0063
0064 struct perf_file_header {
0065 u64 magic;
0066 u64 size;
0067 u64 attr_size;
0068 struct perf_file_section attrs;
0069 struct perf_file_section data;
0070
0071 struct perf_file_section event_types;
0072 DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
0073 };
0074
0075 struct perf_pipe_file_header {
0076 u64 magic;
0077 u64 size;
0078 };
0079
0080 struct perf_header;
0081
0082 int perf_file_header__read(struct perf_file_header *header,
0083 struct perf_header *ph, int fd);
0084
0085 struct perf_header {
0086 enum perf_header_version version;
0087 bool needs_swap;
0088 u64 data_offset;
0089 u64 data_size;
0090 u64 feat_offset;
0091 DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
0092 struct perf_env env;
0093 };
0094
0095 struct feat_fd {
0096 struct perf_header *ph;
0097 int fd;
0098 void *buf;
0099 ssize_t offset;
0100 size_t size;
0101 struct evsel *events;
0102 };
0103
0104 struct perf_header_feature_ops {
0105 int (*write)(struct feat_fd *ff, struct evlist *evlist);
0106 void (*print)(struct feat_fd *ff, FILE *fp);
0107 int (*process)(struct feat_fd *ff, void *data);
0108 const char *name;
0109 bool full_only;
0110 bool synthesize;
0111 };
0112
0113 struct evlist;
0114 struct perf_session;
0115 struct perf_tool;
0116 union perf_event;
0117
0118 int perf_session__read_header(struct perf_session *session, int repipe_fd);
0119 int perf_session__write_header(struct perf_session *session,
0120 struct evlist *evlist,
0121 int fd, bool at_exit);
0122 int perf_header__write_pipe(int fd);
0123
0124
0125 struct feat_writer {
0126 int (*write)(struct feat_writer *fw, void *buf, size_t sz);
0127 };
0128
0129
0130 struct feat_copier {
0131 int (*copy)(struct feat_copier *fc, int feat, struct feat_writer *fw);
0132 };
0133
0134 int perf_session__inject_header(struct perf_session *session,
0135 struct evlist *evlist,
0136 int fd,
0137 struct feat_copier *fc);
0138
0139 size_t perf_session__data_offset(const struct evlist *evlist);
0140
0141 void perf_header__set_feat(struct perf_header *header, int feat);
0142 void perf_header__clear_feat(struct perf_header *header, int feat);
0143 bool perf_header__has_feat(const struct perf_header *header, int feat);
0144
0145 int perf_header__set_cmdline(int argc, const char **argv);
0146
0147 int perf_header__process_sections(struct perf_header *header, int fd,
0148 void *data,
0149 int (*process)(struct perf_file_section *section,
0150 struct perf_header *ph,
0151 int feat, int fd, void *data));
0152
0153 int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
0154
0155 int perf_event__process_feature(struct perf_session *session,
0156 union perf_event *event);
0157 int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
0158 struct evlist **pevlist);
0159 int perf_event__process_event_update(struct perf_tool *tool,
0160 union perf_event *event,
0161 struct evlist **pevlist);
0162 size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
0163 int perf_event__process_tracing_data(struct perf_session *session,
0164 union perf_event *event);
0165 int perf_event__process_build_id(struct perf_session *session,
0166 union perf_event *event);
0167 bool is_perf_magic(u64 magic);
0168
0169 #define NAME_ALIGN 64
0170
0171 struct feat_fd;
0172
0173 int do_write(struct feat_fd *fd, const void *buf, size_t size);
0174
0175 int write_padded(struct feat_fd *fd, const void *bf,
0176 size_t count, size_t count_aligned);
0177
0178 int is_cpu_online(unsigned int cpu);
0179
0180
0181
0182 int get_cpuid(char *buffer, size_t sz);
0183
0184 char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused);
0185 int strcmp_cpuid_str(const char *s1, const char *s2);
0186 #endif