[PATCH 08/23] perf tools: Introduce perf data file version CHECK macro

From: Jiri Olsa
Date: Wed Jul 17 2013 - 13:56:13 EST


Introducing perf data file version CHECK macro, so the check
is easily extensible for new versions.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
---
tools/perf/util/header.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index f558f83..4ebe4a1 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2493,18 +2493,23 @@ static int check_magic_endian(u64 magic, uint64_t hdr_sz,
* - encode endianness of file
*/

- /* check magic number with one endianness */
- if (magic == __perf_magic2)
- return 0;
-
- /* check magic number with opposite endianness */
- if (magic != __perf_magic2_sw)
- return -1;
+#define CHECK(__m, __v) \
+do { \
+ /* check magic number with one endianness */ \
+ if (magic == __m) \
+ goto v ## __v; \
+ /* check magic number with opposite endianness */ \
+ if (magic != __m ## _sw) \
+ break; \
+ ph->needs_swap = true; \
+ v ## __v: \
+ ph->version = __v; \
+ return 0; \
+} while (0)
+
+ CHECK(__perf_magic2, PERF_HEADER_VERSION_2);

- ph->needs_swap = true;
- ph->version = PERF_HEADER_VERSION_2;
-
- return 0;
+ return -1;
}

int perf_file_header__read(struct perf_file_header *header,
--
1.7.11.7

--
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/