Re: [PATCH] perf record: handle death by SIGTERM

From: David Ahern
Date: Mon May 06 2013 - 20:05:47 EST


On 5/6/13 4:40 PM, Stephane Eranian wrote:
This is a good fix. I have run into this infinite loop in perf report
many times.

The perf_file_header could use an 'I am sane' bit which is only set when the file is closed properly. Perhaps we could overload the magic field like this:

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 326068a..cd9fad6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2364,7 +2364,6 @@ out_err_write:
}

f_header = (struct perf_file_header){
- .magic = PERF_MAGIC,
.size = sizeof(f_header),
.attr_size = sizeof(f_attr),
.attrs = {
@@ -2382,6 +2381,8 @@ out_err_write:
};

memcpy(&f_header.adds_features, &header->adds_features, sizeof(header->adds_features));
+ if (at_exit)
+ f_header.magic = PERF_MAGIC,

lseek(fd, 0, SEEK_SET);
err = do_write(fd, &f_header, sizeof(f_header));

The perf magic is only written when the file is closed properly. In Mike's case you end up with the message (which can be enhanced)

magic/endian check failed
incompatible file format (rerun with -v to learn more)

which is better than an infinite loop.

David

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/