diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-16 22:18:09 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-17 01:19:54 -0500 |
commit | 11deb1f9f6ca6318fa9470e024b9f0634df48b4c (patch) | |
tree | 3f1e18ccaffa47e1a139c1f2f12f94510c3a4751 /tools/perf/util | |
parent | 1124ba73be6a758965340bd997593b2996649d60 (diff) |
perf tools: Don't die() in perf_header__add_attr()
Propagate the errors instead, the users are the ones to decide
what to do if a library call fails.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1258427892-16312-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/header.c | 30 | ||||
-rw-r--r-- | tools/perf/util/header.h | 6 |
2 files changed, 26 insertions, 10 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 2f07a238ffdf..23ccddae0b06 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -33,6 +33,12 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) | |||
33 | return self; | 33 | return self; |
34 | } | 34 | } |
35 | 35 | ||
36 | void perf_header_attr__delete(struct perf_header_attr *self) | ||
37 | { | ||
38 | free(self->id); | ||
39 | free(self); | ||
40 | } | ||
41 | |||
36 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) | 42 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) |
37 | { | 43 | { |
38 | int pos = self->ids; | 44 | int pos = self->ids; |
@@ -66,22 +72,28 @@ struct perf_header *perf_header__new(void) | |||
66 | return self; | 72 | return self; |
67 | } | 73 | } |
68 | 74 | ||
69 | void perf_header__add_attr(struct perf_header *self, | 75 | int perf_header__add_attr(struct perf_header *self, |
70 | struct perf_header_attr *attr) | 76 | struct perf_header_attr *attr) |
71 | { | 77 | { |
72 | int pos = self->attrs; | 78 | int pos = self->attrs; |
73 | 79 | ||
74 | if (self->frozen) | 80 | if (self->frozen) |
75 | die("frozen"); | 81 | return -1; |
76 | 82 | ||
77 | self->attrs++; | 83 | self->attrs++; |
78 | if (self->attrs > self->size) { | 84 | if (self->attrs > self->size) { |
79 | self->size *= 2; | 85 | int nsize = self->size * 2; |
80 | self->attr = realloc(self->attr, self->size * sizeof(void *)); | 86 | struct perf_header_attr **nattr; |
81 | if (!self->attr) | 87 | |
82 | die("nomem"); | 88 | nattr = realloc(self->attr, nsize * sizeof(void *)); |
89 | if (nattr == NULL) | ||
90 | return -1; | ||
91 | |||
92 | self->size = nsize; | ||
93 | self->attr = nattr; | ||
83 | } | 94 | } |
84 | self->attr[pos] = attr; | 95 | self->attr[pos] = attr; |
96 | return 0; | ||
85 | } | 97 | } |
86 | 98 | ||
87 | #define MAX_EVENT_NAME 64 | 99 | #define MAX_EVENT_NAME 64 |
@@ -434,7 +446,9 @@ struct perf_header *perf_header__read(int fd) | |||
434 | 446 | ||
435 | perf_header_attr__add_id(attr, f_id); | 447 | perf_header_attr__add_id(attr, f_id); |
436 | } | 448 | } |
437 | perf_header__add_attr(self, attr); | 449 | if (perf_header__add_attr(self, attr) < 0) |
450 | die("nomem"); | ||
451 | |||
438 | lseek(fd, tmp, SEEK_SET); | 452 | lseek(fd, tmp, SEEK_SET); |
439 | } | 453 | } |
440 | 454 | ||
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 0cbd4c9e982c..b0d5cd707a7b 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -58,13 +58,15 @@ struct perf_header { | |||
58 | struct perf_header *perf_header__read(int fd); | 58 | struct perf_header *perf_header__read(int fd); |
59 | void perf_header__write(struct perf_header *self, int fd, bool at_exit); | 59 | void perf_header__write(struct perf_header *self, int fd, bool at_exit); |
60 | 60 | ||
61 | void perf_header__add_attr(struct perf_header *self, | 61 | int perf_header__add_attr(struct perf_header *self, |
62 | struct perf_header_attr *attr); | 62 | struct perf_header_attr *attr); |
63 | 63 | ||
64 | void perf_header__push_event(u64 id, const char *name); | 64 | void perf_header__push_event(u64 id, const char *name); |
65 | char *perf_header__find_event(u64 id); | 65 | char *perf_header__find_event(u64 id); |
66 | 66 | ||
67 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); | 67 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); |
68 | void perf_header_attr__delete(struct perf_header_attr *self); | ||
69 | |||
68 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); | 70 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); |
69 | 71 | ||
70 | u64 perf_header__sample_type(struct perf_header *header); | 72 | u64 perf_header__sample_type(struct perf_header *header); |