Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: [PATCH] perf: detect when perf.data file not closed out properly

0 views
Skip to first unread message

Ingo Molnar

unread,
May 9, 2013, 5:33:34 AM5/9/13
to David Ahern, ac...@ghostprotocols.net, linux-...@vger.kernel.org, Frederic Weisbecker, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Stephane Eranian

* David Ahern <dsa...@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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

David Ahern

unread,
May 9, 2013, 7:09:28 AM5/9/13
to ac...@ghostprotocols.net, linux-...@vger.kernel.org, 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 <dsa...@gmail.com>
Cc: Arnaldo Carvalho de Melo <ac...@ghostprotocols.net>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Jiri Olsa <jo...@redhat.com>
Cc: Namhyung Kim <namh...@kernel.org>
Cc: Stephane Eranian <era...@google.com>
---
tools/perf/util/header.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --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

David Ahern

unread,
May 9, 2013, 9:59:38 AM5/9/13
to Ingo Molnar, ac...@ghostprotocols.net, linux-...@vger.kernel.org, Frederic Weisbecker, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Stephane Eranian
On 5/9/13 3:32 AM, Ingo Molnar wrote:
>
> * David Ahern <dsa...@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

David Ahern

unread,
May 9, 2013, 6:59:52 PM5/9/13
to ac...@ghostprotocols.net, linux-...@vger.kernel.org, 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.

v2: put error message on one line

Signed-off-by: David Ahern <dsa...@gmail.com>
Cc: Arnaldo Carvalho de Melo <ac...@ghostprotocols.net>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Jiri Olsa <jo...@redhat.com>
Cc: Namhyung Kim <namh...@kernel.org>
Cc: Stephane Eranian <era...@google.com>
---
tools/perf/util/header.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 326068a..95baef4 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2802,6 +2802,17 @@ 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

Ingo Molnar

unread,
May 10, 2013, 9:34:03 AM5/10/13
to David Ahern, ac...@ghostprotocols.net, linux-...@vger.kernel.org, Frederic Weisbecker, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Stephane Eranian

* David Ahern <dsa...@gmail.com> wrote:

> 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.
>
> v2: put error message on one line
>
> Signed-off-by: David Ahern <dsa...@gmail.com>
> Cc: Arnaldo Carvalho de Melo <ac...@ghostprotocols.net>
> Cc: Ingo Molnar <mi...@kernel.org>
> Cc: Frederic Weisbecker <fwei...@gmail.com>
> Cc: Peter Zijlstra <pet...@infradead.org>
> Cc: Jiri Olsa <jo...@redhat.com>
> Cc: Namhyung Kim <namh...@kernel.org>
> Cc: Stephane Eranian <era...@google.com>

Acked-by: Ingo Molnar <mi...@kernel.org>

Thanks,

Ingo
0 new messages