Imported Upstream version 1.0.0
[platform/upstream/oprofile.git] / libperf_events / operf_event.h
1 /*
2  * @file pe_profiling/operf_event.h
3  * Definitions of structures and methods for handling perf_event data
4  * from the kernel.
5  *
6  * @remark Copyright 2011 OProfile authors
7  * @remark Read the file COPYING
8  *
9  * Created on: Dec 7, 2011
10  * @author Maynard Johnson
11  * (C) Copyright IBM Corp. 2011
12  */
13
14 #ifndef OPERF_EVENT_H_
15 #define OPERF_EVENT_H_
16
17 #include <limits.h>
18 #include <linux/perf_event.h>
19 #include <vector>
20 #include "op_types.h"
21
22
23 #define OP_MAX_EVT_NAME_LEN 64
24 #define OP_MAX_UM_NAME_LEN 64
25 #define OP_MAX_UM_NAME_STR_LEN 17
26 #define OP_MAX_NUM_EVENTS 512
27
28 struct ip_event {
29         struct perf_event_header header;
30         u64 ip;
31         u32 pid, tid;
32         unsigned char __more_data[];
33 };
34
35 struct mmap_event {
36         struct perf_event_header header;
37         u32 pid, tid;
38         u64 start;
39         u64 len;
40         u64 pgoff;
41         char filename[PATH_MAX];
42 };
43
44 struct comm_event {
45         struct perf_event_header header;
46         u32 pid, tid;
47         char comm[16];
48 };
49
50 struct fork_event {
51         struct perf_event_header header;
52         u32 pid, ppid;
53         u32 tid, ptid;
54         u64 time;
55 };
56
57 struct lost_event {
58         struct perf_event_header header;
59         u64 id;
60         u64 lost;
61 };
62
63 struct read_event {
64         struct perf_event_header header;
65         u32 pid, tid;
66         u64 value;
67         u64 time_enabled;
68         u64 time_running;
69         u64 id;
70 };
71
72 struct sample_event {
73         struct perf_event_header header;
74         u64 array[];
75 };
76
77 struct throttle_event {
78         struct perf_event_header header;
79         u64 time;
80         u64 id;
81         u64 stream_id;
82 };
83
84 typedef union event_union {
85         struct perf_event_header header;
86         struct ip_event ip;
87         struct mmap_event mmap;
88         struct comm_event comm;
89         struct fork_event fork;
90         struct lost_event lost;
91         struct read_event read;
92         struct sample_event sample;
93         struct throttle_event throttle;
94 } event_t;
95
96 struct mmap_data {
97         void *base;
98         u64 mask;
99         u64 prev;
100 };
101
102 struct ip_callchain {
103         u64 nr;
104         u64 ips[0];
105 };
106 struct sample_data {
107         u64 ip;
108         u32 pid, tid;
109         u64 time;
110         u64 addr;
111         u64 id;
112         u32 cpu;
113         u64 period;
114         u32 raw_size;
115         void *raw_data;
116         struct ip_callchain * callchain;
117 };
118
119
120 typedef struct operf_event {
121         char name[OP_MAX_EVT_NAME_LEN];
122         // code for perf_events
123         u64 evt_code;
124         /* Base event code for oprofile sample file management; may be the same as evt_code,
125          * but different for certain architectures (e.g., ppc64).  Also, when unit masks
126          * are used, the evt_code to be passed to perf_events includes both the
127          * base code from op_evt_code and the left-shifted unit mask bits.
128          */
129         u64 op_evt_code;
130         // Make the evt_um and count fields unsigned long to match op_default_event_descr
131         unsigned long evt_um;
132         char um_name[OP_MAX_UM_NAME_LEN];
133         unsigned long count;
134         bool no_kernel;
135         bool no_user;
136         bool no_hv;
137         bool mode_specified; /* user specified user or kernel modes */
138         bool umask_specified; /* user specified a unit mask */
139         char um_numeric_val_as_str[OP_MAX_UM_NAME_STR_LEN];
140         bool throttled;  /* set to true if the event is ever throttled */
141 } operf_event_t;
142
143 struct mmap_info {
144         u64 offset, file_data_size, file_data_offset, head;
145         char * buf;
146         int traceFD;
147 };
148
149
150 struct op_file_section {
151         u64 size;
152         u64 offset;
153 };
154
155 struct op_file_attr {
156         struct perf_event_attr  attr;
157         struct op_file_section ids;
158 };
159
160 struct op_header_evt_info {
161         struct perf_event_attr attr;
162         std::vector<u64> ids;
163         off_t id_offset;
164 };
165
166 struct OP_file_header {
167         u64                             magic;
168         u64                             size;
169         u64                             attr_size;
170         struct op_file_section  attrs;
171         struct op_file_section  data;
172 };
173
174 struct OP_header {
175         struct op_header_evt_info h_attrs[OP_MAX_NUM_EVENTS];
176         off_t                   attr_offset;
177         off_t                   data_offset;
178         u64                     data_size;
179 };
180 /* Some of the above definitions were borrowed from the perf tool's util/event.h file. */
181
182 #endif /* OPERF_EVENT_H_ */