perf/core improvements and fixes
Jiri Olsa
reviewerhi Ingo,
please consider pulling
thanks,
jirka
The following changes since commit 1c92f88542faa3ae4f970c548b4fe8275a45201b:
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/core (2014-06-25 07:44:19 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git tags/perf-core-for-mingo
for you to fetch changes up to 8ac631cd502d6b31fd29f6d019305305b479fa3e:
perf script: Handle the num array type in python properly (2014-06-27 11:15:02 +0200)
----------------------------------------------------------------
perf/core improvements and fixes:
. 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)
----------------------------------------------------------------
Jiri Olsa (1):
perf tools: Fix wrong condition for allocation failure
Rickard Strandqvist (1):
tools lib traceevent: Fix a risk for doing free on uninitialized pointer
Sebastian Andrzej Siewior (2):
perf script: Move the number processing into its own function perf script: Handle the num array type in python properly
Sukadev Bhattiprolu (1):
perf tools powerpc: Adjust callchain based on DWARF debug info
tools/lib/traceevent/event-parse.c | 6 +- tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/skip-callchain-idx.c | 266 +++++++++++++++++++++ tools/perf/builtin-stat.c | 2 +- tools/perf/config/Makefile | 4 + tools/perf/util/callchain.h | 13 + tools/perf/util/machine.c | 18 +- .../util/scripting-engines/trace-event-python.c | 57 +++-- 8 files changed, 346 insertions(+), 21 deletions(-) create mode 100644 tools/perf/arch/powerpc/util/skip-callchain-idx.c
Jiri Olsa
reviewerPATCH 1/5 tools lib traceevent: Fix a risk for doing free on uninitialized pointer
From: Rickard Strandqvist <[email protected]>
Fix a risk of doing free on an uninitialized pointer.
This was found using a static code analysis program called cppcheck.
--- tools/lib/traceevent/event-parse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/lib/traceevent/event-parse.c +3 -3
@@ -2395,7 +2395,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) {struct print_arg *field;enum event_type type; -char *token; +char *token =NULL ;memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_FLAGS ;
@@ -2448,7 +2448,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) {struct print_arg *field;enum event_type type; -char *token; +char *token =NULL ;memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_SYMBOL ;
@@ -2487,7 +2487,7 @@ process_hex(struct event_format *event, struct print_arg *arg, char **tok) {struct print_arg *field;enum event_type type; -char *token; +char *token =NULL ;memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_HEX ;
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 2/5 perf tools powerpc: Adjust callchain based on DWARF debug info
In reply to Jiri OlsaFrom: Sukadev Bhattiprolu <[email protected]>
When saving the callchain on Power, the kernel conservatively saves excess entries in the callchain. A few of these entries are needed in some cases but not others. We should use the DWARF debug information to determine when the entries are needed.
Eg: the value in the link register (LR) is needed only when it holds the return address of a function. At other times it must be ignored.
If the unnecessary entries are not ignored, we end up with duplicate arcs in the call-graphs.
Use the DWARF debug information to determine if any callchain entries should be ignored when building call-graphs.
Callgraph before the patch:
14.67% 2234 sprintft libc-2.18.so [.] __random
|
--- __random
|
|--61.12%-- __random
| |
| |--97.15%-- rand
| | do_my_sprintf
| | main
| | generic_start_main.isra.0
| | __libc_start_main
| | 0x0
| |
| --2.85%-- do_my_sprintf
| main
| generic_start_main.isra.0
| __libc_start_main
| 0x0
|
--38.88%-- rand
|
|--94.01%-- rand
| do_my_sprintf
| main
| generic_start_main.isra.0
| __libc_start_main
| 0x0
|
--5.99%-- do_my_sprintf
main
generic_start_main.isra.0
__libc_start_main
0x0Callgraph after the patch:
14.67% 2234 sprintft libc-2.18.so [.] __random
|
--- __random
|
|--95.93%-- rand
| do_my_sprintf
| main
| generic_start_main.isra.0
| __libc_start_main
| 0x0
|
--4.07%-- do_my_sprintf
main
generic_start_main.isra.0
__libc_start_main
0x0TODO: For split-debug info objects like glibc, we can only determine
the call-frame-address only when both .eh_frame and .debug_info sections are available. We should be able to determin the CFA even without the .eh_frame section.
Fix suggested by Anton Blanchard.
Thanks to valuable input on DWARF debug information from Ulrich Weigand.
--- tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/skip-callchain-idx.c | 266 ++++++++++++++++++++++ tools/perf/config/Makefile | 4 + tools/perf/util/callchain.h | 13 ++ tools/perf/util/machine.c | 18 +- 5 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 tools/perf/arch/powerpc/util/skip-callchain-idx.c
tools/perf/arch/powerpc/Makefile +1 -0
@@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o endif LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o +LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/skip-callchain-idx.o
tools/perf/arch/powerpc/util/skip-callchain-idx.c new file +266 -0
266 lines not on this page · raw message
tools/perf/config/Makefile +4 -0
@@ -48,6 +48,10 @@ ifneq ($(ARCH),$(filter $(ARCH),x86 arm)) NO_LIBDW_DWARF_UNWIND := 1 endif +ifeq ($(ARCH),powerpc) + CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX +endif + ifeq ($(LIBUNWIND_LIBS),) NO_LIBUNWIND := 1 else
tools/perf/util/callchain.h +13 -0
@@ -176,4 +176,17 @@ static inline void callchain_cursor_snapshot(struct callchain_cursor *dest, dest->first = src->curr; dest->nr -= src->pos; } + +#ifdef HAVE_SKIP_CALLCHAIN_IDX +extern int arch_skip_callchain_idx (struct machine *machine, +struct thread *thread,struct ip_callchain *chain); +#else +static inline int arch_skip_callchain_idx (struct machine *machine__maybe_unused , +struct thread *thread__maybe_unused , +struct ip_callchain *chain__maybe_unused ) +{ +return -1 ; +} +#endif +#endif /* __PERF_CALLCHAIN_H */
tools/perf/util/machine.c +16 -2
@@ -1281,7 +1281,9 @@ static int machine__resolve_callchain_sample(struct machine *machine,u8 cpumode =PERF_RECORD_MISC_USER ;int chain_nr =min (max_stack, (int )chain->nr);int i; +int j;int err; +int skip_idx__maybe_unused ;callchain_cursor_reset (&callchain_cursor);
@@ -1290,14 +1292,26 @@ static int machine__resolve_callchain_sample(struct machine *machine,return 0 ; } +/* +* Based on DWARF debug information, some architectures skip +* a callchain entry saved by the kernel. +*/ + skip_idx =arch_skip_callchain_idx (machine, thread, chain); +for (i =0 ; i < chain_nr; i++) {u64 ip;struct addr_location al;if (callchain_param.order ==ORDER_CALLEE ) - ip = chain->ips[i]; + j = i;else - ip = chain->ips[chain->nr - i -1 ]; + j = chain->nr - i -1 ; + +#ifdef HAVE_SKIP_CALLCHAIN_IDX +if (j == skip_idx) +continue ; +#endif + ip = chain->ips[j];if (ip >=PERF_CONTEXT_MAX ) {switch (ip) {
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 3/5 perf tools: Fix wrong condition for allocation failure
In reply to Jiri OlsaCheck real allocated pointer for NULL.
--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -184,7 +184,7 @@ static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)static int perf_evsel__alloc_stat_priv (struct perf_evsel *evsel) { evsel->priv =zalloc (sizeof (struct perf_stat )); -if (evsel ==NULL ) +if (evsel->priv ==NULL )return -ENOMEM ;perf_evsel__reset_stat_priv (evsel);return 0 ;
Signature · 1 line
1.8.3.1
Re: [PATCH 3/5] perf tools: Fix wrong condition for allocation failure
Em Fri, Jun 27, 2014 at 02:20:59PM +0200, Jiri Olsa escreveu:
Quoted 1 line
Check real allocated pointer for NULL.
Thanks, applied.
- Arnaldo
Quoted 29 lines
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-stat.c +1
-1@@ -184,7 +184,7 @@ static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)static int perf_evsel__alloc_stat_priv (struct perf_evsel *evsel) { evsel->priv =zalloc (sizeof (struct perf_stat )); -if (evsel ==NULL ) +if (evsel->priv ==NULL )return -ENOMEM ;perf_evsel__reset_stat_priv (evsel);return 0 ;Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 4/5 perf script: Move the number processing into its own function
In reply to Jiri OlsaFrom: Sebastian Andrzej Siewior <[email protected]>
I was going to change something here and the result was so much on the right side of the screen that I decided to move that piece into its own function.
This patch should make no function change except the moving the code into its own function.
--- .../util/scripting-engines/trace-event-python.c | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +23 -15
@@ -231,6 +231,28 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel)return event; } +static PyObject *get_field_numeric_entry (struct event_format *event, +struct format_field *field,void *data) +{ +PyObject *obj; +unsigned long long val; + + val =read_size (event, data + field->offset, field->size); +if (field->flags &FIELD_IS_SIGNED ) { +if ((long long )val >=LONG_MIN && + (long long )val <=LONG_MAX ) + obj =PyInt_FromLong (val); +else + obj =PyLong_FromLongLong (val); + }else { +if (val <=LONG_MAX ) + obj =PyInt_FromLong (val); +else + obj =PyLong_FromUnsignedLongLong (val); + } +return obj; +} + static void python_process_tracepoint(struct perf_sample *sample, struct perf_evsel *evsel, struct thread *thread,
@@ -239,7 +261,6 @@ static void python_process_tracepoint(struct perf_sample *sample,PyObject *handler, *retval, *context, *t, *obj, *dict =NULL ;static char handler_name[256 ];struct format_field *field; -unsigned long long val;unsigned long s, ns;struct event_format *event;unsigned n =0 ;
@@ -303,20 +324,7 @@ static void python_process_tracepoint(struct perf_sample *sample, offset = field->offset; obj =PyString_FromString ((char *)data + offset); }else {/* FIELD_IS_NUMERIC */ - val =read_size (event, data + field->offset, - field->size); -if (field->flags &FIELD_IS_SIGNED ) { -if ((long long )val >=LONG_MIN && - (long long )val <=LONG_MAX ) - obj =PyInt_FromLong (val); -else - obj =PyLong_FromLongLong (val); - }else { -if (val <=LONG_MAX ) - obj =PyInt_FromLong (val); -else - obj =PyLong_FromUnsignedLongLong (val); - } + obj =get_field_numeric_entry (event, field, data); }if (handler)PyTuple_SetItem (t, n++, obj);
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 5/5 perf script: Handle the num array type in python properly
In reply to Jiri OlsaFrom: Sebastian Andrzej Siewior <[email protected]>
The raw_syscalls:sys_enter tracer for instance passes has one argument named 'arg' which is an array of 6 integers. Right the python scripts gets only 0 passed as an argument. The reason is that pevent_read_number() can not handle data types of 48 and returns always 0.
This patch changes this by passing num array as list of nums which fit the description. As a result python will now see a list named arg which contains 6 (integer) items.
--- .../util/scripting-engines/trace-event-python.c | 43 ++++++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +31 -12
@@ -234,22 +234,41 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel)static PyObject *get_field_numeric_entry (struct event_format *event,struct format_field *field,void *data) { -PyObject *obj; +bool is_array = field->flags &FIELD_IS_ARRAY ; +PyObject *obj, *list =NULL ;unsigned long long val; +unsigned int item_size, n_items, i; - val =read_size (event, data + field->offset, field->size); -if (field->flags &FIELD_IS_SIGNED ) { -if ((long long )val >=LONG_MIN && - (long long )val <=LONG_MAX ) - obj =PyInt_FromLong (val); -else - obj =PyLong_FromLongLong (val); +if (is_array) { + list =PyList_New (field->arraylen); + item_size = field->size / field->arraylen; + n_items = field->arraylen; }else { -if (val <=LONG_MAX ) - obj =PyInt_FromLong (val); -else - obj =PyLong_FromUnsignedLongLong (val); + item_size = field->size; + n_items =1 ; + } + +for (i =0 ; i < n_items; i++) { + + val =read_size (event, data + field->offset + i * item_size, + item_size); +if (field->flags &FIELD_IS_SIGNED ) { +if ((long long )val >=LONG_MIN && + (long long )val <=LONG_MAX ) + obj =PyInt_FromLong (val); +else + obj =PyLong_FromLongLong (val); + }else { +if (val <=LONG_MAX ) + obj =PyInt_FromLong (val); +else + obj =PyLong_FromUnsignedLongLong (val); + } +if (is_array) +PyList_SET_ITEM (list, i, obj); } +if (is_array) + obj = list;return obj; }
Signature · 1 line
1.8.3.1
Quoted 46 lines · Jiri Olsa
hi Ingo,
please consider pullingthanks,
jirkaThe following changes since commit
1c92f88542faa3ae4f970c548b4fe8275a45201b:Merge tag 'perf-core-for-mingo' of
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perfinto perf/core (2014-06-25 07:44:19 +0200)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.gittags/perf-core-for-mingofor you to fetch changes up to
8ac631cd502d6b31fd29f6d019305305b479fa3e:perf script: Handle the num array type in python properly (2014-06-27 11:15:02 +0200)
----------------------------------------------------------------
perf/core improvements and fixes:. 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 <[email protected]>----------------------------------------------------------------
Jiri Olsa (1):
perf tools: Fix wrong condition for allocation failureRickard Strandqvist (1):
tools lib traceevent: Fix a risk for doing free on uninitialized pointerSebastian Andrzej Siewior (2):
perf script: Move the number processing into its own function perf script: Handle the num array type in python properlySukadev Bhattiprolu (1):
perf tools powerpc: Adjust callchain based on DWARF debug info
Quoted 10 lines
tools/lib/traceevent/event-parse.c | 6 +- tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/skip-callchain-idx.c | 266 +++++++++++++++++++++ tools/perf/builtin-stat.c | 2 +- tools/perf/config/Makefile | 4 + tools/perf/util/callchain.h | 13 + tools/perf/util/machine.c | 18 +- .../util/scripting-engines/trace-event-python.c | 57 +++-- 8 files changed, 346 insertions(+), 21 deletions(-) create mode 100644 tools/perf/arch/powerpc/util/skip-callchain-idx.c
Pulled, thanks a lot Jiri!
Ingo