1 #ifndef __PERF_HEADER_H
2 #define __PERF_HEADER_H
3 
4 #include "../../../include/linux/perf_event.h"
5 #include <sys/types.h>
6 #include <stdbool.h>
7 #include "types.h"
8 #include "event.h"
9 
10 #include <linux/bitmap.h>
11 
12 enum {
13 	HEADER_TRACE_INFO = 1,
14 	HEADER_BUILD_ID,
15 	HEADER_LAST_FEATURE,
16 };
17 
18 #define HEADER_FEAT_BITS			256
19 
20 struct perf_file_section {
21 	u64 offset;
22 	u64 size;
23 };
24 
25 struct perf_file_header {
26 	u64				magic;
27 	u64				size;
28 	u64				attr_size;
29 	struct perf_file_section	attrs;
30 	struct perf_file_section	data;
31 	struct perf_file_section	event_types;
32 	DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
33 };
34 
35 struct perf_pipe_file_header {
36 	u64				magic;
37 	u64				size;
38 };
39 
40 struct perf_header;
41 
42 int perf_file_header__read(struct perf_file_header *header,
43 			   struct perf_header *ph, int fd);
44 
45 struct perf_header {
46 	int			frozen;
47 	bool			needs_swap;
48 	s64			attr_offset;
49 	u64			data_offset;
50 	u64			data_size;
51 	u64			event_offset;
52 	u64			event_size;
53 	DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
54 };
55 
56 struct perf_evlist;
57 
58 int perf_session__read_header(struct perf_session *session, int fd);
59 int perf_session__write_header(struct perf_session *session,
60 			       struct perf_evlist *evlist,
61 			       int fd, bool at_exit);
62 int perf_header__write_pipe(int fd);
63 
64 int perf_header__push_event(u64 id, const char *name);
65 char *perf_header__find_event(u64 id);
66 
67 u64 perf_evlist__sample_type(struct perf_evlist *evlist);
68 bool perf_evlist__sample_id_all(const struct perf_evlist *evlist);
69 void perf_header__set_feat(struct perf_header *header, int feat);
70 void perf_header__clear_feat(struct perf_header *header, int feat);
71 bool perf_header__has_feat(const struct perf_header *header, int feat);
72 
73 int perf_header__process_sections(struct perf_header *header, int fd,
74 				  int (*process)(struct perf_file_section *section,
75 						 struct perf_header *ph,
76 						 int feat, int fd));
77 
78 int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
79 			  const char *name, bool is_kallsyms);
80 int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
81 
82 int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
83 				perf_event__handler_t process,
84 				struct perf_session *session);
85 int perf_session__synthesize_attrs(struct perf_session *session,
86 				   perf_event__handler_t process);
87 int perf_event__process_attr(union perf_event *event, struct perf_session *session);
88 
89 int perf_event__synthesize_event_type(u64 event_id, char *name,
90 				      perf_event__handler_t process,
91 				      struct perf_session *session);
92 int perf_event__synthesize_event_types(perf_event__handler_t process,
93 				       struct perf_session *session);
94 int perf_event__process_event_type(union perf_event *event,
95 				   struct perf_session *session);
96 
97 int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist,
98 					perf_event__handler_t process,
99 					struct perf_session *session);
100 int perf_event__process_tracing_data(union perf_event *event,
101 				     struct perf_session *session);
102 
103 int perf_event__synthesize_build_id(struct dso *pos, u16 misc,
104 				    perf_event__handler_t process,
105 				    struct machine *machine,
106 				    struct perf_session *session);
107 int perf_event__process_build_id(union perf_event *event,
108 				 struct perf_session *session);
109 #endif /* __PERF_HEADER_H */
110