Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Improve error reporting

In the current version, when using perf record, if something goes
wrong in tools/perf/builtin-record.c:375
session = perf_session__new(file, false, NULL);

The error message:
"Not enough memory for reading per file header"

is issued. This error message seems to be outdated and is not very
helpful. This patch proposes to replace this error message by
"Perf session creation failed"

I believe this issue has been brought to lkml:
https://lkml.org/lkml/2014/2/24/458
although this patch only tackles a (small) part of the issue.

Additionnaly, this patch improves error reporting in
tools/perf/util/data.c open_file_write.

Currently, if the call to open fails, the user is unaware of it.
This patch logs the error, before returning the error code to
the caller.

Reported-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Adrien BAK <adrien.bak@metascale.org>
Link: http://lkml.kernel.org/r/1397786443.3093.4.camel@beast
[ Reorganize the changelog into paragraphs ]
[ Added empty line after fd declaration in open_file_write ]
Signed-off-by: Jiri Olsa <jolsa@redhat.com>

authored by

Adrien BAK and committed by
Jiri Olsa
ffa91880 922d0e4d

+9 -2
+1 -1
tools/perf/builtin-record.c
··· 374 374 375 375 session = perf_session__new(file, false, NULL); 376 376 if (session == NULL) { 377 - pr_err("Not enough memory for reading perf file header\n"); 377 + pr_err("Perf session creation failed.\n"); 378 378 return -1; 379 379 } 380 380
+8 -1
tools/perf/util/data.c
··· 86 86 87 87 static int open_file_write(struct perf_data_file *file) 88 88 { 89 + int fd; 90 + 89 91 if (check_backup(file)) 90 92 return -1; 91 93 92 - return open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); 94 + fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); 95 + 96 + if (fd < 0) 97 + pr_err("failed to open %s : %s\n", file->path, strerror(errno)); 98 + 99 + return fd; 93 100 } 94 101 95 102 static int open_file(struct perf_data_file *file)