[tip:perf/core] perf tools: Ensure return negative value when write header error

From: tip-bot for Wang Nan
Date: Thu Oct 30 2014 - 02:45:57 EST


Commit-ID: ed3077585f2f041e0db0fc41060b69673e98963b
Gitweb: http://git.kernel.org/tip/ed3077585f2f041e0db0fc41060b69673e98963b
Author: Wang Nan <wangnan0@xxxxxxxxxx>
AuthorDate: Thu, 16 Oct 2014 11:08:29 +0800
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Wed, 29 Oct 2014 10:32:48 -0200

perf tools: Ensure return negative value when write header error

When 'perf record' write headers, it calls write_xxx in
tools/perf/util/header.c, and check return value. It rolls back all
working only when return value is negative.

This patch ensures write_cpudesc() and write_total_mem() return negative number
when error. Without this patch, headers reported by 'perf report' header is
error in some platform. Following output is caputured on ARM, which doesn't
contain "Processor" field in /proc/cpuinfo. See "cpudesc", "total memory" and
"cmdline" field.

bash-4.2# perf record ls
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.001 MB perf.data (~36 samples) ]
bash-4.2# perf report --stdio --header
Error:
The perf.data file has no samples!
# ========
# captured on: Fri Sep 12 10:09:10 2014
# hostname : arma15el
# os release : 3.17.0+
# perf version : 3.10.53
# arch : armv7l
# nrcpus online : 4
# nrcpus avail : 1
# cpudesc : (null)
# total memory : 0 kB
# cmdline :
# event : name = cycles, type = 0, config = 0x0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern = 0, excl_host = 0, excl_guest = 1, precise_ip = 0
# pmu mappings: not available
# ========
#

Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Li Zefan <lizefan@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung.kim@xxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Waiman Long <Waiman.Long@xxxxxx>
Link: http://lkml.kernel.org/r/1413428909-80017-1-git-send-email-wangnan0@xxxxxxxxxx
Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/header.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 26f5b2f..0ecf4a3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -601,8 +601,10 @@ static int __write_cpudesc(int fd, const char *cpuinfo_proc)
break;
}

- if (ret)
+ if (ret) {
+ ret = -1;
goto done;
+ }

s = buf;

@@ -965,7 +967,8 @@ static int write_total_mem(int fd, struct perf_header *h __maybe_unused,
n = sscanf(buf, "%*s %"PRIu64, &mem);
if (n == 1)
ret = do_write(fd, &mem, sizeof(mem));
- }
+ } else
+ ret = -1;
free(buf);
fclose(fp);
return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/