linux/tools/perf/util
Kan Liang 94ba462d69 perf diff: Support for different binaries
Currently, the perf diff only works with same binaries. That's because
it compares the symbol start address. It doesn't work if the perf.data
comes from different binaries. This patch matches the symbol names.

Actually, perf diff once intended to compare the symbol names.  The
commit as below can look for a pair by name.

604c5c9297 (perf diff: Change the default sort order to "dso,symbol")
However, at that time, perf diff used a global list of dsos. That means
the binaries which has same name can only be loaded once. That's a
problem for comparing different binaries.

For example, we have an old binary and an updated binary. They very
likely have same name and most of the functions, so only dsos from old
binary will be loaded. When processing the data from updated binary,
perf still use the symbol information from old binary. That's wrong.

Then the commit as below used IP to replace symbol name.
9c443dfdd3 ("perf diff: Fix support for all --sort combinations")
>From that time, perf diff starts to compare the symbol address.

The global dsos is discarded from a patch in 2010.
a1645ce12a ("perf: 'perf kvm' tool for monitoring guest performance
from host")
However, at that time, perf diff already compared by address. So perf
diff cannot work for different binaries as well.

This patch actually rolls back the perf diff to original design. The
document is also changed, so everybody knows the original design is to
compare the symbol names.

Here are some examples:

The only difference between example_v1.c and example_v2.c is the
location of f2 and f3. There is no change in behavior, but the previous
perf diff display the wrong differential profile.

example_v1.c
noinline void f3(void)
{
        volatile int i;
        for (i = 0; i < 10000;) {

                if(i%2)
                        i++;
                else
                        i++;
        }
}

noinline void f2(void)
{
        volatile int a = 100, b, c;
        for (b = 0; b < 10000; b++)
                c = a * b;

}

noinline void f1(void)
{
                f2();
                f3();
}

int main()
{
        int i;
        for (i = 0; i < 100000; i++)
                f1();
}

example_v2.c
noinline void f2(void)
{
        volatile int a = 100, b, c;
        for (b = 0; b < 10000; b++)
                c = a * b;
}

noinline void f3(void)
{
        volatile int i;
        for (i = 0; i < 10000;) {
                if(i%2)
                        i++;
                else
                        i++;
        }
}

noinline void f1(void)
{
                f2();
                f3();
}

int main()
{
        int i;
        for (i = 0; i < 100000; i++)
                f1();
}

[lk@localhost perf_diff]$ gcc example_v1.c -o example
[lk@localhost perf_diff]$ perf record -o example_v1.data ./example
[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 0.813 MB example_v1.data (~35522 samples) ]

[lk@localhost perf_diff]$ gcc example_v2.c -o example
[lk@localhost perf_diff]$ perf record -o example_v2.data ./example
[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 0.824 MB example_v2.data (~36015 samples) ]

Old perf diff result:

[lk@localhost perf_diff]$ perf diff example_v1.data example_v2.data
 Event 'cycles'
 Baseline    Delta  Shared Object     Symbol
 ........  .......  ................  ...............................

                     [kernel.vmlinux]  [k] __perf_event_task_sched_out
     0.00%           [kernel.vmlinux]  [k] apic_timer_interrupt
                     [kernel.vmlinux]  [k] idle_cpu
                     [kernel.vmlinux]  [k] intel_pstate_timer_func
                     [kernel.vmlinux]  [k] native_read_msr_safe
     0.00%           [kernel.vmlinux]  [k] native_read_tsc
     0.00%           [kernel.vmlinux]  [k] native_write_msr_safe
                     [kernel.vmlinux]  [k] ntp_tick_length
     0.00%           [kernel.vmlinux]  [k] rb_erase
     0.00%           [kernel.vmlinux]  [k] tick_sched_timer
     0.00%           [kernel.vmlinux]  [k] unmap_single_vma
     0.00%           [kernel.vmlinux]  [k] update_wall_time
     0.00%           example           [.] f1
    46.24%           example           [.] f2
    53.71%   -7.55%  example           [.] f3
            +53.81%  example           [.] f3
     0.02%           example           [.] main

New perf diff result:

[lk@localhost perf_diff]$ perf diff example_v1.data example_v2.data
                     [kernel.vmlinux]  [k] __perf_event_task_sched_out
     0.00%           [kernel.vmlinux]  [k] apic_timer_interrupt
                     [kernel.vmlinux]  [k] idle_cpu
                     [kernel.vmlinux]  [k] intel_pstate_timer_func
                     [kernel.vmlinux]  [k] native_read_msr_safe
     0.00%           [kernel.vmlinux]  [k] native_read_tsc
     0.00%           [kernel.vmlinux]  [k] native_write_msr_safe
                     [kernel.vmlinux]  [k] ntp_tick_length
     0.00%           [kernel.vmlinux]  [k] rb_erase
     0.00%           [kernel.vmlinux]  [k] tick_sched_timer
     0.00%           [kernel.vmlinux]  [k] unmap_single_vma
     0.00%           [kernel.vmlinux]  [k] update_wall_time
     0.00%           example           [.] f1
    46.24%   -0.08%  example           [.] f2
    53.71%   +0.11%  example           [.] f3
     0.02%           example           [.] main

Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1423460384-11645-1-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-02-27 10:08:38 -03:00
..
include tools: Remove bitops/hweight usage of bits in tools/perf 2015-01-16 17:49:29 -03:00
scripting-engines perf build: Add scripts objects building 2015-02-12 11:49:53 -03:00
abspath.c
alias.c perf tools: Introduce zfree 2013-12-27 15:17:00 -03:00
annotate.c perf tools: Remove EOL whitespaces 2015-01-21 13:24:31 -03:00
annotate.h perf tools: Fix segfault for symbol annotation on TUI 2015-01-16 17:49:29 -03:00
bitmap.c
Build perf data: Add perf data to CTF conversion support 2015-02-25 16:13:12 -03:00
build-id.c perf buildid-cache: Add new buildid cache if update target is not cached 2015-02-27 10:08:37 -03:00
build-id.h perf buildid-cache: Add new buildid cache if update target is not cached 2015-02-27 10:08:37 -03:00
cache.h perf tools: Make perf aware of tracefs 2015-02-11 12:37:08 -03:00
callchain.c perf tools: Enable LBR call stack support 2015-02-18 17:16:17 +01:00
callchain.h perf tools: Enable LBR call stack support 2015-02-18 17:16:17 +01:00
cgroup.c perf evlist: Introduce evlist__for_each() & friends 2014-01-13 10:06:25 -03:00
cgroup.h
cloexec.c perf util: Replace strerror with strerror_r for thread-safety 2014-08-15 10:58:35 -03:00
cloexec.h perf tools: Enable close-on-exec flag on perf file descriptor 2014-07-18 09:09:34 +02:00
color.c perf tools: Remove some unused functions from color.c 2015-01-21 13:24:32 -03:00
color.h perf tools: Remove some unused functions from color.c 2015-01-21 13:24:32 -03:00
comm.c perf tools: Identify which comms are from exec 2014-08-13 19:23:08 -03:00
comm.h perf tools: Add facility to export data in database-friendly way 2014-10-29 10:32:49 -02:00
config.c perf tools: Add --buildid-dir option to set cache directory 2014-12-09 09:14:35 -03:00
cpumap.c perf tools: Use cpu/possible instead of cpu/kernel_max 2014-04-22 17:39:16 +02:00
cpumap.h perf tools: Allow ability to map cpus to nodes easily 2014-04-22 17:39:12 +02:00
ctype.c
data-convert-bt.c perf data: Add a 'perf' prefix to the generic fields 2015-02-25 16:14:33 -03:00
data-convert-bt.h perf data: Add perf data to CTF conversion support 2015-02-25 16:13:12 -03:00
data.c perf util: Replace strerror with strerror_r for thread-safety 2014-08-15 10:58:35 -03:00
data.h perf tools: Add perf_data_file__write interface 2013-12-02 09:22:46 -03:00
db-export.c perf tools: Defer export of comms that were not 'set' 2014-11-03 18:11:59 -03:00
db-export.h perf tools: Defer export of comms that were not 'set' 2014-11-03 18:11:59 -03:00
debug.c perf data: Add perf data to CTF conversion support 2015-02-25 16:13:12 -03:00
debug.h perf data: Add perf data to CTF conversion support 2015-02-25 16:13:12 -03:00
dso.c perf symbols: debuglink should take symfs option into account 2015-02-06 11:46:36 +01:00
dso.h perf callchain: Cache eh/debug frame offset for dwarf unwind 2015-01-29 16:20:42 -03:00
dwarf-aux.c perf probe: Fix to handle optimized not-inlined functions 2015-02-06 11:46:36 +01:00
dwarf-aux.h perf probe: Fix to handle optimized not-inlined functions 2015-02-06 11:46:36 +01:00
environment.c
event.c perf tools: Print the thread's tid on PERF_RECORD_COMM events when -D is asked 2015-02-24 17:34:00 -03:00
event.h Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2014-12-09 21:18:06 -08:00
evlist.c perf evlist: Introduce set_filter_pids method 2015-02-22 22:21:27 -03:00
evlist.h perf evlist: Adopt events_stats from perf_session 2015-02-22 22:22:57 -03:00
evsel.c perf record: Support recording running/enabled time 2015-02-25 12:42:23 -03:00
evsel.h perf tools: Construct LBR call chain 2015-02-18 17:16:18 +01:00
exec_cmd.c
exec_cmd.h
find-vdso-map.c perf tools: Build programs to copy 32-bit compatibility 2014-10-29 10:32:48 -02:00
generate-cmdlist.sh tools/perf: Standardize feature support define names to: HAVE_{FEATURE}_SUPPORT 2013-10-09 08:48:28 +02:00
header.c perf header: Set header version correctly 2015-01-29 16:53:11 -03:00
header.h perf build-id: Move build-id related functions to util/build-id.c 2014-11-05 10:14:07 -03:00
help.c perf tools: Use zfree to help detect use after free bugs 2013-12-27 17:08:19 -03:00
help.h
hist.c perf tools: Pass struct perf_hpp_fmt to its callbacks 2015-01-21 13:24:34 -03:00
hist.h perf tools: Pass struct perf_hpp_fmt to its callbacks 2015-01-21 13:24:34 -03:00
intlist.c perf util: Add findnew method to intlist 2013-10-14 10:28:48 -03:00
intlist.h perf util: Add findnew method to intlist 2013-10-14 10:28:48 -03:00
kvm-stat.h perf kvm stat report: Save pid string in opts.target.pid 2014-09-17 17:08:07 -03:00
levenshtein.c
levenshtein.h
machine.c perf tools: Construct LBR call chain 2015-02-18 17:16:18 +01:00
machine.h perf tools: Add facility to export data in database-friendly way 2014-10-29 10:32:49 -02:00
map.c perf callchain: Make get_srcline fall back to sym+offset 2014-11-24 18:03:47 -03:00
map.h perf symbols: Introduce 'for' method to iterate over the symbols with a given name 2015-01-21 10:06:15 -03:00
ordered-events.c perf ordered_events: Stop using tool->ordered_events 2015-02-23 11:39:38 -03:00
ordered-events.h perf session: Add option to copy events when queueing 2014-10-15 17:39:03 -03:00
pager.c perf tools: Add cat as fallback pager 2014-05-21 11:48:33 +02:00
parse-events.c perf list: Place the header text in its right position 2015-02-13 11:57:50 -03:00
parse-events.h perf tools: Make perf aware of tracefs 2015-02-11 12:37:08 -03:00
parse-events.l perf tools: allow user to specify hardware breakpoint bp_len 2014-12-03 15:14:29 +01:00
parse-events.y perf tools: allow user to specify hardware breakpoint bp_len 2014-12-03 15:14:29 +01:00
parse-options.c perf tools: Fix a bug of segmentation fault 2015-02-13 11:38:43 -03:00
parse-options.h perf tools: Add support for exclusive option 2014-10-29 10:32:47 -02:00
path.c tools/perf: Turn strlcpy() into a __weak function 2013-10-09 08:48:49 +02:00
PERF-VERSION-GEN perf tools: Fix version when building out of tree 2013-11-07 10:40:47 -03:00
perf_regs.c perf tools: Cache register accesses for unwind processing 2014-06-12 16:53:19 +02:00
perf_regs.h perf tools: Cache register accesses for unwind processing 2014-06-12 16:53:19 +02:00
pmu.c perf tools: Extend format_alias() to include event parameters 2015-01-21 13:24:33 -03:00
pmu.h perf tools: Add snapshot format file parsing 2014-11-24 18:03:51 -03:00
pmu.l
pmu.y perf tools: Fix build with bison 2.3 and older. 2013-02-14 16:12:34 -03:00
probe-event.c perf probe: Handle strdup() failure 2015-02-27 10:08:29 -03:00
probe-event.h perf probe: Do not access kallsyms when analyzing user binaries 2014-09-17 18:01:14 -03:00
probe-finder.c perf probe: Fix to handle optimized not-inlined functions 2015-02-06 11:46:36 +01:00
probe-finder.h perf probe: Support distro-style debuginfo for uprobe 2014-02-18 09:38:44 -03:00
pstack.c perf tools: Move pr_* debug macros into debug object 2014-07-17 12:58:39 -03:00
pstack.h perf tools: Finish the removal of 'self' arguments 2013-11-05 15:32:36 -03:00
python-ext-sources perf tools: Remove api fs object from python build 2015-02-12 11:22:01 -03:00
python.c perf tools: Remove EOL whitespaces 2015-01-21 13:24:31 -03:00
quote.c
quote.h
rblist.c perf util: Add findnew method to intlist 2013-10-14 10:28:48 -03:00
rblist.h perf util: Add findnew method to intlist 2013-10-14 10:28:48 -03:00
record.c perf tools: Use sysctl__read_int instead of ad-hoc copies 2014-12-11 17:53:04 -03:00
run-command.c perf util: Replace strerror with strerror_r for thread-safety 2014-08-15 10:58:35 -03:00
run-command.h
session.c perf session: Remove perf_session from dump_event 2015-02-22 22:23:46 -03:00
session.h perf evlist: Adopt events_stats from perf_session 2015-02-22 22:22:57 -03:00
setup.py tools lib api: Rename libapikfs.a to libapi.a 2015-02-12 17:55:18 -03:00
sigchain.c
sigchain.h
sort.c perf diff: Support for different binaries 2015-02-27 10:08:38 -03:00
sort.h perf tools: Add +field argument support for --field option 2014-08-24 08:11:19 -03:00
srcline.c perf: Fix building warning on ARM 32 2014-12-19 13:09:43 +01:00
stat.c perf stats: Add max and min stats 2013-08-07 17:35:26 -03:00
stat.h tools: Consolidate types.h 2014-05-01 21:22:39 +02:00
strbuf.c perf tools: Use zfree to help detect use after free bugs 2013-12-27 17:08:19 -03:00
strbuf.h
strfilter.c perf tools: Use zfree to help detect use after free bugs 2013-12-27 17:08:19 -03:00
strfilter.h perf tools: Finish the removal of 'self' arguments 2013-11-05 15:32:36 -03:00
string.c Revert "perf tools: Default to cpu// for events v5" 2014-10-15 16:04:33 -03:00
strlist.c perf tools: Fix build error due to zfree() cast 2014-01-15 15:10:04 -03:00
strlist.h perf tools: Stop using 'self' in strlist 2013-01-25 12:49:28 -03:00
svghelper.c perf timechart: Implement IO mode 2014-07-10 00:22:54 +02:00
svghelper.h perf timechart: Implement IO mode 2014-07-10 00:22:54 +02:00
symbol-elf.c perf symbols: Define STT_GNU_IFUNC for glibc 2.9 and older. 2015-02-11 12:37:32 -03:00
symbol-minimal.c perf symbols: Fix use after free in filename__read_build_id 2014-12-17 11:58:17 -03:00
symbol.c perf tools: Remove EOL whitespaces 2015-01-21 13:24:31 -03:00
symbol.h perf symbols: Introduce method to iterate symbols ordered by name 2015-01-21 10:05:54 -03:00
target.c perf record: Make per-cpu mmaps the default. 2013-11-27 14:58:36 -03:00
target.h perf target: Move the checking of which map function to call into function. 2013-12-04 13:46:37 -03:00
thread-stack.c perf tools: Enhance the thread stack to output call/return data 2014-11-03 17:43:56 -03:00
thread-stack.h perf tools: Enhance the thread stack to output call/return data 2014-11-03 17:43:56 -03:00
thread.c perf tools: Only override the default :tid comm entry 2014-11-19 12:37:26 -03:00
thread.h perf tools: Add a thread stack for synthesizing call chains 2014-11-03 17:10:59 -03:00
thread_map.c perf thread_map: Create dummy constructor out of open coded equivalent 2014-10-14 17:32:52 -03:00
thread_map.h perf thread_map: Create dummy constructor out of open coded equivalent 2014-10-14 17:32:52 -03:00
tool.h perf tools: Add id index 2014-10-29 11:24:47 -02:00
top.c perf tools: Rename 'perf_record_opts' to 'record_opts 2013-12-19 14:43:45 -03:00
top.h tools: Consolidate types.h 2014-05-01 21:22:39 +02:00
trace-event-info.c perf tools: Move pr_* debug macros into debug object 2014-07-17 12:58:39 -03:00
trace-event-parse.c perf tools: Introduce event_format__fprintf method 2015-02-06 11:46:37 +01:00
trace-event-read.c perf tools: Remove needless getopt.h includes 2014-07-17 12:59:00 -03:00
trace-event-scripting.c perf scripting: Add 'flush' callback to scripting API 2014-08-22 13:12:11 -03:00
trace-event.c tools lib traceevent: Make plugin unload function receive pevent 2014-01-15 15:10:40 -03:00
trace-event.h perf tools: Introduce event_format__fprintf method 2015-02-06 11:46:37 +01:00
tsc.c perf tools: Move rdtsc() function 2014-07-23 11:48:11 -03:00
tsc.h perf tools: Move rdtsc() function 2014-07-23 11:48:11 -03:00
unwind-libdw.c perf callchains: Use thread->mg->machine 2014-10-29 10:32:46 -02:00
unwind-libdw.h perf tools: Add libdw DWARF post unwind support 2014-02-24 09:29:36 -03:00
unwind-libunwind.c perf callchain: Cache eh/debug frame offset for dwarf unwind 2015-01-29 16:20:42 -03:00
unwind.h perf callchains: Use thread->mg->machine 2014-10-29 10:32:46 -02:00
usage.c
util.c perf tools: Introduce dump_stack signal helper 2015-02-24 15:34:23 -03:00
util.h perf tools: Introduce dump_stack signal helper 2015-02-24 15:34:23 -03:00
values.c perf tools: Use zfree to help detect use after free bugs 2013-12-27 17:08:19 -03:00
values.h tools: Consolidate types.h 2014-05-01 21:22:39 +02:00
vdso.c perf tools: Do not attempt to run perf-read-vdso32 if it wasn't built 2014-10-29 10:32:48 -02:00
vdso.h perf tools: Add support for 32-bit compatibility VDSOs 2014-10-29 10:32:48 -02:00
wrapper.c
xyarray.c
xyarray.h
zlib.c perf tools: Add gzip decompression support for kernel module 2014-11-05 10:11:26 -03:00