linux/tools/perf/util
Chris Phlipot 9919a65ec5 perf callchain: Fix incorrect ordering of entries
The existing implementation of thread__resolve_callchain, under certain
circumstances, can assemble callchain entries in the incorrect order.

The callchain entries are resolved incorrectly for a sample when all of
the following conditions are met:

1. callchain_param.order is set to ORDER_CALLER

2. thread__resolve_callchain_sample is able to resolve callchain entries
   for the sample.

3. unwind__get_entries is also able to resolve callchain entries for the
   sample.

The fix is accomplished by reversing the order in which
thread__resolve_callchain_sample and unwind__get_entries are called when
callchain_param.order is set to ORDER_CALLER.

Unwind specific code from thread__resolve_callchain is also moved into a
new static function to improve readability of the fix.

How to Reproduce the Existing Bug:

Modifying perf script to print call trees in the opposite order or
applying the remaining patches from this series and comparing the
results output from export-to-postgtresql.py are the easiest ways to see
the bug, however it can still be seen in current builds using perf
report.

Here is how i can reproduce the bug using perf report:

  # perf record --call-graph=dwarf stress -c 1 -t 5

when i run this command:

  # perf report --call-graph=flat,0,0,callee

This callchain, containing kernel (handle_irq_event, etc) and userspace
samples (__libc_start_main, etc) is contained in the output, which looks
correct (callee order):

                gen8_irq_handler
                handle_irq_event_percpu
                handle_irq_event
                handle_edge_irq
                handle_irq
                do_IRQ
                ret_from_intr
                __random
                rand
                0x558f2a04dded
                0x558f2a04c774
                __libc_start_main
                0x558f2a04dcd9

Now run this command using caller order:

  # perf report --call-graph=flat,0,0,caller

It is expected to see the exact reverse of the above when using caller
order (with "0x558f2a04dcd9" at the top and "gen8_irq_handler" at the
bottom) in the output, but it is nowhere to be found.

instead you see this:

                ret_from_intr
                do_IRQ
                handle_irq
                handle_edge_irq
                handle_irq_event
                handle_irq_event_percpu
                gen8_irq_handler
                0x558f2a04dcd9
                __libc_start_main
                0x558f2a04c774
                0x558f2a04dded
                rand
                __random

Notice how internally the kernel symbols are reversed and the user space
symbols are reversed, but the kernel symbols still appear above the user
space symbols.

if this patch is applied and perf script is re-run, you will see the
expected output (with "0x558f2a04dcd9" at the top and "gen8_irq_handler"
at the bottom):

                0x558f2a04dcd9
                __libc_start_main
                0x558f2a04c774
                0x558f2a04dded
                rand
                __random
                ret_from_intr
                do_IRQ
                handle_irq
                handle_edge_irq
                handle_irq_event
                handle_irq_event_percpu
                gen8_irq_handler

