diff options
author | David Ahern <dsahern@gmail.com> | 2011-07-15 14:34:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-08-05 00:58:35 -0400 |
commit | 5dd830d09df97bc9318d6e0841fcf652bdc46bfa (patch) | |
tree | 093da618b5afc26c3074b6c6f52cabeace91599b /tools/perf | |
parent | 64d488f079f68f58210f4c79c7e76b04a7c9db20 (diff) |
perf tools: Fix endian conversion reading event attr from file header
commit eda3913bb70ecebac13adccffe1e7f96e93cee02 upstream.
The perf_event_attr struct has two __u32's at the top and
they need to be swapped individually.
With this change I was able to analyze a perf.data collected in a
32-bit PPC VM on an x86 system. I tested both 32-bit and 64-bit
binaries for the Intel analysis side; both read the PPC perf.data
file correctly.
-v2:
- changed the existing perf_event__attr_swap() to swap only elements
of perf_event_attr and exported it for use in swapping the
attributes in the file header
- updated swap_ops used for processing events
Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: acme@ghostprotocols.net
Cc: peterz@infradead.org
Cc: paulus@samba.org
Link: http://lkml.kernel.org/r/1310754849-12474-1-git-send-email-dsahern@gmail.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/header.c | 5 | ||||
-rw-r--r-- | tools/perf/util/session.c | 30 | ||||
-rw-r--r-- | tools/perf/util/session.h | 1 |
3 files changed, 23 insertions, 13 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index afb0849fe53..cb2959a3fb4 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -877,9 +877,12 @@ int perf_session__read_header(struct perf_session *session, int fd) | |||
877 | struct perf_evsel *evsel; | 877 | struct perf_evsel *evsel; |
878 | off_t tmp; | 878 | off_t tmp; |
879 | 879 | ||
880 | if (perf_header__getbuffer64(header, fd, &f_attr, sizeof(f_attr))) | 880 | if (readn(fd, &f_attr, sizeof(f_attr)) <= 0) |
881 | goto out_errno; | 881 | goto out_errno; |
882 | 882 | ||
883 | if (header->needs_swap) | ||
884 | perf_event__attr_swap(&f_attr.attr); | ||
885 | |||
883 | tmp = lseek(fd, 0, SEEK_CUR); | 886 | tmp = lseek(fd, 0, SEEK_CUR); |
884 | evsel = perf_evsel__new(&f_attr.attr, i); | 887 | evsel = perf_evsel__new(&f_attr.attr, i); |
885 | 888 | ||
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index f5a8fbdd3f7..2dbf0abd8e1 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -407,20 +407,26 @@ static void perf_event__read_swap(union perf_event *event) | |||
407 | event->read.id = bswap_64(event->read.id); | 407 | event->read.id = bswap_64(event->read.id); |
408 | } | 408 | } |
409 | 409 | ||
410 | static void perf_event__attr_swap(union perf_event *event) | 410 | /* exported for swapping attributes in file header */ |
411 | void perf_event__attr_swap(struct perf_event_attr *attr) | ||
412 | { | ||
413 | attr->type = bswap_32(attr->type); | ||
414 | attr->size = bswap_32(attr->size); | ||
415 | attr->config = bswap_64(attr->config); | ||
416 | attr->sample_period = bswap_64(attr->sample_period); | ||
417 | attr->sample_type = bswap_64(attr->sample_type); | ||
418 | attr->read_format = bswap_64(attr->read_format); | ||
419 | attr->wakeup_events = bswap_32(attr->wakeup_events); | ||
420 | attr->bp_type = bswap_32(attr->bp_type); | ||
421 | attr->bp_addr = bswap_64(attr->bp_addr); | ||
422 | attr->bp_len = bswap_64(attr->bp_len); | ||
423 | } | ||
424 | |||
425 | static void perf_event__hdr_attr_swap(union perf_event *event) | ||
411 | { | 426 | { |
412 | size_t size; | 427 | size_t size; |
413 | 428 | ||
414 | event->attr.attr.type = bswap_32(event->attr.attr.type); | 429 | perf_event__attr_swap(&event->attr.attr); |
415 | event->attr.attr.size = bswap_32(event->attr.attr.size); | ||
416 | event->attr.attr.config = bswap_64(event->attr.attr.config); | ||
417 | event->attr.attr.sample_period = bswap_64(event->attr.attr.sample_period); | ||
418 | event->attr.attr.sample_type = bswap_64(event->attr.attr.sample_type); | ||
419 | event->attr.attr.read_format = bswap_64(event->attr.attr.read_format); | ||
420 | event->attr.attr.wakeup_events = bswap_32(event->attr.attr.wakeup_events); | ||
421 | event->attr.attr.bp_type = bswap_32(event->attr.attr.bp_type); | ||
422 | event->attr.attr.bp_addr = bswap_64(event->attr.attr.bp_addr); | ||
423 | event->attr.attr.bp_len = bswap_64(event->attr.attr.bp_len); | ||
424 | 430 | ||
425 | size = event->header.size; | 431 | size = event->header.size; |
426 | size -= (void *)&event->attr.id - (void *)event; | 432 | size -= (void *)&event->attr.id - (void *)event; |
@@ -448,7 +454,7 @@ static perf_event__swap_op perf_event__swap_ops[] = { | |||
448 | [PERF_RECORD_LOST] = perf_event__all64_swap, | 454 | [PERF_RECORD_LOST] = perf_event__all64_swap, |
449 | [PERF_RECORD_READ] = perf_event__read_swap, | 455 | [PERF_RECORD_READ] = perf_event__read_swap, |
450 | [PERF_RECORD_SAMPLE] = perf_event__all64_swap, | 456 | [PERF_RECORD_SAMPLE] = perf_event__all64_swap, |
451 | [PERF_RECORD_HEADER_ATTR] = perf_event__attr_swap, | 457 | [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap, |
452 | [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, | 458 | [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, |
453 | [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap, | 459 | [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap, |
454 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, | 460 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 66d4e149087..b84c003189f 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -112,6 +112,7 @@ int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, | |||
112 | u64 addr); | 112 | u64 addr); |
113 | 113 | ||
114 | void mem_bswap_64(void *src, int byte_size); | 114 | void mem_bswap_64(void *src, int byte_size); |
115 | void perf_event__attr_swap(struct perf_event_attr *attr); | ||
115 | 116 | ||
116 | int perf_session__create_kernel_maps(struct perf_session *self); | 117 | int perf_session__create_kernel_maps(struct perf_session *self); |
117 | 118 | ||