diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 12:13:04 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 12:41:47 -0400 |
commit | e6b6f6795265ec19ff35572f527bb74c07ff9399 (patch) | |
tree | 144f0b7db761410bab5f0bd79631de316c5542a3 /tools | |
parent | 0807d2d8a381f4fc600ad481c3e77e5cdb624eed (diff) |
perf evsel: Handle endianity in intval method
We were relying on the info in pevent, but since we have it in
perf_evsel, set up by the perf_session routine if read from a perf.data
file or by whoever creates the evsels, use it.
New 'perf test' entries will use it to parse locally generated events,
in a non perf.data centered workflow.
As well as use byteswap.h to get per arch optimized swap routines, like
other parts of perf (header, perf_evsel__parse_sample, symbol, etc)
already do.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-8tjuxk09mlsfmh7macgkxsip@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/evsel.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index fe9581b0323..c78e42ab977 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -1108,13 +1108,43 @@ u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, | |||
1108 | const char *name) | 1108 | const char *name) |
1109 | { | 1109 | { |
1110 | struct format_field *field = perf_evsel__field(evsel, name); | 1110 | struct format_field *field = perf_evsel__field(evsel, name); |
1111 | u64 val; | 1111 | void *ptr; |
1112 | u64 value; | ||
1112 | 1113 | ||
1113 | if (!field) | 1114 | if (!field) |
1114 | return 0; | 1115 | return 0; |
1115 | 1116 | ||
1116 | val = pevent_read_number(evsel->tp_format->pevent, | 1117 | ptr = sample->raw_data + field->offset; |
1117 | sample->raw_data + field->offset, field->size); | ||
1118 | return val; | ||
1119 | 1118 | ||
1119 | switch (field->size) { | ||
1120 | case 1: | ||
1121 | return *(u8 *)ptr; | ||
1122 | case 2: | ||
1123 | value = *(u16 *)ptr; | ||
1124 | break; | ||
1125 | case 4: | ||
1126 | value = *(u32 *)ptr; | ||
1127 | break; | ||
1128 | case 8: | ||
1129 | value = *(u64 *)ptr; | ||
1130 | break; | ||
1131 | default: | ||
1132 | return 0; | ||
1133 | } | ||
1134 | |||
1135 | if (!evsel->needs_swap) | ||
1136 | return value; | ||
1137 | |||
1138 | switch (field->size) { | ||
1139 | case 2: | ||
1140 | return bswap_16(value); | ||
1141 | case 4: | ||
1142 | return bswap_32(value); | ||
1143 | case 8: | ||
1144 | return bswap_64(value); | ||
1145 | default: | ||
1146 | return 0; | ||
1147 | } | ||
1148 | |||
1149 | return 0; | ||
1120 | } | 1150 | } |