Commit d5eed904 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar

perf tools: Eliminate some more die() uses in library functions

This time in perf_header__adds_write, propagating the do_write
error returns.
Signed-off-by: default avatarArnaldo 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-2-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 4dc0a04b
...@@ -474,8 +474,11 @@ static int __cmd_record(int argc, const char **argv) ...@@ -474,8 +474,11 @@ static int __cmd_record(int argc, const char **argv)
} }
} }
if (file_new) if (file_new) {
perf_header__write(header, output, false); err = perf_header__write(header, output, false);
if (err < 0)
return err;
}
if (!system_wide) if (!system_wide)
event__synthesize_thread(pid, process_synthesized_event); event__synthesize_thread(pid, process_synthesized_event);
......
...@@ -176,7 +176,7 @@ static int do_write(int fd, const void *buf, size_t size) ...@@ -176,7 +176,7 @@ static int do_write(int fd, const void *buf, size_t size)
int ret = write(fd, buf, size); int ret = write(fd, buf, size);
if (ret < 0) if (ret < 0)
return -1; return -errno;
size -= ret; size -= ret;
buf += ret; buf += ret;
...@@ -190,6 +190,7 @@ static int dsos__write_buildid_table(int fd) ...@@ -190,6 +190,7 @@ static int dsos__write_buildid_table(int fd)
struct dso *pos; struct dso *pos;
list_for_each_entry(pos, &dsos, node) { list_for_each_entry(pos, &dsos, node) {
int err;
struct build_id_event b; struct build_id_event b;
size_t len; size_t len;
...@@ -200,33 +201,35 @@ static int dsos__write_buildid_table(int fd) ...@@ -200,33 +201,35 @@ static int dsos__write_buildid_table(int fd)
memset(&b, 0, sizeof(b)); memset(&b, 0, sizeof(b));
memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
b.header.size = sizeof(b) + len; b.header.size = sizeof(b) + len;
if (do_write(fd, &b, sizeof(b)) < 0 || err = do_write(fd, &b, sizeof(b));
do_write(fd, pos->long_name, len) < 0) if (err < 0)
return -1; return err;
err = do_write(fd, pos->long_name, len);
if (err < 0)
return err;
} }
return 0; return 0;
} }
static void static int perf_header__adds_write(struct perf_header *self, int fd)
perf_header__adds_write(struct perf_header *self, int fd)
{ {
int nr_sections; int nr_sections;
struct perf_file_section *feat_sec; struct perf_file_section *feat_sec;
int sec_size; int sec_size;
u64 sec_start; u64 sec_start;
int idx = 0; int idx = 0, err;
if (dsos__read_build_ids()) if (dsos__read_build_ids())
perf_header__set_feat(self, HEADER_BUILD_ID); perf_header__set_feat(self, HEADER_BUILD_ID);
nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
if (!nr_sections) if (!nr_sections)
return; return 0;
feat_sec = calloc(sizeof(*feat_sec), nr_sections); feat_sec = calloc(sizeof(*feat_sec), nr_sections);
if (!feat_sec) if (feat_sec == NULL)
die("No memory"); return -ENOMEM;
sec_size = sizeof(*feat_sec) * nr_sections; sec_size = sizeof(*feat_sec) * nr_sections;
...@@ -258,23 +261,29 @@ perf_header__adds_write(struct perf_header *self, int fd) ...@@ -258,23 +261,29 @@ perf_header__adds_write(struct perf_header *self, int fd)
/* Write build-ids */ /* Write build-ids */
buildid_sec->offset = lseek(fd, 0, SEEK_CUR); buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
if (dsos__write_buildid_table(fd) < 0) err = dsos__write_buildid_table(fd);
die("failed to write buildid table"); if (err < 0) {
pr_debug("failed to write buildid table\n");
goto out_free;
}
buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset;
} }
lseek(fd, sec_start, SEEK_SET); lseek(fd, sec_start, SEEK_SET);
if (do_write(fd, feat_sec, sec_size) < 0) err = do_write(fd, feat_sec, sec_size);
die("failed to write feature section"); if (err < 0)
pr_debug("failed to write feature section\n");
out_free:
free(feat_sec); free(feat_sec);
return err;
} }
void perf_header__write(struct perf_header *self, int fd, bool at_exit) int perf_header__write(struct perf_header *self, int fd, bool at_exit)
{ {
struct perf_file_header f_header; struct perf_file_header f_header;
struct perf_file_attr f_attr; struct perf_file_attr f_attr;
struct perf_header_attr *attr; struct perf_header_attr *attr;
int i; int i, err;
lseek(fd, sizeof(f_header), SEEK_SET); lseek(fd, sizeof(f_header), SEEK_SET);
...@@ -283,8 +292,11 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) ...@@ -283,8 +292,11 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
attr = self->attr[i]; attr = self->attr[i];
attr->id_offset = lseek(fd, 0, SEEK_CUR); attr->id_offset = lseek(fd, 0, SEEK_CUR);
if (do_write(fd, attr->id, attr->ids * sizeof(u64)) < 0) err = do_write(fd, attr->id, attr->ids * sizeof(u64));
die("failed to write perf header"); if (err < 0) {
pr_debug("failed to write perf header\n");
return err;
}
} }
...@@ -300,20 +312,30 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) ...@@ -300,20 +312,30 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
.size = attr->ids * sizeof(u64), .size = attr->ids * sizeof(u64),
} }
}; };
if (do_write(fd, &f_attr, sizeof(f_attr)) < 0) err = do_write(fd, &f_attr, sizeof(f_attr));
die("failed to write perf header attribute"); if (err < 0) {
pr_debug("failed to write perf header attribute\n");
return err;
}
} }
self->event_offset = lseek(fd, 0, SEEK_CUR); self->event_offset = lseek(fd, 0, SEEK_CUR);
self->event_size = event_count * sizeof(struct perf_trace_event_type); self->event_size = event_count * sizeof(struct perf_trace_event_type);
if (events) if (events) {
if (do_write(fd, events, self->event_size) < 0) err = do_write(fd, events, self->event_size);
die("failed to write perf header events"); if (err < 0) {
pr_debug("failed to write perf header events\n");
return err;
}
}
self->data_offset = lseek(fd, 0, SEEK_CUR); self->data_offset = lseek(fd, 0, SEEK_CUR);
if (at_exit) if (at_exit) {
perf_header__adds_write(self, fd); err = perf_header__adds_write(self, fd);
if (err < 0)
return err;
}
f_header = (struct perf_file_header){ f_header = (struct perf_file_header){
.magic = PERF_MAGIC, .magic = PERF_MAGIC,
...@@ -336,11 +358,15 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit) ...@@ -336,11 +358,15 @@ void perf_header__write(struct perf_header *self, int fd, bool at_exit)
memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features));
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
if (do_write(fd, &f_header, sizeof(f_header)) < 0) err = do_write(fd, &f_header, sizeof(f_header));
die("failed to write perf header"); if (err < 0) {
pr_debug("failed to write perf header\n");
return err;
}
lseek(fd, self->data_offset + self->data_size, SEEK_SET); lseek(fd, self->data_offset + self->data_size, SEEK_SET);
self->frozen = 1; self->frozen = 1;
return 0;
} }
static void do_read(int fd, void *buf, size_t size) static void do_read(int fd, void *buf, size_t size)
......
...@@ -59,7 +59,7 @@ struct perf_header *perf_header__new(void); ...@@ -59,7 +59,7 @@ struct perf_header *perf_header__new(void);
void perf_header__delete(struct perf_header *self); void perf_header__delete(struct perf_header *self);
int perf_header__read(struct perf_header *self, int fd); int perf_header__read(struct perf_header *self, int fd);
void perf_header__write(struct perf_header *self, int fd, bool at_exit); int perf_header__write(struct perf_header *self, int fd, bool at_exit);
int perf_header__add_attr(struct perf_header *self, int perf_header__add_attr(struct perf_header *self,
struct perf_header_attr *attr); struct perf_header_attr *attr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment