aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/header.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-11-19 11:55:55 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-19 12:47:17 -0500
commit4dc0a04bb18fe9b80cefa08694f46a3a19ebfe50 (patch)
tree6d3ff5b79e71985ef4691df2d47202a4f6c3bd53 /tools/perf/util/header.c
parent2446042c93bfc6eeebfc89e88fdef2435d2bb5c4 (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/header.c')
-rw-r--r--tools/perf/util/header.c52
1 files changed, 31 insertions, 21 deletions
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
81void 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
81int perf_header__add_attr(struct perf_header *self, 92int 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
444struct perf_header *perf_header__read(int fd) 453int 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
505u64 perf_header__sample_type(struct perf_header *header) 515u64 perf_header__sample_type(struct perf_header *header)