Signed-off-by: Chris Phlipot <cphlipot0@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1461831551-12213-2-git-send-email-cphlipot0@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-06 08:59:47 -03:00
..
include tools lib: Move bitmap.[ch] from tools/perf/ to tools/{lib,include}/ 2016-01-08 12:35:46 -03:00
intel-pt-decoder perf intel-pt: Fix off-by-one comparison on maximum code 2016-04-25 20:35:59 -03:00
scripting-engines perf tools: Set the maximum allowed stack from /proc/sys/kernel/perf_event_max_stack 2016-04-27 10:29:07 -03:00
alias.c
annotate.c perf hists: Move sort__has_sym into struct perf_hpp_list 2016-05-05 21:03:59 -03:00
annotate.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
auxtrace.c perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
auxtrace.h perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
bpf-loader.c perf bpf: Automatically create bpf-output event __bpf_stdout__ 2016-04-11 22:18:04 -03:00
bpf-loader.h perf bpf: Clone bpf stdout events in multiple bpf scripts 2016-04-11 22:17:45 -03:00
bpf-prologue.c perf bpf: Add prologue for BPF programs for fetching arguments 2015-11-18 17:51:04 -03:00
bpf-prologue.h perf bpf: Add prologue for BPF programs for fetching arguments 2015-11-18 17:51:04 -03:00
Build perf build: Remove x86 references from arch-neutral Build 2016-04-19 12:37:02 -03:00
build-id.c perf buildid: Fix off-by-one in write_buildid() 2016-04-25 12:49:16 -03:00
build-id.h perf symbols: Fix symbols searching for module in buildid-cache 2016-02-12 10:54:47 -03:00
cache.h perf llvm: Use realpath to canonicalize paths 2016-03-23 17:39:19 -03:00
callchain.c perf hists: Move sort__has_parent into struct perf_hpp_list 2016-05-05 21:03:59 -03:00
callchain.h perf record: Export record_opts based callchain parsing helper 2016-04-15 16:37:17 -03:00
cgroup.c perf subcmd: Create subcmd library 2015-12-17 14:27:14 -03:00
cgroup.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
cloexec.c perf bench numa: Fix to show proper convergence stats 2015-06-25 12:28:35 -03:00
cloexec.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
color.c perf config: Bring perf_default_config to the very beginning at main() 2016-02-26 19:49:16 -03:00
color.h perf tools: Remove trail argument to color vsprintf 2015-08-05 16:44:02 -03:00
comm.c perf comm: Use atomic.h for refcounting 2015-05-27 12:21:43 -03:00
comm.h
config.c perf config: Introduce perf_config_set class 2016-04-14 09:00:42 -03:00
config.h perf config: Introduce perf_config_set class 2016-04-14 09:00:42 -03:00
counts.c perf stat: Move perf_counts struct and functions into separate object 2015-08-08 14:16:49 -03:00
counts.h perf stat: Move perf_counts struct and functions into separate object 2015-08-08 14:16:49 -03:00
cpumap.c perf cpu_map: Add has() method 2016-04-13 10:11:50 -03:00
cpumap.h perf cpu_map: Add has() method 2016-04-13 10:11:50 -03:00
ctype.c perf ui/stdio: Align column header for hierarchy output 2016-02-24 20:21:12 -03:00
data-convert-bt.c perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
data-convert-bt.h
data.c perf data: Add perf_data_file__switch() helper 2016-04-14 08:57:54 -03:00
data.h perf data: Add perf_data_file__switch() helper 2016-04-14 08:57:54 -03:00
db-export.c perf thread: Rename perf_event__preprocess_sample_addr to thread__resolve 2016-03-23 12:03:08 -03:00
db-export.h
debug.c perf tools: Make binary data printer code in trace_event public available 2016-02-24 11:38:01 -03:00
debug.h perf tools: Initialize libapi debug output 2016-02-16 17:12:59 -03:00
demangle-java.c perf symbols: add Java demangling support 2016-02-05 09:46:45 -03:00
demangle-java.h perf symbols: add Java demangling support 2016-02-05 09:46:45 -03:00
dso.c perf symbols: Do not read symbols/data from device files 2016-01-26 11:52:43 -03:00
dso.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
dwarf-aux.c perf probe: Check if dwarf_getlocations() is available 2016-04-06 10:44:28 -03:00
dwarf-aux.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
env.c perf tools: Add perf data cache feature 2016-02-16 17:13:00 -03:00
env.h perf tools: Add perf data cache feature 2016-02-16 17:13:00 -03:00
event.c perf tools: Use readdir() instead of deprecated readdir_r() 2016-04-08 11:32:15 -03:00
event.h perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
evlist.c perf evlist: Rename variable in perf_mmap__read() 2016-05-05 21:04:04 -03:00
evlist.h perf evlist: Expose perf_event_mlock_kb_in_pages() helper 2016-04-15 17:46:31 -03:00
evsel.c perf evsel: Remove two extraneous ending newlines in open_strerror() 2016-04-28 09:58:58 -03:00
evsel.h perf evsel: Add missign class prefix to has_branch_stack method 2016-04-18 11:17:09 -03:00
evsel_fprintf.c perf evsel: Move fprintf methods to separate source file 2016-04-14 19:46:58 -03:00
find-vdso-map.c
genelf.c perf jit: add source line info support 2016-02-05 12:33:09 -03:00
genelf.h perf jit: genelf makes assumptions about endian 2016-03-30 18:12:06 -03:00
genelf_debug.c perf jit: add source line info support 2016-02-05 12:33:09 -03:00
generate-cmdlist.sh perf tools: Do not show trace command if it's not compiled in 2016-01-08 12:46:17 -03:00
header.c perf test: Remove 'core_id' check in topo test 2016-03-11 13:45:04 -03:00
header.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
help-unknown-cmd.c perf config: Bring perf_default_config to the very beginning at main() 2016-02-26 19:49:16 -03:00
help-unknown-cmd.h perf tools: Move help_unknown_cmd() to its own file 2015-12-14 12:30:37 -03:00
hist.c perf hists: Move sort__need_collapse into struct perf_hpp_list 2016-05-05 21:03:58 -03:00
hist.h perf hists: Move sort__has_comm into struct perf_hpp_list 2016-05-05 21:04:02 -03:00
intel-bts.c perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
intel-bts.h perf tools: Add Intel BTS support 2015-08-21 11:34:10 -03:00
intel-pt.c Merge branch 'perf/urgent' into perf/core, to resolve conflict 2016-04-23 14:12:10 +02:00
intel-pt.h perf tools: Pass Intel PT information for decoding MTC and CYC 2015-08-24 17:46:43 -03:00
intlist.c
intlist.h
jit.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
jitdump.c perf jit: memset() variable 'st' using the correct size 2016-04-19 12:37:01 -03:00
jitdump.h perf jit: Add support for using TSC as a timestamp 2016-04-01 18:42:55 -03:00
kvm-stat.h perf kvm/powerpc: Port perf kvm stat to powerpc 2016-01-29 17:49:54 -03:00
levenshtein.c
levenshtein.h
llvm-utils.c perf llvm: Use strerror_r instead of the thread unsafe strerror one 2016-03-23 17:42:21 -03:00
llvm-utils.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
lzma.c
machine.c perf callchain: Fix incorrect ordering of entries 2016-05-06 08:59:47 -03:00
machine.h perf machine: Introduce number of threads member 2016-05-05 21:03:55 -03:00
map.c perf symbols: Record text offset in dso to calculate objdump address 2016-04-08 09:58:14 -03:00
map.h perf maps: Introduce maps__find_symbol_by_name() 2015-09-30 18:34:25 -03:00
mem-events.c perf script: Display data_src values 2016-02-24 10:32:11 -03:00
mem-events.h perf script: Display data_src values 2016-02-24 10:32:11 -03:00
ordered-events.c perf ordered_events: Introduce reinit() 2016-04-14 08:57:54 -03:00
ordered-events.h perf ordered_events: Introduce reinit() 2016-04-14 08:57:54 -03:00
parse-branch-options.c perf subcmd: Create subcmd library 2015-12-17 14:27:14 -03:00
parse-branch-options.h perf tools: Move branch option parsing to own file 2015-05-27 21:02:17 -03:00
parse-events.c perf tools: Use readdir() instead of deprecated readdir_r() 2016-04-08 11:53:02 -03:00
parse-events.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
parse-events.l perf tools: Introduce bpf-output event 2016-02-22 14:37:21 -03:00
parse-events.y perf tools: Explicitly declare inc_group_count as a void function 2016-03-08 10:11:16 +01:00
parse-regs-options.c perf subcmd: Create subcmd library 2015-12-17 14:27:14 -03:00
parse-regs-options.h perf record: Add ability to name registers to record 2015-08-31 18:01:33 -03:00
path.c perf tools: Remove unused perf_pathdup, xstrdup functions 2016-03-23 15:27:33 -03:00
PERF-VERSION-GEN
perf_regs.c perf tools: Fix build break on powerpc due to sample_reg_masks 2015-09-30 18:34:27 -03:00
perf_regs.h perf tools: Fix build break on powerpc due to sample_reg_masks 2015-09-30 18:34:27 -03:00
pmu.c perf tools: Fix PMU term format max value calculation 2016-04-01 18:46:24 -03:00
pmu.h perf tools: Add perf_pmu__format_bits() 2015-08-06 16:49:01 -03:00
pmu.l
pmu.y
probe-event.c perf symbols: Fix kallsyms perf test on ppc64le 2016-05-05 21:04:03 -03:00
probe-event.h perf symbols: Fix kallsyms perf test on ppc64le 2016-05-05 21:04:03 -03:00
probe-file.c perf probe: Let probe_file__add_event return 0 if succeeded 2016-04-26 13:14:58 -03:00
probe-file.h perf probe: Print deleted events in cmd_probe() 2015-09-04 12:43:44 -03:00
probe-finder.c perf probe: Use strbuf for making strings 2016-04-28 09:58:58 -03:00
probe-finder.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
pstack.c
pstack.h
python-ext-sources perf symbols: Move fprintf routines to separate object file 2016-04-14 19:46:53 -03:00
python.c perf python: Support the PERF_RECORD_SWITCH event 2015-10-07 19:41:50 -03:00
quote.c
quote.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
rb_resort.h perf tools: Add template for generating rbtree resort class 2016-05-05 21:03:55 -03:00
rblist.c
rblist.h
record.c perf evsel: Do not use globals in config() 2016-04-11 22:18:20 -03:00
session.c perf evsel: Add missign class prefix to has_branch_stack method 2016-04-18 11:17:09 -03:00
session.h perf evsel: Move some methods from session.[ch] to evsel.[ch] 2016-04-13 10:11:52 -03:00
setup.py perf tools: Fix python extension build 2016-02-29 11:18:25 -03:00
sort.c perf hists: Move sort__has_comm into struct perf_hpp_list 2016-05-05 21:04:02 -03:00
sort.h perf hists: Move sort__has_comm into struct perf_hpp_list 2016-05-05 21:04:02 -03:00
srcline.c perf tools: Always use non inlined file name for 'srcfile' sort key 2015-09-02 16:30:46 -03:00
stat-shadow.c perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
stat.c Merge branch 'perf/urgent' into perf/core, to pick up fixes 2016-02-04 08:57:44 +01:00
stat.h perf stat: Check for frontend stalled for metrics 2016-03-03 11:10:40 -03:00
strbuf.c perf tools: Unexport some methods unused outside strbuf.c 2016-03-23 17:09:53 -03:00
strbuf.h perf tools: Unexport some methods unused outside strbuf.c 2016-03-23 17:09:53 -03:00
strfilter.c
strfilter.h
string.c tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c 2015-11-18 17:51:02 -03:00
strlist.c perf tools: Add file_only config option to strlist 2016-01-12 12:42:07 -03:00
strlist.h perf tools: Add file_only config option to strlist 2016-01-12 12:42:07 -03:00
svghelper.c perf tools: Add reference counting for cpu_map object 2015-06-25 15:15:50 -03:00
svghelper.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
symbol-elf.c perf symbols: Fix kallsyms perf test on ppc64le 2016-05-05 21:04:03 -03:00
symbol-minimal.c perf symbols: Fix type error when reading a build-id 2015-10-28 10:02:00 -03:00
symbol.c perf symbols: Allow loading kallsyms without considering kcore files 2016-04-19 12:38:56 -03:00
symbol.h perf symbols: Fix kallsyms perf test on ppc64le 2016-05-05 21:04:03 -03:00
symbol_fprintf.c perf symbols: Move fprintf routines to separate object file 2016-04-14 19:46:53 -03:00
syscalltbl.c perf tools: Build syscall table .c header from kernel's syscall_64.tbl 2016-04-08 09:58:14 -03:00
syscalltbl.h perf tools: Allow generating per-arch syscall table arrays 2016-04-08 09:58:14 -03:00
target.c
target.h
term.c perf tools: Move term functions out of util.c 2015-12-09 13:42:02 -03:00
term.h perf tools: Move term functions out of util.c 2015-12-09 13:42:02 -03:00
thread-stack.c perf tools: Ensure thread-stack is flushed 2015-06-19 16:03:33 -03:00
thread-stack.h perf tools: Ensure thread-stack is flushed 2015-06-19 16:03:33 -03:00
thread.c perf thread: Introduce method to set comm from /proc/pid/self 2016-04-26 13:15:00 -03:00
thread.h perf thread: Introduce method to set comm from /proc/pid/self 2016-04-26 13:15:00 -03:00
thread_map.c perf thread_map: Make new_by_tid_str constructor public 2016-04-13 10:11:51 -03:00
thread_map.h perf thread_map: Make new_by_tid_str constructor public 2016-04-13 10:11:51 -03:00
tool.h perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
top.c
top.h
trace-event-info.c tools lib api fs: Move tracing_path interface into api/fs/tracing_path.c 2015-09-04 12:00:45 -03:00
trace-event-parse.c irq_poll: make blk-iopoll available outside the block layer 2015-12-11 11:52:24 -08:00
trace-event-read.c perf tools: Stop reading the kallsyms data from perf.data 2015-07-23 22:51:11 -03:00
trace-event-scripting.c
trace-event.c tools lib api fs: Adopt filename__read_str from perf 2016-02-16 17:12:56 -03:00
trace-event.h perf script: Add process_stat/process_stat_interval scripting interface 2016-01-06 20:11:15 -03:00
trigger.h perf tools: Introduce trigger class 2016-04-28 09:58:58 -03:00
tsc.c perf tools: Use 64-bit shifts with (TSC) time conversion 2016-03-08 10:11:18 +01:00
tsc.h perf jit: Add support for using TSC as a timestamp 2016-04-01 18:42:55 -03:00
unwind-libdw.c perf libdw: Check for mmaps also in MAP__VARIABLE tree 2016-01-08 14:16:57 -03:00
unwind-libdw.h perf callchain: Add order support for libdw DWARF unwinder 2015-11-23 18:31:13 -03:00
unwind-libunwind.c perf tools: Add dedicated unwind addr_space member into thread struct 2016-04-08 09:58:02 -03:00
unwind.h
usage.c perf tools: Simplify die() mechanism 2016-03-23 12:32:31 -03:00
util.c perf tools: Set the maximum allowed stack from /proc/sys/kernel/perf_event_max_stack 2016-04-27 10:29:07 -03:00
util.h perf tools: Set the maximum allowed stack from /proc/sys/kernel/perf_event_max_stack 2016-04-27 10:29:07 -03:00
values.c
values.h
vdso.c perf tools: Fix lockup using 32-bit compat vdso 2015-07-07 11:05:08 -03:00
vdso.h perf machine: Fix up vdso methods names 2015-05-29 12:43:44 -03:00
wrapper.c perf tools: Remove unused perf_pathdup, xstrdup functions 2016-03-23 15:27:33 -03:00
xyarray.c perf tools: Introduce xyarray__reset function 2015-06-16 10:34:39 -03:00
xyarray.h perf tools: Introduce xyarray__reset function 2015-06-16 10:34:39 -03:00
zlib.c