blob: 29ccbfdf87245136c227da56ca92f8f64650ef71 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
John Kacur8b40f522009-09-24 18:02:18 +02002#ifndef __PERF_HEADER_H
3#define __PERF_HEADER_H
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +02004
David Howellsd2709c72012-11-19 22:21:03 +00005#include <linux/perf_event.h>
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +02006#include <sys/types.h>
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -02007#include <stdbool.h>
Borislav Petkovd944c4e2014-04-25 21:31:02 +02008#include <linux/bitmap.h>
9#include <linux/types.h>
Arnaldo Carvalho de Meloef12a142010-01-20 15:28:45 -020010#include "event.h"
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030011#include "env.h"
Frederic Weisbeckerdb9f11e2009-10-17 17:57:18 +020012
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020013enum {
Robert Richterb1e5a9b2011-12-07 10:02:57 +010014 HEADER_RESERVED = 0, /* always cleared */
Robert Richter781ba9d2011-12-15 17:32:40 +010015 HEADER_FIRST_FEATURE = 1,
Stephane Eranian2eeaaa02012-05-15 13:28:13 +020016 HEADER_TRACING_DATA = 1,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020017 HEADER_BUILD_ID,
Stephane Eranianfbe96f22011-09-30 15:40:40 +020018
19 HEADER_HOSTNAME,
20 HEADER_OSRELEASE,
21 HEADER_VERSION,
22 HEADER_ARCH,
23 HEADER_NRCPUS,
24 HEADER_CPUDESC,
25 HEADER_CPUID,
26 HEADER_TOTAL_MEM,
27 HEADER_CMDLINE,
28 HEADER_EVENT_DESC,
29 HEADER_CPU_TOPOLOGY,
30 HEADER_NUMA_TOPOLOGY,
Stephane Eranian330aa672012-03-08 23:47:46 +010031 HEADER_BRANCH_STACK,
Robert Richter50a96672012-08-16 21:10:24 +020032 HEADER_PMU_MAPPINGS,
Namhyung Kima8bb5592013-01-22 18:09:31 +090033 HEADER_GROUP_DESC,
Adrian Hunter4025ea42015-04-09 18:53:41 +030034 HEADER_AUXTRACE,
Jiri Olsaffa517a2015-10-25 15:51:43 +010035 HEADER_STAT,
Jiri Olsa720e98b2016-02-16 16:01:43 +010036 HEADER_CACHE,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020037 HEADER_LAST_FEATURE,
Robert Richterb1e5a9b2011-12-07 10:02:57 +010038 HEADER_FEAT_BITS = 256,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020039};
Frederic Weisbecker2ba08252009-10-17 17:12:34 +020040
Jiri Olsa2a08c3e2013-07-17 19:49:47 +020041enum perf_header_version {
42 PERF_HEADER_VERSION_1,
43 PERF_HEADER_VERSION_2,
44};
45
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020046struct perf_file_section {
47 u64 offset;
48 u64 size;
49};
50
51struct perf_file_header {
52 u64 magic;
53 u64 size;
54 u64 attr_size;
55 struct perf_file_section attrs;
56 struct perf_file_section data;
Jiri Olsa44b3c572013-07-11 17:28:31 +020057 /* event_types is ignored */
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020058 struct perf_file_section event_types;
59 DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
60};
61
Tom Zanussi8dc58102010-04-01 23:59:15 -050062struct perf_pipe_file_header {
63 u64 magic;
64 u64 size;
65};
66
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020067struct perf_header;
68
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -030069int perf_file_header__read(struct perf_file_header *header,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020070 struct perf_header *ph, int fd);
71
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020072struct perf_header {
Jiri Olsa2a08c3e2013-07-17 19:49:47 +020073 enum perf_header_version version;
74 bool needs_swap;
75 u64 data_offset;
76 u64 data_size;
77 u64 feat_offset;
Frederic Weisbeckerdb9f11e2009-10-17 17:57:18 +020078 DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
Kan Liangce80d3b2015-08-28 05:48:04 -040079 struct perf_env env;
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020080};
81
Arnaldo Carvalho de Melo361c99a2011-01-11 20:56:53 -020082struct perf_evlist;
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020083struct perf_session;
Arnaldo Carvalho de Melo361c99a2011-01-11 20:56:53 -020084
Jiri Olsad4339562013-07-17 19:49:41 +020085int perf_session__read_header(struct perf_session *session);
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -030086int perf_session__write_header(struct perf_session *session,
87 struct perf_evlist *evlist,
88 int fd, bool at_exit);
Tom Zanussi8dc58102010-04-01 23:59:15 -050089int perf_header__write_pipe(int fd);
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020090
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -030091void perf_header__set_feat(struct perf_header *header, int feat);
92void perf_header__clear_feat(struct perf_header *header, int feat);
93bool perf_header__has_feat(const struct perf_header *header, int feat);
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020094
Stephane Eranianfbe96f22011-09-30 15:40:40 +020095int perf_header__set_cmdline(int argc, const char **argv);
96
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -030097int perf_header__process_sections(struct perf_header *header, int fd,
Stephane Eranianfbe96f22011-09-30 15:40:40 +020098 void *data,
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -030099 int (*process)(struct perf_file_section *section,
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200100 struct perf_header *ph,
101 int feat, int fd, void *data));
102
103int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -0200104
David Carrillo-Cisnerose9def1b2017-07-17 21:25:48 -0700105int perf_event__synthesize_features(struct perf_tool *tool,
106 struct perf_session *session,
107 struct perf_evlist *evlist,
108 perf_event__handler_t process);
109
110int perf_event__process_feature(struct perf_tool *tool,
111 union perf_event *event,
112 struct perf_session *session);
113
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200114int perf_event__synthesize_attr(struct perf_tool *tool,
Robert Richterf4d83432012-08-16 21:10:17 +0200115 struct perf_event_attr *attr, u32 ids, u64 *id,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200116 perf_event__handler_t process);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200117int perf_event__synthesize_attrs(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200118 struct perf_session *session,
119 perf_event__handler_t process);
Jiri Olsaa6e52812015-10-25 15:51:37 +0100120int perf_event__synthesize_event_update_unit(struct perf_tool *tool,
121 struct perf_evsel *evsel,
122 perf_event__handler_t process);
Jiri Olsadaeecbc2015-10-25 15:51:38 +0100123int perf_event__synthesize_event_update_scale(struct perf_tool *tool,
124 struct perf_evsel *evsel,
125 perf_event__handler_t process);
Jiri Olsa802c9042015-10-25 15:51:39 +0100126int perf_event__synthesize_event_update_name(struct perf_tool *tool,
127 struct perf_evsel *evsel,
128 perf_event__handler_t process);
Jiri Olsa86ebb092015-10-25 15:51:40 +0100129int perf_event__synthesize_event_update_cpus(struct perf_tool *tool,
130 struct perf_evsel *evsel,
131 perf_event__handler_t process);
Adrian Hunter47c3d102013-07-04 16:20:21 +0300132int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
133 struct perf_evlist **pevlist);
Arnaldo Carvalho de Melob8f8eb82016-03-22 13:09:37 -0300134int perf_event__process_event_update(struct perf_tool *tool,
Jiri Olsaffe777252015-10-25 15:51:36 +0100135 union perf_event *event,
136 struct perf_evlist **pevlist);
Jiri Olsac853f932015-10-25 15:51:41 +0100137size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
Tom Zanussicd19a032010-04-01 23:59:20 -0500138
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200139int perf_event__synthesize_tracing_data(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200140 int fd, struct perf_evlist *evlist,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200141 perf_event__handler_t process);
Adrian Hunter47c3d102013-07-04 16:20:21 +0300142int perf_event__process_tracing_data(struct perf_tool *tool,
143 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200144 struct perf_session *session);
145
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200146int perf_event__synthesize_build_id(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200147 struct dso *pos, u16 misc,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200148 perf_event__handler_t process,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200149 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200150int perf_event__process_build_id(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200151 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200152 struct perf_session *session);
Feng Tange84ba4e2012-10-30 11:56:07 +0800153bool is_perf_magic(u64 magic);
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200154
Namhyung Kime195fac2014-11-04 10:14:30 +0900155#define NAME_ALIGN 64
156
David Carrillo-Cisnerosccebbeb2017-07-17 21:25:39 -0700157struct feat_fd;
David Carrillo-Cisneros3b8f51a2017-07-17 21:25:38 -0700158
David Carrillo-Cisnerosccebbeb2017-07-17 21:25:39 -0700159int do_write(struct feat_fd *fd, const void *buf, size_t size);
160
161int write_padded(struct feat_fd *fd, const void *bf,
162 size_t count, size_t count_aligned);
Adrian Hunter1f625b02014-07-22 16:17:23 +0300163
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200164/*
165 * arch specific callback
166 */
167int get_cpuid(char *buffer, size_t sz);
168
Sukadev Bhattiprolu933f82f2016-09-15 15:24:40 -0700169char *get_cpuid_str(void);
John Kacur8b40f522009-09-24 18:02:18 +0200170#endif /* __PERF_HEADER_H */