perf tools: Call graph from Intel BTS

From: Adrian Hunter
Date: Fri Jul 11 2014 - 10:36:53 EST


Alexander Shishkin is working on the Intel PT driver for perf
and has included a driver for Intel BTS. I have taken that and
extended perf tools to enable the creation of context-sensitive
call graphs. A screen shot from an example call graph from
tracing "ls" is shown here:

The patches are here:

There are many perf tools patches and it would be helpful to start
considering how to get them into mainline. Many need to wait for
the driver, but others could be taken sooner.

The perf tools python API has been extended to facilitate exporting
to databases, a script is provided to export to PostgreSQL, and
another script reads the database and displays the call graph.

The Intel BTS data provides branches (address from / to) but to
create the call graph the type of instruction (call, return etc)
is needed. That is found by reading the object code, but for the
kernel that requires an accurate image. A copy of /proc/kcore
is needed but it must be made under the same conditions as the
trace. That has proven sufficiently awkward to warrant creating
a script to do it.

Here is how the "ls" call graph was created:

$ sudo bash -c 'echo 0 > /proc/sys/kernel/kptr_restrict'
$ sudo bash -c 'echo -1 > /proc/sys/kernel/perf_event_paranoid'
$ sudo bash -c 'chmod go+rx /sys/kernel/debug'
$ ~/libexec/perf-core/perf-with-kcore record bts_ls --per-thread -e intel_bts// -- ls
Using /home/ahunter/bin/perf
perf version 3.16.rc2.linux.local.gaabf
/home/ahunter/bin/perf record -o bts_ls/ --per-thread -e intel_bts// -- ls
CREDITS drivers ipc MAINTAINERS modules.order REPORTING-BUGS signing_key.priv tools vmlinux.o
arch crypto firmware Kconfig Makefile Module.symvers samples signing_key.x509 usr x509.genkey
block fs include kernel mm net scripts sound virt
bts_ls COPYING Documentation init Kbuild lib modules.builtin README security vmlinux
[ perf record: Woken up 100 times to write data ]
[ perf record: Captured and wrote 6.945 MB bts_ls/ ]
Copying kcore
$ ~/libexec/perf-core/perf-with-kcore script bts_ls -s ~/libexec/perf-core/scripts/python/ bts_ls branches calls
Using /home/ahunter/bin/perf
perf version 3.16.rc2.linux.local.gaabf
/home/ahunter/bin/perf script -i bts_ls/ --kallsyms=bts_ls/kcore_dir/kallsyms -s ~/libexec/perf-core/scripts/python/ bts_ls branches calls
2014-07-11 15:13:38.313702 Creating database...
2014-07-11 15:13:39.150277 Writing to intermediate files...
2014-07-11 15:13:40.182816 Copying to database...
2014-07-11 15:13:41.776815 Removing intermediate files...
2014-07-11 15:13:41.783443 Adding primary keys
2014-07-11 15:13:44.290786 Adding foreign keys
2014-07-11 15:13:44.974865 Done
$ ~/libexec/perf-core/scripts/python/ bts_ls


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at