Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 264098
b: refs/heads/master
c: 936be50
h: refs/heads/master
v: v3
  • Loading branch information
David Ahern authored and Arnaldo Carvalho de Melo committed Sep 23, 2011
1 parent 861cae3 commit b67ddd7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6bb8f311a870d6042e0310309eb3d607ae52fe3e
refs/heads/master: 936be50306a92356367f330ef9d44f1f62478d22
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static int test__basic_mmap(void)
}

err = perf_event__parse_sample(event, attr.sample_type, sample_size,
false, &sample);
false, &sample, false);
if (err) {
pr_err("Can't parse sample, err = %d\n", err);
goto out_munmap;
Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ const char *perf_event__name(unsigned int id);

int perf_event__parse_sample(const union perf_event *event, u64 type,
int sample_size, bool sample_id_all,
struct perf_sample *sample);
struct perf_sample *sample, bool swapped);

#endif /* __PERF_RECORD_H */
54 changes: 43 additions & 11 deletions trunk/tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Released under the GPL v2. (and only v2, not any later version)
*/

#include <byteswap.h>
#include "asm/bug.h"
#include "evsel.h"
#include "evlist.h"
#include "util.h"
Expand Down Expand Up @@ -342,10 +344,20 @@ static bool sample_overlap(const union perf_event *event,

int perf_event__parse_sample(const union perf_event *event, u64 type,
int sample_size, bool sample_id_all,
struct perf_sample *data)
struct perf_sample *data, bool swapped)
{
const u64 *array;

/*
* used for cross-endian analysis. See git commit 65014ab3
* for why this goofiness is needed.
*/
union {
u64 val64;
u32 val32[2];
} u;


data->cpu = data->pid = data->tid = -1;
data->stream_id = data->id = data->time = -1ULL;

Expand All @@ -366,9 +378,16 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
}

if (type & PERF_SAMPLE_TID) {
u32 *p = (u32 *)array;
data->pid = p[0];
data->tid = p[1];
u.val64 = *array;
if (swapped) {
/* undo swap of u64, then swap on individual u32s */
u.val64 = bswap_64(u.val64);
u.val32[0] = bswap_32(u.val32[0]);
u.val32[1] = bswap_32(u.val32[1]);
}

data->pid = u.val32[0];
data->tid = u.val32[1];
array++;
}

Expand All @@ -395,8 +414,15 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
}

if (type & PERF_SAMPLE_CPU) {
u32 *p = (u32 *)array;
data->cpu = *p;

u.val64 = *array;
if (swapped) {
/* undo swap of u64, then swap on individual u32s */
u.val64 = bswap_64(u.val64);
u.val32[0] = bswap_32(u.val32[0]);
}

data->cpu = u.val32[0];
array++;
}

Expand All @@ -423,18 +449,24 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
}

if (type & PERF_SAMPLE_RAW) {
u32 *p = (u32 *)array;
u.val64 = *array;
if (WARN_ONCE(swapped,
"Endianness of raw data not corrected!\n")) {
/* undo swap of u64, then swap on individual u32s */
u.val64 = bswap_64(u.val64);
u.val32[0] = bswap_32(u.val32[0]);
u.val32[1] = bswap_32(u.val32[1]);
}

if (sample_overlap(event, array, sizeof(u32)))
return -EFAULT;

data->raw_size = *p;
p++;
data->raw_size = u.val32[0];

if (sample_overlap(event, p, data->raw_size))
if (sample_overlap(event, &u.val32[1], data->raw_size))
return -EFAULT;

data->raw_data = p;
data->raw_data = &u.val32[1];
}

return 0;
Expand Down
3 changes: 2 additions & 1 deletion trunk/tools/perf/util/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ static inline int perf_session__parse_sample(struct perf_session *session,
{
return perf_event__parse_sample(event, session->sample_type,
session->sample_size,
session->sample_id_all, sample);
session->sample_id_all, sample,
session->header.needs_swap);
}

struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
Expand Down

0 comments on commit b67ddd7

Please sign in to comment.