Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1 | #include <sys/types.h> |
| 2 | #include <unistd.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 5 | #include <linux/list.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 6 | |
| 7 | #include "util.h" |
| 8 | #include "header.h" |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 9 | #include "../perf.h" |
| 10 | #include "trace-event.h" |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 11 | #include "symbol.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 12 | |
| 13 | /* |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 14 | * Create new perf.data header attribute: |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 15 | */ |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 16 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 17 | { |
| 18 | struct perf_header_attr *self = malloc(sizeof(*self)); |
| 19 | |
| 20 | if (!self) |
| 21 | die("nomem"); |
| 22 | |
| 23 | self->attr = *attr; |
| 24 | self->ids = 0; |
| 25 | self->size = 1; |
| 26 | self->id = malloc(sizeof(u64)); |
| 27 | |
| 28 | if (!self->id) |
| 29 | die("nomem"); |
| 30 | |
| 31 | return self; |
| 32 | } |
| 33 | |
| 34 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) |
| 35 | { |
| 36 | int pos = self->ids; |
| 37 | |
| 38 | self->ids++; |
| 39 | if (self->ids > self->size) { |
| 40 | self->size *= 2; |
| 41 | self->id = realloc(self->id, self->size * sizeof(u64)); |
| 42 | if (!self->id) |
| 43 | die("nomem"); |
| 44 | } |
| 45 | self->id[pos] = id; |
| 46 | } |
| 47 | |
| 48 | /* |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 49 | * Create new perf.data header: |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 50 | */ |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 51 | struct perf_header *perf_header__new(void) |
| 52 | { |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 53 | struct perf_header *self = calloc(sizeof(*self), 1); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 54 | |
| 55 | if (!self) |
| 56 | die("nomem"); |
| 57 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 58 | self->size = 1; |
| 59 | self->attr = malloc(sizeof(void *)); |
| 60 | |
| 61 | if (!self->attr) |
| 62 | die("nomem"); |
| 63 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 64 | return self; |
| 65 | } |
| 66 | |
| 67 | void perf_header__add_attr(struct perf_header *self, |
| 68 | struct perf_header_attr *attr) |
| 69 | { |
| 70 | int pos = self->attrs; |
| 71 | |
| 72 | if (self->frozen) |
| 73 | die("frozen"); |
| 74 | |
| 75 | self->attrs++; |
| 76 | if (self->attrs > self->size) { |
| 77 | self->size *= 2; |
| 78 | self->attr = realloc(self->attr, self->size * sizeof(void *)); |
| 79 | if (!self->attr) |
| 80 | die("nomem"); |
| 81 | } |
| 82 | self->attr[pos] = attr; |
| 83 | } |
| 84 | |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 85 | #define MAX_EVENT_NAME 64 |
| 86 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 87 | struct perf_trace_event_type { |
| 88 | u64 event_id; |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 89 | char name[MAX_EVENT_NAME]; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static int event_count; |
| 93 | static struct perf_trace_event_type *events; |
| 94 | |
| 95 | void perf_header__push_event(u64 id, const char *name) |
| 96 | { |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 97 | if (strlen(name) > MAX_EVENT_NAME) |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 98 | pr_warning("Event %s will be truncated\n", name); |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 99 | |
| 100 | if (!events) { |
| 101 | events = malloc(sizeof(struct perf_trace_event_type)); |
| 102 | if (!events) |
| 103 | die("nomem"); |
| 104 | } else { |
| 105 | events = realloc(events, (event_count + 1) * sizeof(struct perf_trace_event_type)); |
| 106 | if (!events) |
| 107 | die("nomem"); |
| 108 | } |
| 109 | memset(&events[event_count], 0, sizeof(struct perf_trace_event_type)); |
| 110 | events[event_count].event_id = id; |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 111 | strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1); |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 112 | event_count++; |
| 113 | } |
| 114 | |
| 115 | char *perf_header__find_event(u64 id) |
| 116 | { |
| 117 | int i; |
| 118 | for (i = 0 ; i < event_count; i++) { |
| 119 | if (events[i].event_id == id) |
| 120 | return events[i].name; |
| 121 | } |
| 122 | return NULL; |
| 123 | } |
| 124 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 125 | static const char *__perf_magic = "PERFFILE"; |
| 126 | |
| 127 | #define PERF_MAGIC (*(u64 *)__perf_magic) |
| 128 | |
| 129 | struct perf_file_section { |
| 130 | u64 offset; |
| 131 | u64 size; |
| 132 | }; |
| 133 | |
| 134 | struct perf_file_attr { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 135 | struct perf_event_attr attr; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 136 | struct perf_file_section ids; |
| 137 | }; |
| 138 | |
| 139 | struct perf_file_header { |
| 140 | u64 magic; |
| 141 | u64 size; |
| 142 | u64 attr_size; |
| 143 | struct perf_file_section attrs; |
| 144 | struct perf_file_section data; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 145 | struct perf_file_section event_types; |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 146 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 149 | void perf_header__feat_trace_info(struct perf_header *header) |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 150 | { |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 151 | set_bit(HEADER_TRACE_INFO, header->adds_features); |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 154 | void perf_header__set_feat(struct perf_header *self, int feat) |
| 155 | { |
| 156 | set_bit(feat, self->adds_features); |
| 157 | } |
| 158 | |
| 159 | bool perf_header__has_feat(const struct perf_header *self, int feat) |
| 160 | { |
| 161 | return test_bit(feat, self->adds_features); |
| 162 | } |
| 163 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 164 | static void do_write(int fd, void *buf, size_t size) |
| 165 | { |
| 166 | while (size) { |
| 167 | int ret = write(fd, buf, size); |
| 168 | |
| 169 | if (ret < 0) |
| 170 | die("failed to write"); |
| 171 | |
| 172 | size -= ret; |
| 173 | buf += ret; |
| 174 | } |
| 175 | } |
| 176 | |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame^] | 177 | static void write_buildid_table(int fd, struct list_head *id_head) |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 178 | { |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame^] | 179 | struct build_id_list *iter, *next; |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 180 | |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame^] | 181 | list_for_each_entry_safe(iter, next, id_head, list) { |
| 182 | struct build_id_event *b = &iter->event; |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 183 | |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame^] | 184 | do_write(fd, b, sizeof(*b)); |
| 185 | do_write(fd, (void *)iter->dso_name, iter->len); |
| 186 | list_del(&iter->list); |
| 187 | free(iter); |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 188 | } |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static void |
| 192 | perf_header__adds_write(struct perf_header *self, int fd, bool at_exit) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 193 | { |
| 194 | struct perf_file_section trace_sec; |
| 195 | u64 cur_offset = lseek(fd, 0, SEEK_CUR); |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 196 | unsigned long *feat_mask = self->adds_features; |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 197 | |
| 198 | if (test_bit(HEADER_TRACE_INFO, feat_mask)) { |
| 199 | /* Write trace info */ |
| 200 | trace_sec.offset = lseek(fd, sizeof(trace_sec), SEEK_CUR); |
| 201 | read_tracing_data(fd, attrs, nr_counters); |
| 202 | trace_sec.size = lseek(fd, 0, SEEK_CUR) - trace_sec.offset; |
| 203 | |
| 204 | /* Write trace info headers */ |
| 205 | lseek(fd, cur_offset, SEEK_SET); |
| 206 | do_write(fd, &trace_sec, sizeof(trace_sec)); |
| 207 | |
| 208 | /* |
| 209 | * Update cur_offset. So that other (future) |
| 210 | * features can set their own infos in this place. But if we are |
| 211 | * the only feature, at least that seeks to the place the data |
| 212 | * should begin. |
| 213 | */ |
| 214 | cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); |
| 215 | } |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 216 | |
| 217 | if (at_exit) { |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame^] | 218 | LIST_HEAD(id_list); |
| 219 | |
| 220 | if (fetch_build_id_table(&id_list)) { |
| 221 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 222 | perf_header__set_feat(self, HEADER_BUILD_ID); |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame^] | 223 | write_buildid_table(fd, &id_list); |
| 224 | lseek(fd, cur_offset, SEEK_SET); |
| 225 | } |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 226 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 227 | }; |
| 228 | |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 229 | void perf_header__write(struct perf_header *self, int fd, bool at_exit) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 230 | { |
| 231 | struct perf_file_header f_header; |
| 232 | struct perf_file_attr f_attr; |
| 233 | struct perf_header_attr *attr; |
| 234 | int i; |
| 235 | |
| 236 | lseek(fd, sizeof(f_header), SEEK_SET); |
| 237 | |
| 238 | |
| 239 | for (i = 0; i < self->attrs; i++) { |
| 240 | attr = self->attr[i]; |
| 241 | |
| 242 | attr->id_offset = lseek(fd, 0, SEEK_CUR); |
| 243 | do_write(fd, attr->id, attr->ids * sizeof(u64)); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | self->attr_offset = lseek(fd, 0, SEEK_CUR); |
| 248 | |
| 249 | for (i = 0; i < self->attrs; i++) { |
| 250 | attr = self->attr[i]; |
| 251 | |
| 252 | f_attr = (struct perf_file_attr){ |
| 253 | .attr = attr->attr, |
| 254 | .ids = { |
| 255 | .offset = attr->id_offset, |
| 256 | .size = attr->ids * sizeof(u64), |
| 257 | } |
| 258 | }; |
| 259 | do_write(fd, &f_attr, sizeof(f_attr)); |
| 260 | } |
| 261 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 262 | self->event_offset = lseek(fd, 0, SEEK_CUR); |
| 263 | self->event_size = event_count * sizeof(struct perf_trace_event_type); |
| 264 | if (events) |
| 265 | do_write(fd, events, self->event_size); |
| 266 | |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 267 | perf_header__adds_write(self, fd, at_exit); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 268 | |
| 269 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
| 270 | |
| 271 | f_header = (struct perf_file_header){ |
| 272 | .magic = PERF_MAGIC, |
| 273 | .size = sizeof(f_header), |
| 274 | .attr_size = sizeof(f_attr), |
| 275 | .attrs = { |
| 276 | .offset = self->attr_offset, |
| 277 | .size = self->attrs * sizeof(f_attr), |
| 278 | }, |
| 279 | .data = { |
| 280 | .offset = self->data_offset, |
| 281 | .size = self->data_size, |
| 282 | }, |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 283 | .event_types = { |
| 284 | .offset = self->event_offset, |
| 285 | .size = self->event_size, |
| 286 | }, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 287 | }; |
| 288 | |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 289 | memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 290 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 291 | lseek(fd, 0, SEEK_SET); |
| 292 | do_write(fd, &f_header, sizeof(f_header)); |
| 293 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); |
| 294 | |
| 295 | self->frozen = 1; |
| 296 | } |
| 297 | |
| 298 | static void do_read(int fd, void *buf, size_t size) |
| 299 | { |
| 300 | while (size) { |
| 301 | int ret = read(fd, buf, size); |
| 302 | |
| 303 | if (ret < 0) |
| 304 | die("failed to read"); |
Pierre Habouzit | 7eac7e9 | 2009-08-07 14:16:00 +0200 | [diff] [blame] | 305 | if (ret == 0) |
| 306 | die("failed to read: missing data"); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 307 | |
| 308 | size -= ret; |
| 309 | buf += ret; |
| 310 | } |
| 311 | } |
| 312 | |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 313 | static void perf_header__adds_read(struct perf_header *self, int fd) |
| 314 | { |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 315 | const unsigned long *feat_mask = self->adds_features; |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 316 | |
| 317 | if (test_bit(HEADER_TRACE_INFO, feat_mask)) { |
| 318 | struct perf_file_section trace_sec; |
| 319 | |
| 320 | do_read(fd, &trace_sec, sizeof(trace_sec)); |
| 321 | lseek(fd, trace_sec.offset, SEEK_SET); |
| 322 | trace_report(fd); |
| 323 | lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); |
| 324 | } |
| 325 | }; |
| 326 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 327 | struct perf_header *perf_header__read(int fd) |
| 328 | { |
| 329 | struct perf_header *self = perf_header__new(); |
| 330 | struct perf_file_header f_header; |
| 331 | struct perf_file_attr f_attr; |
| 332 | u64 f_id; |
| 333 | |
| 334 | int nr_attrs, nr_ids, i, j; |
| 335 | |
| 336 | lseek(fd, 0, SEEK_SET); |
| 337 | do_read(fd, &f_header, sizeof(f_header)); |
| 338 | |
| 339 | if (f_header.magic != PERF_MAGIC || |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 340 | f_header.attr_size != sizeof(f_attr)) |
| 341 | die("incompatible file format"); |
| 342 | |
Frederic Weisbecker | 26dd2cb | 2009-10-08 22:07:29 +0200 | [diff] [blame] | 343 | if (f_header.size != sizeof(f_header)) { |
| 344 | /* Support the previous format */ |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 345 | if (f_header.size == offsetof(typeof(f_header), adds_features)) |
| 346 | bitmap_zero(f_header.adds_features, HEADER_FEAT_BITS); |
| 347 | else |
Frederic Weisbecker | 26dd2cb | 2009-10-08 22:07:29 +0200 | [diff] [blame] | 348 | die("incompatible file format"); |
| 349 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 350 | nr_attrs = f_header.attrs.size / sizeof(f_attr); |
| 351 | lseek(fd, f_header.attrs.offset, SEEK_SET); |
| 352 | |
| 353 | for (i = 0; i < nr_attrs; i++) { |
| 354 | struct perf_header_attr *attr; |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 355 | off_t tmp; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 356 | |
| 357 | do_read(fd, &f_attr, sizeof(f_attr)); |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 358 | tmp = lseek(fd, 0, SEEK_CUR); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 359 | |
| 360 | attr = perf_header_attr__new(&f_attr.attr); |
| 361 | |
| 362 | nr_ids = f_attr.ids.size / sizeof(u64); |
| 363 | lseek(fd, f_attr.ids.offset, SEEK_SET); |
| 364 | |
| 365 | for (j = 0; j < nr_ids; j++) { |
| 366 | do_read(fd, &f_id, sizeof(f_id)); |
| 367 | |
| 368 | perf_header_attr__add_id(attr, f_id); |
| 369 | } |
| 370 | perf_header__add_attr(self, attr); |
| 371 | lseek(fd, tmp, SEEK_SET); |
| 372 | } |
| 373 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 374 | if (f_header.event_types.size) { |
| 375 | lseek(fd, f_header.event_types.offset, SEEK_SET); |
| 376 | events = malloc(f_header.event_types.size); |
| 377 | if (!events) |
| 378 | die("nomem"); |
| 379 | do_read(fd, events, f_header.event_types.size); |
| 380 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); |
| 381 | } |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 382 | |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 383 | memcpy(&self->adds_features, &f_header.adds_features, sizeof(f_header.adds_features)); |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 384 | |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 385 | perf_header__adds_read(self, fd); |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 386 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 387 | self->event_offset = f_header.event_types.offset; |
| 388 | self->event_size = f_header.event_types.size; |
| 389 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 390 | self->data_offset = f_header.data.offset; |
| 391 | self->data_size = f_header.data.size; |
| 392 | |
Ingo Molnar | 2e01d17 | 2009-09-03 16:21:11 +0200 | [diff] [blame] | 393 | lseek(fd, self->data_offset, SEEK_SET); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 394 | |
| 395 | self->frozen = 1; |
| 396 | |
| 397 | return self; |
| 398 | } |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 399 | |
| 400 | u64 perf_header__sample_type(struct perf_header *header) |
| 401 | { |
| 402 | u64 type = 0; |
| 403 | int i; |
| 404 | |
| 405 | for (i = 0; i < header->attrs; i++) { |
| 406 | struct perf_header_attr *attr = header->attr[i]; |
| 407 | |
| 408 | if (!type) |
| 409 | type = attr->attr.sample_type; |
| 410 | else if (type != attr->attr.sample_type) |
| 411 | die("non matching sample_type"); |
| 412 | } |
| 413 | |
| 414 | return type; |
| 415 | } |
| 416 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 417 | struct perf_event_attr * |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 418 | perf_header__find_attr(u64 id, struct perf_header *header) |
| 419 | { |
| 420 | int i; |
| 421 | |
| 422 | for (i = 0; i < header->attrs; i++) { |
| 423 | struct perf_header_attr *attr = header->attr[i]; |
| 424 | int j; |
| 425 | |
| 426 | for (j = 0; j < attr->ids; j++) { |
| 427 | if (attr->id[j] == id) |
| 428 | return &attr->attr; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | return NULL; |
| 433 | } |