perf: detect when perf.data file not closed out properly
PATCH v2 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.
v2: put error message on one line
--- tools/perf/util/header.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/perf/util/header.c +11 -0
@@ -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 );
Signature · 1 line
1.7.10.1
Quoted 10 lines · David Ahern
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_eventsdepends on thedata_sizewhich is read from the file header and that function loops ifdata_sizeis 0.Catch this condition when the file is opened and warn the user.
v2: put error message on one line
Quoted 8 lines
Signed-off-by David Ahern <[email protected]>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]>
Thanks,
Ingo