diff options
| author | Ingo Molnar <mingo@kernel.org> | 2014-07-05 05:29:32 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2014-07-05 05:29:32 -0400 |
| commit | 8b5b584daf3b92fc5cdc83919e64231817d2f5a7 (patch) | |
| tree | 20519c481b8233a3efda947ea0c7202e4881b087 /tools | |
| parent | 432100ba2aacc2146a2b1f26e5b5ae5d6e29972a (diff) | |
| parent | 8ac631cd502d6b31fd29f6d019305305b479fa3e (diff) | |
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/core
Pull perf/core improvements and fixes from Jiri Olsa:
* Handle the num array type in python properly (Sebastian Andrzej Siewior)
* Fix wrong condition for allocation failure (Jiri Olsa)
* Adjust callchain based on DWARF debug info on powerpc (Sukadev Bhattiprolu)
* Fix a risk for doing free on uninitialized pointer in traceevent lib (Rickard Strandqvist)
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/lib/traceevent/event-parse.c | 6 | ||||
| -rw-r--r-- | tools/perf/arch/powerpc/Makefile | 1 | ||||
| -rw-r--r-- | tools/perf/arch/powerpc/util/skip-callchain-idx.c | 266 | ||||
| -rw-r--r-- | tools/perf/builtin-stat.c | 2 | ||||
| -rw-r--r-- | tools/perf/config/Makefile | 4 | ||||
| -rw-r--r-- | tools/perf/util/callchain.h | 13 | ||||
| -rw-r--r-- | tools/perf/util/machine.c | 18 | ||||
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 57 |
8 files changed, 346 insertions, 21 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 93825a17dcce..cf3a44bf1ec3 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
| @@ -2395,7 +2395,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 2395 | { | 2395 | { |
| 2396 | struct print_arg *field; | 2396 | struct print_arg *field; |
| 2397 | enum event_type type; | 2397 | enum event_type type; |
| 2398 | char *token; | 2398 | char *token = NULL; |
| 2399 | 2399 | ||
| 2400 | memset(arg, 0, sizeof(*arg)); | 2400 | memset(arg, 0, sizeof(*arg)); |
| 2401 | arg->type = PRINT_FLAGS; | 2401 | arg->type = PRINT_FLAGS; |
| @@ -2448,7 +2448,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 2448 | { | 2448 | { |
| 2449 | struct print_arg *field; | 2449 | struct print_arg *field; |
| 2450 | enum event_type type; | 2450 | enum event_type type; |
| 2451 | char *token; | 2451 | char *token = NULL; |
| 2452 | 2452 | ||
| 2453 | memset(arg, 0, sizeof(*arg)); | 2453 | memset(arg, 0, sizeof(*arg)); |
| 2454 | arg->type = PRINT_SYMBOL; | 2454 | arg->type = PRINT_SYMBOL; |
| @@ -2487,7 +2487,7 @@ process_hex(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 2487 | { | 2487 | { |
| 2488 | struct print_arg *field; | 2488 | struct print_arg *field; |
| 2489 | enum event_type type; | 2489 | enum event_type type; |
| 2490 | char *token; | 2490 | char *token = NULL; |
| 2491 | 2491 | ||
| 2492 | memset(arg, 0, sizeof(*arg)); | 2492 | memset(arg, 0, sizeof(*arg)); |
| 2493 | arg->type = PRINT_HEX; | 2493 | arg->type = PRINT_HEX; |
diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile index 744e629797be..b92219b1900d 100644 --- a/tools/perf/arch/powerpc/Makefile +++ b/tools/perf/arch/powerpc/Makefile | |||
| @@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1 | |||
| 3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | 3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o |
| 4 | endif | 4 | endif |
| 5 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o | 5 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o |
| 6 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/skip-callchain-idx.o | ||
diff --git a/tools/perf/arch/powerpc/util/skip-callchain-idx.c b/tools/perf/arch/powerpc/util/skip-callchain-idx.c new file mode 100644 index 000000000000..a7c23a4b3778 --- /dev/null +++ b/tools/perf/arch/powerpc/util/skip-callchain-idx.c | |||
| @@ -0,0 +1,266 @@ | |||
| 1 | /* | ||
| 2 | * Use DWARF Debug information to skip unnecessary callchain entries. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Sukadev Bhattiprolu, IBM Corporation. | ||
| 5 | * Copyright (C) 2014 Ulrich Weigand, IBM Corporation. | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU General Public License | ||
| 9 | * as published by the Free Software Foundation; either version | ||
| 10 | * 2 of the License, or (at your option) any later version. | ||
| 11 | */ | ||
| 12 | #include <inttypes.h> | ||
| 13 | #include <dwarf.h> | ||
| 14 | #include <elfutils/libdwfl.h> | ||
| 15 | |||
| 16 | #include "util/thread.h" | ||
| 17 | #include "util/callchain.h" | ||
| 18 | |||
| 19 | /* | ||
| 20 | * When saving the callchain on Power, the kernel conservatively saves | ||
| 21 | * excess entries in the callchain. A few of these entries are needed | ||
| 22 | * in some cases but not others. If the unnecessary entries are not | ||
| 23 | * ignored, we end up with duplicate arcs in the call-graphs. Use | ||
| 24 | * DWARF debug information to skip over any unnecessary callchain | ||
| 25 | * entries. | ||
| 26 | * | ||
| 27 | * See function header for arch_adjust_callchain() below for more details. | ||
| 28 | * | ||
| 29 | * The libdwfl code in this file is based on code from elfutils | ||
| 30 | * (libdwfl/argp-std.c, libdwfl/tests/addrcfi.c, etc). | ||
| 31 | */ | ||
| 32 | static char *debuginfo_path; | ||
| 33 | |||
| 34 | static const Dwfl_Callbacks offline_callbacks = { | ||
| 35 | .debuginfo_path = &debuginfo_path, | ||
| 36 | .find_debuginfo = dwfl_standard_find_debuginfo, | ||
| 37 | .section_address = dwfl_offline_section_address, | ||
| 38 | }; | ||
| 39 | |||
| 40 | |||
| 41 | /* | ||
| 42 | * Use the DWARF expression for the Call-frame-address and determine | ||
| 43 | * if return address is in LR and if a new frame was allocated. | ||
| 44 | */ | ||
| 45 | static int check_return_reg(int ra_regno, Dwarf_Frame *frame) | ||
| 46 | { | ||
| 47 | Dwarf_Op ops_mem[2]; | ||
| 48 | Dwarf_Op dummy; | ||
| 49 | Dwarf_Op *ops = &dummy; | ||
| 50 | size_t nops; | ||
| 51 | int result; | ||
| 52 | |||
| 53 | result = dwarf_frame_register(frame, ra_regno, ops_mem, &ops, &nops); | ||
| 54 | if (result < 0) { | ||
| 55 | pr_debug("dwarf_frame_register() %s\n", dwarf_errmsg(-1)); | ||
| 56 | return -1; | ||
| 57 | } | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Check if return address is on the stack. | ||
| 61 | */ | ||
| 62 | if (nops != 0 || ops != NULL) | ||
| 63 | return 0; | ||
| 64 | |||
| 65 | /* | ||
| 66 | * Return address is in LR. Check if a frame was allocated | ||
| 67 | * but not-yet used. | ||
| 68 | */ | ||
| 69 | result = dwarf_frame_cfa(frame, &ops, &nops); | ||
| 70 | if (result < 0) { | ||
| 71 | pr_debug("dwarf_frame_cfa() returns %d, %s\n", result, | ||
| 72 | dwarf_errmsg(-1)); | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | |||
| 76 | /* | ||
| 77 | * If call frame address is in r1, no new frame was allocated. | ||
| 78 | */ | ||
| 79 | if (nops == 1 && ops[0].atom == DW_OP_bregx && ops[0].number == 1 && | ||
| 80 | ops[0].number2 == 0) | ||
| 81 | return 1; | ||
| 82 | |||
| 83 | /* | ||
| 84 | * A new frame was allocated but has not yet been used. | ||
| 85 | */ | ||
| 86 | return 2; | ||
| 87 | } | ||
| 88 | |||
| 89 | /* | ||
| 90 | * Get the DWARF frame from the .eh_frame section. | ||
| 91 | */ | ||
| 92 | static Dwarf_Frame *get_eh_frame(Dwfl_Module *mod, Dwarf_Addr pc) | ||
| 93 | { | ||
| 94 | int result; | ||
| 95 | Dwarf_Addr bias; | ||
| 96 | Dwarf_CFI *cfi; | ||
| 97 | Dwarf_Frame *frame; | ||
| 98 | |||
| 99 | cfi = dwfl_module_eh_cfi(mod, &bias); | ||
| 100 | if (!cfi) { | ||
| 101 | pr_debug("%s(): no CFI - %s\n", __func__, dwfl_errmsg(-1)); | ||
| 102 | return NULL; | ||
| 103 | } | ||
| 104 | |||
| 105 | result = dwarf_cfi_addrframe(cfi, pc, &frame); | ||
| 106 | if (result) { | ||
| 107 | pr_debug("%s(): %s\n", __func__, dwfl_errmsg(-1)); | ||
| 108 | return NULL; | ||
| 109 | } | ||
| 110 | |||
| 111 | return frame; | ||
| 112 | } | ||
| 113 | |||
| 114 | /* | ||
| 115 | * Get the DWARF frame from the .debug_frame section. | ||
| 116 | */ | ||
| 117 | static Dwarf_Frame *get_dwarf_frame(Dwfl_Module *mod, Dwarf_Addr pc) | ||
| 118 | { | ||
| 119 | Dwarf_CFI *cfi; | ||
| 120 | Dwarf_Addr bias; | ||
| 121 | Dwarf_Frame *frame; | ||
| 122 | int result; | ||
| 123 | |||
| 124 | cfi = dwfl_module_dwarf_cfi(mod, &bias); | ||
| 125 | if (!cfi) { | ||
| 126 | pr_debug("%s(): no CFI - %s\n", __func__, dwfl_errmsg(-1)); | ||
| 127 | return NULL; | ||
| 128 | } | ||
| 129 | |||
| 130 | result = dwarf_cfi_addrframe(cfi, pc, &frame); | ||
| 131 | if (result) { | ||
| 132 | pr_debug("%s(): %s\n", __func__, dwfl_errmsg(-1)); | ||
| 133 | return NULL; | ||
| 134 | } | ||
| 135 | |||
| 136 | return frame; | ||
| 137 | } | ||
| 138 | |||
| 139 | /* | ||
| 140 | * Return: | ||
| 141 | * 0 if return address for the program counter @pc is on stack | ||
| 142 | * 1 if return address is in LR and no new stack frame was allocated | ||
| 143 | * 2 if return address is in LR and a new frame was allocated (but not | ||
| 144 | * yet used) | ||
| 145 | * -1 in case of errors | ||
| 146 | */ | ||
| 147 | static int check_return_addr(const char *exec_file, Dwarf_Addr pc) | ||
| 148 | { | ||
| 149 | int rc = -1; | ||
| 150 | Dwfl *dwfl; | ||
| 151 | Dwfl_Module *mod; | ||
| 152 | Dwarf_Frame *frame; | ||
| 153 | int ra_regno; | ||
| 154 | Dwarf_Addr start = pc; | ||
| 155 | Dwarf_Addr end = pc; | ||
| 156 | bool signalp; | ||
| 157 | |||
| 158 | dwfl = dwfl_begin(&offline_callbacks); | ||
| 159 | if (!dwfl) { | ||
| 160 | pr_debug("dwfl_begin() failed: %s\n", dwarf_errmsg(-1)); | ||
| 161 | return -1; | ||
| 162 | } | ||
| 163 | |||
| 164 | if (dwfl_report_offline(dwfl, "", exec_file, -1) == NULL) { | ||
| 165 | pr_debug("dwfl_report_offline() failed %s\n", dwarf_errmsg(-1)); | ||
| 166 | goto out; | ||
| 167 | } | ||
| 168 | |||
| 169 | mod = dwfl_addrmodule(dwfl, pc); | ||
| 170 | if (!mod) { | ||
| 171 | pr_debug("dwfl_addrmodule() failed, %s\n", dwarf_errmsg(-1)); | ||
| 172 | goto out; | ||
| 173 | } | ||
| 174 | |||
| 175 | /* | ||
| 176 | * To work with split debug info files (eg: glibc), check both | ||
| 177 | * .eh_frame and .debug_frame sections of the ELF header. | ||
| 178 | */ | ||
| 179 | frame = get_eh_frame(mod, pc); | ||
| 180 | if (!frame) { | ||
| 181 | frame = get_dwarf_frame(mod, pc); | ||
| 182 | if (!frame) | ||
| 183 | goto out; | ||
| 184 | } | ||
| 185 | |||
| 186 | ra_regno = dwarf_frame_info(frame, &start, &end, &signalp); | ||
| 187 | if (ra_regno < 0) { | ||
| 188 | pr_debug("Return address register unavailable: %s\n", | ||
| 189 | dwarf_errmsg(-1)); | ||
| 190 | goto out; | ||
| 191 | } | ||
| 192 | |||
| 193 | rc = check_return_reg(ra_regno, frame); | ||
| 194 | |||
| 195 | out: | ||
| 196 | dwfl_end(dwfl); | ||
| 197 | return rc; | ||
| 198 | } | ||
| 199 | |||
| 200 | /* | ||
| 201 | * The callchain saved by the kernel always includes the link register (LR). | ||
| 202 | * | ||
| 203 | * 0: PERF_CONTEXT_USER | ||
| 204 | * 1: Program counter (Next instruction pointer) | ||
| 205 | * 2: LR value | ||
| 206 | * 3: Caller's caller | ||
| 207 | * 4: ... | ||
| 208 | * | ||
| 209 | * The value in LR is only needed when it holds a return address. If the | ||
| 210 | * return address is on the stack, we should ignore the LR value. | ||
| 211 | * | ||
| 212 | * Further, when the return address is in the LR, if a new frame was just | ||
| 213 | * allocated but the LR was not saved into it, then the LR contains the | ||
| 214 | * caller, slot 4: contains the caller's caller and the contents of slot 3: | ||
| 215 | * (chain->ips[3]) is undefined and must be ignored. | ||
| 216 | * | ||
| 217 | * Use DWARF debug information to determine if any entries need to be skipped. | ||
| 218 | * | ||
| 219 | * Return: | ||
| 220 | * index: of callchain entry that needs to be ignored (if any) | ||
| 221 | * -1 if no entry needs to be ignored or in case of errors | ||
| 222 | */ | ||
| 223 | int arch_skip_callchain_idx(struct machine *machine, struct thread *thread, | ||
| 224 | struct ip_callchain *chain) | ||
| 225 | { | ||
| 226 | struct addr_location al; | ||
| 227 | struct dso *dso = NULL; | ||
| 228 | int rc; | ||
| 229 | u64 ip; | ||
| 230 | u64 skip_slot = -1; | ||
| 231 | |||
| 232 | if (chain->nr < 3) | ||
| 233 | return skip_slot; | ||
| 234 | |||
| 235 | ip = chain->ips[2]; | ||
| 236 | |||
| 237 | thread__find_addr_location(thread, machine, PERF_RECORD_MISC_USER, | ||
| 238 | MAP__FUNCTION, ip, &al); | ||
| 239 | |||
| 240 | if (al.map) | ||
| 241 | dso = al.map->dso; | ||
| 242 | |||
| 243 | if (!dso) { | ||
| 244 | pr_debug("%" PRIx64 " dso is NULL\n", ip); | ||
| 245 | return skip_slot; | ||
| 246 | } | ||
| 247 | |||
| 248 | rc = check_return_addr(dso->long_name, ip); | ||
| 249 | |||
| 250 | pr_debug("DSO %s, nr %" PRIx64 ", ip 0x%" PRIx64 "rc %d\n", | ||
| 251 | dso->long_name, chain->nr, ip, rc); | ||
| 252 | |||
| 253 | if (rc == 0) { | ||
| 254 | /* | ||
| 255 | * Return address on stack. Ignore LR value in callchain | ||
| 256 | */ | ||
| 257 | skip_slot = 2; | ||
| 258 | } else if (rc == 2) { | ||
| 259 | /* | ||
| 260 | * New frame allocated but return address still in LR. | ||
| 261 | * Ignore the caller's caller entry in callchain. | ||
| 262 | */ | ||
| 263 | skip_slot = 3; | ||
| 264 | } | ||
| 265 | return skip_slot; | ||
| 266 | } | ||
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 65a151e36067..3e80aa10cfd8 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
| @@ -184,7 +184,7 @@ static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel) | |||
| 184 | static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel) | 184 | static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel) |
| 185 | { | 185 | { |
| 186 | evsel->priv = zalloc(sizeof(struct perf_stat)); | 186 | evsel->priv = zalloc(sizeof(struct perf_stat)); |
| 187 | if (evsel == NULL) | 187 | if (evsel->priv == NULL) |
| 188 | return -ENOMEM; | 188 | return -ENOMEM; |
| 189 | perf_evsel__reset_stat_priv(evsel); | 189 | perf_evsel__reset_stat_priv(evsel); |
| 190 | return 0; | 190 | return 0; |
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index f30ac5e5d271..346bdb617544 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
| @@ -48,6 +48,10 @@ ifneq ($(ARCH),$(filter $(ARCH),x86 arm)) | |||
| 48 | NO_LIBDW_DWARF_UNWIND := 1 | 48 | NO_LIBDW_DWARF_UNWIND := 1 |
| 49 | endif | 49 | endif |
| 50 | 50 | ||
| 51 | ifeq ($(ARCH),powerpc) | ||
| 52 | CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX | ||
| 53 | endif | ||
| 54 | |||
| 51 | ifeq ($(LIBUNWIND_LIBS),) | 55 | ifeq ($(LIBUNWIND_LIBS),) |
| 52 | NO_LIBUNWIND := 1 | 56 | NO_LIBUNWIND := 1 |
| 53 | else | 57 | else |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 8f84423a75da..da43619d6173 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
| @@ -176,4 +176,17 @@ static inline void callchain_cursor_snapshot(struct callchain_cursor *dest, | |||
| 176 | dest->first = src->curr; | 176 | dest->first = src->curr; |
| 177 | dest->nr -= src->pos; | 177 | dest->nr -= src->pos; |
| 178 | } | 178 | } |
| 179 | |||
| 180 | #ifdef HAVE_SKIP_CALLCHAIN_IDX | ||
| 181 | extern int arch_skip_callchain_idx(struct machine *machine, | ||
| 182 | struct thread *thread, struct ip_callchain *chain); | ||
| 183 | #else | ||
| 184 | static inline int arch_skip_callchain_idx(struct machine *machine __maybe_unused, | ||
| 185 | struct thread *thread __maybe_unused, | ||
| 186 | struct ip_callchain *chain __maybe_unused) | ||
| 187 | { | ||
| 188 | return -1; | ||
| 189 | } | ||
| 190 | #endif | ||
| 191 | |||
| 179 | #endif /* __PERF_CALLCHAIN_H */ | 192 | #endif /* __PERF_CALLCHAIN_H */ |
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index c73e1fc12e53..e9b943acaa5e 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
| @@ -1281,7 +1281,9 @@ static int machine__resolve_callchain_sample(struct machine *machine, | |||
| 1281 | u8 cpumode = PERF_RECORD_MISC_USER; | 1281 | u8 cpumode = PERF_RECORD_MISC_USER; |
| 1282 | int chain_nr = min(max_stack, (int)chain->nr); | 1282 | int chain_nr = min(max_stack, (int)chain->nr); |
| 1283 | int i; | 1283 | int i; |
| 1284 | int j; | ||
| 1284 | int err; | 1285 | int err; |
| 1286 | int skip_idx __maybe_unused; | ||
| 1285 | 1287 | ||
| 1286 | callchain_cursor_reset(&callchain_cursor); | 1288 | callchain_cursor_reset(&callchain_cursor); |
| 1287 | 1289 | ||
| @@ -1290,14 +1292,26 @@ static int machine__resolve_callchain_sample(struct machine *machine, | |||
| 1290 | return 0; | 1292 | return 0; |
| 1291 | } | 1293 | } |
| 1292 | 1294 | ||
| 1295 | /* | ||
| 1296 | * Based on DWARF debug information, some architectures skip | ||
| 1297 | * a callchain entry saved by the kernel. | ||
| 1298 | */ | ||
| 1299 | skip_idx = arch_skip_callchain_idx(machine, thread, chain); | ||
| 1300 | |||
| 1293 | for (i = 0; i < chain_nr; i++) { | 1301 | for (i = 0; i < chain_nr; i++) { |
| 1294 | u64 ip; | 1302 | u64 ip; |
| 1295 | struct addr_location al; | 1303 | struct addr_location al; |
| 1296 | 1304 | ||
| 1297 | if (callchain_param.order == ORDER_CALLEE) | 1305 | if (callchain_param.order == ORDER_CALLEE) |
| 1298 | ip = chain->ips[i]; | 1306 | j = i; |
| 1299 | else | 1307 | else |
| 1300 | ip = chain->ips[chain->nr - i - 1]; | 1308 | j = chain->nr - i - 1; |
| 1309 | |||
| 1310 | #ifdef HAVE_SKIP_CALLCHAIN_IDX | ||
| 1311 | if (j == skip_idx) | ||
| 1312 | continue; | ||
| 1313 | #endif | ||
| 1314 | ip = chain->ips[j]; | ||
| 1301 | 1315 | ||
| 1302 | if (ip >= PERF_CONTEXT_MAX) { | 1316 | if (ip >= PERF_CONTEXT_MAX) { |
| 1303 | switch (ip) { | 1317 | switch (ip) { |
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 1c419321f707..e55b65a65558 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
| @@ -231,6 +231,47 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel) | |||
| 231 | return event; | 231 | return event; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | static PyObject *get_field_numeric_entry(struct event_format *event, | ||
| 235 | struct format_field *field, void *data) | ||
| 236 | { | ||
| 237 | bool is_array = field->flags & FIELD_IS_ARRAY; | ||
| 238 | PyObject *obj, *list = NULL; | ||
| 239 | unsigned long long val; | ||
| 240 | unsigned int item_size, n_items, i; | ||
| 241 | |||
| 242 | if (is_array) { | ||
| 243 | list = PyList_New(field->arraylen); | ||
| 244 | item_size = field->size / field->arraylen; | ||
| 245 | n_items = field->arraylen; | ||
| 246 | } else { | ||
| 247 | item_size = field->size; | ||
| 248 | n_items = 1; | ||
| 249 | } | ||
| 250 | |||
| 251 | for (i = 0; i < n_items; i++) { | ||
| 252 | |||
| 253 | val = read_size(event, data + field->offset + i * item_size, | ||
| 254 | item_size); | ||
| 255 | if (field->flags & FIELD_IS_SIGNED) { | ||
| 256 | if ((long long)val >= LONG_MIN && | ||
| 257 | (long long)val <= LONG_MAX) | ||
| 258 | obj = PyInt_FromLong(val); | ||
| 259 | else | ||
| 260 | obj = PyLong_FromLongLong(val); | ||
| 261 | } else { | ||
| 262 | if (val <= LONG_MAX) | ||
| 263 | obj = PyInt_FromLong(val); | ||
| 264 | else | ||
| 265 | obj = PyLong_FromUnsignedLongLong(val); | ||
| 266 | } | ||
| 267 | if (is_array) | ||
| 268 | PyList_SET_ITEM(list, i, obj); | ||
| 269 | } | ||
| 270 | if (is_array) | ||
| 271 | obj = list; | ||
| 272 | return obj; | ||
| 273 | } | ||
| 274 | |||
| 234 | static void python_process_tracepoint(struct perf_sample *sample, | 275 | static void python_process_tracepoint(struct perf_sample *sample, |
| 235 | struct perf_evsel *evsel, | 276 | struct perf_evsel *evsel, |
| 236 | struct thread *thread, | 277 | struct thread *thread, |
| @@ -239,7 +280,6 @@ static void python_process_tracepoint(struct perf_sample *sample, | |||
| 239 | PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; | 280 | PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; |
| 240 | static char handler_name[256]; | 281 | static char handler_name[256]; |
| 241 | struct format_field *field; | 282 | struct format_field *field; |
| 242 | unsigned long long val; | ||
| 243 | unsigned long s, ns; | 283 | unsigned long s, ns; |
| 244 | struct event_format *event; | 284 | struct event_format *event; |
| 245 | unsigned n = 0; | 285 | unsigned n = 0; |
| @@ -303,20 +343,7 @@ static void python_process_tracepoint(struct perf_sample *sample, | |||
| 303 | offset = field->offset; | 343 | offset = field->offset; |
| 304 | obj = PyString_FromString((char *)data + offset); | 344 | obj = PyString_FromString((char *)data + offset); |
| 305 | } else { /* FIELD_IS_NUMERIC */ | 345 | } else { /* FIELD_IS_NUMERIC */ |
| 306 | val = read_size(event, data + field->offset, | 346 | obj = get_field_numeric_entry(event, field, data); |
| 307 | field->size); | ||
| 308 | if (field->flags & FIELD_IS_SIGNED) { | ||
| 309 | if ((long long)val >= LONG_MIN && | ||
| 310 | (long long)val <= LONG_MAX) | ||
| 311 | obj = PyInt_FromLong(val); | ||
| 312 | else | ||
| 313 | obj = PyLong_FromLongLong(val); | ||
| 314 | } else { | ||
| 315 | if (val <= LONG_MAX) | ||
| 316 | obj = PyInt_FromLong(val); | ||
| 317 | else | ||
| 318 | obj = PyLong_FromUnsignedLongLong(val); | ||
| 319 | } | ||
| 320 | } | 347 | } |
| 321 | if (handler) | 348 | if (handler) |
| 322 | PyTuple_SetItem(t, n++, obj); | 349 | PyTuple_SetItem(t, n++, obj); |
