public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf session: Fix infinite loop on invalid perf.data file
@ 2013-09-30  8:19 Namhyung Kim
  2013-09-30 13:49 ` David Ahern
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Namhyung Kim @ 2013-09-30  8:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
	Jiri Olsa, David Ahern, Sonny Rao

From: Namhyung Kim <namhyung.kim@lge.com>

perf-record updates the header in the perf.data file at termination.
Without this update perf-report (and other processing built-ins) it
caused an infinite loop when perf report (or something like) called.

This is because the algorithm in __perf_session__process_events()
depends on the data_size which is read from file header.  Use file
size directly instead in this case to do the best-effort processing.

Cc: David Ahern <dsahern@gmail.com>
Cc: Sonny Rao <sonnyrao@chromium.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/header.c  | 9 +++++++++
 tools/perf/util/session.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 26441d0e571b..cedccde6a6b2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2753,6 +2753,15 @@ int perf_session__read_header(struct perf_session *session)
 	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 contains only partial
+	 * information.  Just warn user and process it as much as it can.
+	 */
+	if (f_header.data.size == 0)
+		pr_warning("Data size is 0. Was the record command properly terminated?\n");
+
 	nr_attrs = f_header.attrs.size / f_header.attr_size;
 	lseek(fd, f_header.attrs.offset, SEEK_SET);
 
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 6c1d4447c5b4..7bbd60c0a0ed 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1323,7 +1323,7 @@ int __perf_session__process_events(struct perf_session *session,
 	file_offset = page_offset;
 	head = data_offset - page_offset;
 
-	if (data_offset + data_size < file_size)
+	if (data_size && (data_offset + data_size < file_size))
 		file_size = data_offset + data_size;
 
 	progress_next = file_size / 16;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-10-08 10:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-30  8:19 [PATCH] perf session: Fix infinite loop on invalid perf.data file Namhyung Kim
2013-09-30 13:49 ` David Ahern
2013-10-01  0:28   ` Sonny Rao
2013-10-01  7:16 ` Ingo Molnar
2013-10-01 13:24   ` David Ahern
2013-10-01 14:21     ` Ingo Molnar
2013-10-01 14:43       ` David Ahern
2013-10-01 15:33         ` Ingo Molnar
2013-10-01 16:54           ` Arnaldo Carvalho de Melo
2013-10-01 16:59             ` David Ahern
2013-10-04 15:25               ` Arnaldo Carvalho de Melo
2013-10-04 15:33                 ` David Ahern
2013-10-01 18:06             ` Ingo Molnar
2013-10-08 10:41 ` [tip:perf/urgent] " tip-bot for Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox