* [PATCH] perf: detect when perf.data file not closed out properly
@ 2013-05-08 15:08 David Ahern
2013-05-09 9:32 ` Ingo Molnar
0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2013-05-08 15:08 UTC (permalink / raw)
To: acme, linux-kernel
Cc: David Ahern, Ingo Molnar, Frederic Weisbecker, Peter Zijlstra,
Jiri Olsa, Namhyung Kim, Stephane Eranian
perf-record updates the header in the perf.data file at termination.
Without this update perf-report (and other processing builtins) cannot
properly read events from the file -- the algorithm in
__perf_session__process_events depends on the data_size which is read
from the file header and that function loops if data_size is 0.
Catch this condition when the file is opened and warn the user.
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
---
| 12 ++++++++++++
1 file changed, 12 insertions(+)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 326068a..aa42c8c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2802,6 +2802,18 @@ int perf_session__read_header(struct perf_session *session, int fd)
if (perf_file_header__read(&f_header, header, fd) < 0)
return -EINVAL;
+ /*
+ * sanity check that perf.data was written cleanly: data size
+ * is initialized to 0 and updated only if the on_exit function
+ * is run. If data size is still 0 then the file cannot be
+ * processed.
+ */
+ if (f_header.data.size == 0) {
+ pr_err("data size is 0. "
+ "Was the record command properly terminated?\n");
+ return -1;
+ }
+
nr_attrs = f_header.attrs.size / f_header.attr_size;
lseek(fd, f_header.attrs.offset, SEEK_SET);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: detect when perf.data file not closed out properly
2013-05-08 15:08 [PATCH] perf: detect when perf.data file not closed out properly David Ahern
@ 2013-05-09 9:32 ` Ingo Molnar
2013-05-09 13:59 ` David Ahern
0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2013-05-09 9:32 UTC (permalink / raw)
To: David Ahern
Cc: acme, linux-kernel, Frederic Weisbecker, Peter Zijlstra,
Jiri Olsa, Namhyung Kim, Stephane Eranian
* David Ahern <dsahern@gmail.com> wrote:
> + pr_err("data size is 0. "
> + "Was the record command properly terminated?\n");
Btw., a small stylistic request: please put user-visible strings into a
single line - even if it technically turns into an overlong line.
pr_err("data size is 0. Was the record command properly terminated?\n");
This 1) makes it easier for people to git grep the error text they are
seeing during usage 2) makes it easier for _developers_ to see the
messages they are outputing to users.
For example from the single-line output it's immediately visible that it
should be capitalized thusly:
pr_err("Data size is 0. Was the record command properly terminated?\n");
:-)
Thanks,
Ingo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: detect when perf.data file not closed out properly
2013-05-09 9:32 ` Ingo Molnar
@ 2013-05-09 13:59 ` David Ahern
0 siblings, 0 replies; 3+ messages in thread
From: David Ahern @ 2013-05-09 13:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: acme, linux-kernel, Frederic Weisbecker, Peter Zijlstra,
Jiri Olsa, Namhyung Kim, Stephane Eranian
On 5/9/13 3:32 AM, Ingo Molnar wrote:
>
> * David Ahern <dsahern@gmail.com> wrote:
>
>> + pr_err("data size is 0. "
>> + "Was the record command properly terminated?\n");
>
> Btw., a small stylistic request: please put user-visible strings into a
> single line - even if it technically turns into an overlong line.
>
> pr_err("data size is 0. Was the record command properly terminated?\n");
>
> This 1) makes it easier for people to git grep the error text they are
> seeing during usage 2) makes it easier for _developers_ to see the
> messages they are outputing to users.
Totally agree just battling the line length.
>
> For example from the single-line output it's immediately visible that it
> should be capitalized thusly:
>
> pr_err("Data size is 0. Was the record command properly terminated?\n");
>
Ok. Will re-send later today.
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-09 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-08 15:08 [PATCH] perf: detect when perf.data file not closed out properly David Ahern
2013-05-09 9:32 ` Ingo Molnar
2013-05-09 13:59 ` David Ahern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox