Messages in this thread Patch in this message | | | From | Jiri Olsa <> | Subject | [PATCH 09/25] perf tools: Introduce perf data file version CHECK macro | Date | Sun, 1 Sep 2013 12:36:20 +0200 |
| |
Introducing perf data file version CHECK macro, so the check is easily extensible for new versions.
Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> --- 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 a33197a..bcded62 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2496,18 +2496,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
| |