Skip to contentSkip to conversation

perf: detect when perf.data file not closed out properly

PATCH Superseded David Ahern 2 participants 3 messages May 8, 2013 – May 9, 2013 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: detect when perf.data file not closed out properly

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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/header.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/perf/util/header.c +12 -0
index 326068a..aa42c8c 100644
@@ -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);
 
Signature · 1 line
1.7.10.1
#1 lore raw

tools/perf/util/header.c int perf_session__read_header(struct perf_session *session, int fd) · line 2813

Quoted 2 lines · David Ahern
tools/perf/util/header.c +2 -0
+		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

#2 lore raw
Quoted 9 lines · Ingo Molnar

tools/perf/util/header.c int perf_session__read_header(struct perf_session *session, int fd) · line 2813

Quoted 2 lines · David Ahern
tools/perf/util/header.c +2 -0
+		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.

Quoted 5 lines
		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.

Quoted 6 lines

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