diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-19 11:55:55 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-19 12:47:17 -0500 |
commit | 4dc0a04bb18fe9b80cefa08694f46a3a19ebfe50 (patch) | |
tree | 6d3ff5b79e71985ef4691df2d47202a4f6c3bd53 /tools/perf/util | |
parent | 2446042c93bfc6eeebfc89e88fdef2435d2bb5c4 (diff) |
perf tools: perf_header__read() shouldn't die()
And also don't call the constructor in it, this way it adheres
to the model the other methods follow.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1258649757-17554-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/data_map.c | 18 | ||||
-rw-r--r-- | tools/perf/util/header.c | 52 | ||||
-rw-r--r-- | tools/perf/util/header.h | 7 |
3 files changed, 48 insertions, 29 deletions
diff --git a/tools/perf/util/data_map.c b/tools/perf/util/data_map.c index 14cb8465eb08..b8fc0fa2f632 100644 --- a/tools/perf/util/data_map.c +++ b/tools/perf/util/data_map.c | |||
@@ -106,7 +106,7 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, | |||
106 | int *cwdlen, | 106 | int *cwdlen, |
107 | char **cwd) | 107 | char **cwd) |
108 | { | 108 | { |
109 | int ret, rc = EXIT_FAILURE; | 109 | int err, rc = EXIT_FAILURE; |
110 | struct perf_header *header; | 110 | struct perf_header *header; |
111 | unsigned long head, shift; | 111 | unsigned long head, shift; |
112 | unsigned long offset = 0; | 112 | unsigned long offset = 0; |
@@ -132,8 +132,8 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, | |||
132 | exit(-1); | 132 | exit(-1); |
133 | } | 133 | } |
134 | 134 | ||
135 | ret = fstat(input, &input_stat); | 135 | err = fstat(input, &input_stat); |
136 | if (ret < 0) { | 136 | if (err < 0) { |
137 | perror("failed to stat file"); | 137 | perror("failed to stat file"); |
138 | exit(-1); | 138 | exit(-1); |
139 | } | 139 | } |
@@ -149,8 +149,16 @@ int mmap_dispatch_perf_file(struct perf_header **pheader, | |||
149 | exit(0); | 149 | exit(0); |
150 | } | 150 | } |
151 | 151 | ||
152 | *pheader = perf_header__read(input); | 152 | header = perf_header__new(); |
153 | header = *pheader; | 153 | if (header == NULL) |
154 | return -ENOMEM; | ||
155 | |||
156 | err = perf_header__read(header, input); | ||
157 | if (err < 0) { | ||
158 | perf_header__delete(header); | ||
159 | return err; | ||
160 | } | ||
161 | *pheader = header; | ||
154 | head = header->data_offset; | 162 | head = header->data_offset; |
155 | 163 | ||
156 | sample_type = perf_header__sample_type(header); | 164 | sample_type = perf_header__sample_type(header); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 425a29ba01a9..e66c7bd4cc88 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -78,16 +78,24 @@ struct perf_header *perf_header__new(void) | |||
78 | return self; | 78 | return self; |
79 | } | 79 | } |
80 | 80 | ||
81 | void perf_header__delete(struct perf_header *self) | ||
82 | { | ||
83 | int i; | ||
84 | |||
85 | for (i = 0; i < self->attrs; ++i) | ||
86 | perf_header_attr__delete(self->attr[i]); | ||
87 | |||
88 | free(self->attr); | ||
89 | free(self); | ||
90 | } | ||
91 | |||
81 | int perf_header__add_attr(struct perf_header *self, | 92 | int perf_header__add_attr(struct perf_header *self, |
82 | struct perf_header_attr *attr) | 93 | struct perf_header_attr *attr) |
83 | { | 94 | { |
84 | int pos = self->attrs; | ||
85 | |||
86 | if (self->frozen) | 95 | if (self->frozen) |
87 | return -1; | 96 | return -1; |
88 | 97 | ||
89 | self->attrs++; | 98 | if (self->attrs == self->size) { |
90 | if (self->attrs > self->size) { | ||
91 | int nsize = self->size * 2; | 99 | int nsize = self->size * 2; |
92 | struct perf_header_attr **nattr; | 100 | struct perf_header_attr **nattr; |
93 | 101 | ||
@@ -98,7 +106,8 @@ int perf_header__add_attr(struct perf_header *self, | |||
98 | self->size = nsize; | 106 | self->size = nsize; |
99 | self->attr = nattr; | 107 | self->attr = nattr; |
100 | } | 108 | } |
101 | self->attr[pos] = attr; | 109 | |
110 | self->attr[self->attrs++] = attr; | ||
102 | return 0; | 111 | return 0; |
103 | } | 112 | } |
104 | 113 | ||
@@ -441,19 +450,17 @@ static int perf_file_section__process(struct perf_file_section *self, | |||
441 | return 0; | 450 | return 0; |
442 | } | 451 | } |
443 | 452 | ||
444 | struct perf_header *perf_header__read(int fd) | 453 | int perf_header__read(struct perf_header *self, int fd) |
445 | { | 454 | { |
446 | struct perf_header *self = perf_header__new(); | ||
447 | struct perf_file_header f_header; | 455 | struct perf_file_header f_header; |
448 | struct perf_file_attr f_attr; | 456 | struct perf_file_attr f_attr; |
449 | u64 f_id; | 457 | u64 f_id; |
450 | int nr_attrs, nr_ids, i, j; | 458 | int nr_attrs, nr_ids, i, j; |
451 | 459 | ||
452 | if (self == NULL) | 460 | if (perf_file_header__read(&f_header, self, fd) < 0) { |
453 | die("nomem"); | 461 | pr_debug("incompatible file format\n"); |
454 | 462 | return -EINVAL; | |
455 | if (perf_file_header__read(&f_header, self, fd) < 0) | 463 | } |
456 | die("incompatible file format"); | ||
457 | 464 | ||
458 | nr_attrs = f_header.attrs.size / sizeof(f_attr); | 465 | nr_attrs = f_header.attrs.size / sizeof(f_attr); |
459 | lseek(fd, f_header.attrs.offset, SEEK_SET); | 466 | lseek(fd, f_header.attrs.offset, SEEK_SET); |
@@ -467,7 +474,7 @@ struct perf_header *perf_header__read(int fd) | |||
467 | 474 | ||
468 | attr = perf_header_attr__new(&f_attr.attr); | 475 | attr = perf_header_attr__new(&f_attr.attr); |
469 | if (attr == NULL) | 476 | if (attr == NULL) |
470 | die("nomem"); | 477 | return -ENOMEM; |
471 | 478 | ||
472 | nr_ids = f_attr.ids.size / sizeof(u64); | 479 | nr_ids = f_attr.ids.size / sizeof(u64); |
473 | lseek(fd, f_attr.ids.offset, SEEK_SET); | 480 | lseek(fd, f_attr.ids.offset, SEEK_SET); |
@@ -475,11 +482,15 @@ struct perf_header *perf_header__read(int fd) | |||
475 | for (j = 0; j < nr_ids; j++) { | 482 | for (j = 0; j < nr_ids; j++) { |
476 | do_read(fd, &f_id, sizeof(f_id)); | 483 | do_read(fd, &f_id, sizeof(f_id)); |
477 | 484 | ||
478 | if (perf_header_attr__add_id(attr, f_id) < 0) | 485 | if (perf_header_attr__add_id(attr, f_id) < 0) { |
479 | die("nomem"); | 486 | perf_header_attr__delete(attr); |
487 | return -ENOMEM; | ||
488 | } | ||
489 | } | ||
490 | if (perf_header__add_attr(self, attr) < 0) { | ||
491 | perf_header_attr__delete(attr); | ||
492 | return -ENOMEM; | ||
480 | } | 493 | } |
481 | if (perf_header__add_attr(self, attr) < 0) | ||
482 | die("nomem"); | ||
483 | 494 | ||
484 | lseek(fd, tmp, SEEK_SET); | 495 | lseek(fd, tmp, SEEK_SET); |
485 | } | 496 | } |
@@ -487,8 +498,8 @@ struct perf_header *perf_header__read(int fd) | |||
487 | if (f_header.event_types.size) { | 498 | if (f_header.event_types.size) { |
488 | lseek(fd, f_header.event_types.offset, SEEK_SET); | 499 | lseek(fd, f_header.event_types.offset, SEEK_SET); |
489 | events = malloc(f_header.event_types.size); | 500 | events = malloc(f_header.event_types.size); |
490 | if (!events) | 501 | if (events == NULL) |
491 | die("nomem"); | 502 | return -ENOMEM; |
492 | do_read(fd, events, f_header.event_types.size); | 503 | do_read(fd, events, f_header.event_types.size); |
493 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); | 504 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); |
494 | } | 505 | } |
@@ -498,8 +509,7 @@ struct perf_header *perf_header__read(int fd) | |||
498 | lseek(fd, self->data_offset, SEEK_SET); | 509 | lseek(fd, self->data_offset, SEEK_SET); |
499 | 510 | ||
500 | self->frozen = 1; | 511 | self->frozen = 1; |
501 | 512 | return 0; | |
502 | return self; | ||
503 | } | 513 | } |
504 | 514 | ||
505 | u64 perf_header__sample_type(struct perf_header *header) | 515 | u64 perf_header__sample_type(struct perf_header *header) |
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index f46a94e09eea..dc8fedb066ab 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -55,7 +55,10 @@ struct perf_header { | |||
55 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); | 55 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
56 | }; | 56 | }; |
57 | 57 | ||
58 | struct perf_header *perf_header__read(int fd); | 58 | struct perf_header *perf_header__new(void); |
59 | void perf_header__delete(struct perf_header *self); | ||
60 | |||
61 | int perf_header__read(struct perf_header *self, int fd); | ||
59 | void perf_header__write(struct perf_header *self, int fd, bool at_exit); | 62 | void perf_header__write(struct perf_header *self, int fd, bool at_exit); |
60 | 63 | ||
61 | int perf_header__add_attr(struct perf_header *self, | 64 | int perf_header__add_attr(struct perf_header *self, |
@@ -75,8 +78,6 @@ perf_header__find_attr(u64 id, struct perf_header *header); | |||
75 | void perf_header__set_feat(struct perf_header *self, int feat); | 78 | void perf_header__set_feat(struct perf_header *self, int feat); |
76 | bool perf_header__has_feat(const struct perf_header *self, int feat); | 79 | bool perf_header__has_feat(const struct perf_header *self, int feat); |
77 | 80 | ||
78 | struct perf_header *perf_header__new(void); | ||
79 | |||
80 | int perf_header__process_sections(struct perf_header *self, int fd, | 81 | int perf_header__process_sections(struct perf_header *self, int fd, |
81 | int (*process)(struct perf_file_section *self, | 82 | int (*process)(struct perf_file_section *self, |
82 | int feat, int fd)); | 83 | int feat, int fd)); |