aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--tools/perf/builtin-record.c16
-rw-r--r--tools/perf/builtin-timechart.c17
-rw-r--r--tools/perf/util/data_map.c18
-rw-r--r--tools/perf/util/header.c52
-rw-r--r--tools/perf/util/header.h7
5 files changed, 70 insertions, 40 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 82260c56db3d..c97cb2ca8fa4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -400,7 +400,7 @@ static int __cmd_record(int argc, const char **argv)
400 struct stat st; 400 struct stat st;
401 pid_t pid = 0; 401 pid_t pid = 0;
402 int flags; 402 int flags;
403 int ret; 403 int err;
404 unsigned long waking = 0; 404 unsigned long waking = 0;
405 405
406 page_size = sysconf(_SC_PAGE_SIZE); 406 page_size = sysconf(_SC_PAGE_SIZE);
@@ -434,16 +434,18 @@ static int __cmd_record(int argc, const char **argv)
434 exit(-1); 434 exit(-1);
435 } 435 }
436 436
437 if (!file_new) 437 header = perf_header__new();
438 header = perf_header__read(output);
439 else
440 header = perf_header__new();
441
442 if (header == NULL) { 438 if (header == NULL) {
443 pr_err("Not enough memory for reading perf file header\n"); 439 pr_err("Not enough memory for reading perf file header\n");
444 return -1; 440 return -1;
445 } 441 }
446 442
443 if (!file_new) {
444 err = perf_header__read(header, output);
445 if (err < 0)
446 return err;
447 }
448
447 if (raw_samples) { 449 if (raw_samples) {
448 perf_header__set_feat(header, HEADER_TRACE_INFO); 450 perf_header__set_feat(header, HEADER_TRACE_INFO);
449 } else { 451 } else {
@@ -527,7 +529,7 @@ static int __cmd_record(int argc, const char **argv)
527 if (hits == samples) { 529 if (hits == samples) {
528 if (done) 530 if (done)
529 break; 531 break;
530 ret = poll(event_array, nr_poll, -1); 532 err = poll(event_array, nr_poll, -1);
531 waking++; 533 waking++;
532 } 534 }
533 535
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 665877e4a944..dd4d82ac7aa4 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1093,7 +1093,7 @@ static void process_samples(void)
1093 1093
1094static int __cmd_timechart(void) 1094static int __cmd_timechart(void)
1095{ 1095{
1096 int ret, rc = EXIT_FAILURE; 1096 int err, rc = EXIT_FAILURE;
1097 unsigned long offset = 0; 1097 unsigned long offset = 0;
1098 unsigned long head, shift; 1098 unsigned long head, shift;
1099 struct stat statbuf; 1099 struct stat statbuf;
@@ -1111,8 +1111,8 @@ static int __cmd_timechart(void)
1111 exit(-1); 1111 exit(-1);
1112 } 1112 }
1113 1113
1114 ret = fstat(input, &statbuf); 1114 err = fstat(input, &statbuf);
1115 if (ret < 0) { 1115 if (err < 0) {
1116 perror("failed to stat file"); 1116 perror("failed to stat file");
1117 exit(-1); 1117 exit(-1);
1118 } 1118 }
@@ -1122,7 +1122,16 @@ static int __cmd_timechart(void)
1122 exit(0); 1122 exit(0);
1123 } 1123 }
1124 1124
1125 header = perf_header__read(input); 1125 header = perf_header__new();
1126 if (header == NULL)
1127 return -ENOMEM;
1128
1129 err = perf_header__read(header, input);
1130 if (err < 0) {
1131 perf_header__delete(header);
1132 return err;
1133 }
1134
1126 head = header->data_offset; 1135 head = header->data_offset;
1127 1136
1128 sample_type = perf_header__sample_type(header); 1137 sample_type = perf_header__sample_type(header);
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
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)
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
58struct perf_header *perf_header__read(int fd); 58struct perf_header *perf_header__new(void);
59void perf_header__delete(struct perf_header *self);
60
61int perf_header__read(struct perf_header *self, int fd);
59void perf_header__write(struct perf_header *self, int fd, bool at_exit); 62void perf_header__write(struct perf_header *self, int fd, bool at_exit);
60 63
61int perf_header__add_attr(struct perf_header *self, 64int perf_header__add_attr(struct perf_header *self,
@@ -75,8 +78,6 @@ perf_header__find_attr(u64 id, struct perf_header *header);
75void perf_header__set_feat(struct perf_header *self, int feat); 78void perf_header__set_feat(struct perf_header *self, int feat);
76bool perf_header__has_feat(const struct perf_header *self, int feat); 79bool perf_header__has_feat(const struct perf_header *self, int feat);
77 80
78struct perf_header *perf_header__new(void);
79
80int perf_header__process_sections(struct perf_header *self, int fd, 81int 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));