linux-stable/tools/perf
Wang Nan c03d5184f0 perf machine: Adjust dso->long_name for offline module
Something unexpected may happen if copy statically linked perf to a
production environment:

  # ./perf probe -m ./mymodule.ko my_func
  [mymodule] with build id 326ab42550ef3d24944f53c817533728367effeb not found, continuing without symbols
  Failed to find symbol my_func in /home/wangnan/kmodule/mymodule.ko
    Error: Failed to add events.
  # ./perf buildid-cache -a ./mymodule.ko
  # ./perf probe -m ./mymodule.ko my_func
  Added new event:
    probe:my_func        (on my_func in /home/wangnan/kmodule/mymodule.ko)

  You can now use it in all perf tools, such as:

  	perf record -e probe:my_func -aR sleep 1

Where:

  # ldd ./perf
 	not a dynamic executable
  # strace -e open ./perf probe -m ./mymodule.ko my_func
  ...
  open("/home/wangnan/kmodule/mymodule.ko", O_RDONLY) = 3
  open("/home/wangnan/kmodule/../lib64/elfutils/libebl_x86_64.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  ...
  open("/lib64/tls/libebl_x86_64.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  open("/lib64/libebl_x86_64.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  open("/usr/lib64/tls/libebl_x86_64.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  open("/usr/lib64/libebl_x86_64.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  open("[mymodule]", O_RDONLY)            = -1 ENOENT (No such file or directory)
  open("/home/wangnan/.debug/.build-id/32/6ab42550ef3d24944f53c817533728367effeb", O_RDONLY) = -1 ENOENT (No such file or directory)
  open("[mymodule]", O_RDONLY)            = -1 ENOENT (No such file or directory)

In the above example, probe fails before we put the module into
buildid-cache. However, user would expect it success in both case
because perf is able to find probe points actually.

The reason is because perf won't utilize module's full path if it failed
to open debuginfo. In:

     convert_to_probe_trace_events ->
        find_probe_trace_events_from_map ->
            get_target_map ->
                kernel_get_module_map ->
                    machine__findnew_module_map ->
                        map_groups__find_by_name

map_groups__find_by_name() is able to find the map of that module, but
this information is found from /proc/module before it knows the real
path of the offline module. Therefore, the map->dso->long_name is set to
something like '[mymodule]', which prevent dso__load() find the real
path of the module file.

In another aspect, if dso__load() can get the offline module through
buildid cache, it can read symble table from that ko. Even if debuginfo
is not available, 'perf probe' can success if the '.symtab' can be
found.

This patch improves machine__findnew_module_map(): when dso->long_name
is leading with '[' (doesn't find path of module when parsing
/proc/modules), fixes it by dso__set_long_name(), so following
dso__load() is possible to find the symbol table.

This patch won't interfere with buildid matching. Here is the test
result:

  # ./perf probe -m ./mymodule.ko my_func
  Added new event:
    probe:my_func        (on my_func in /home/wangnan/kmodule/mymodule.ko)

  You can now use it in all perf tools, such as:

  	perf record -e probe:my_func -aR sleep 1

  # ./perf probe -d '*'
  Removed event: probe:my_func
  # mv ./mymodule.{ko,.bak}
  # mv ./moduleb.ko mymodule.ko
  # ./perf probe -m ./mymodule.ko my_func
  /home/wangnan/kmodule/mymodule.ko with build id 326ab42550ef3d24944f53c817533728367effeb not found, continuing without symbols
  Failed to find symbol my_func in /home/wangnan/kmodule/mymodule.ko
    Error: Failed to add events.

  # ./perf probe -v -m ./mymodule.ko my_func
  probe-definition(0): my_func
  symbol:my_func file:(null) line:0 offset:0 return:0 lazy:(null)
  0 arguments
  Could not open debuginfo. Try to use symbols.
  symsrc__init: build id mismatch for /home/wangnan/kmodule/mymodule.ko.
  /home/wangnan/kmodule/mymodule.ko with build id 326ab42550ef3d24944f53c817533728367effeb not found, continuing without symbols
  Failed to find symbol my_func in /home/wangnan/kmodule/mymodule.ko
    Error: Failed to add events. Reason: No such file or directory (Code: -2)

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1448510397-187965-1-git-send-email-wangnan0@huawei.com
[ Renamed adjust_dso_long_name() do dso__adjust_kmod_long_name() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-11-26 13:47:43 -03:00
..
arch perf tests: Pass the subtest index to each test routine 2015-11-19 13:19:15 -03:00
bench perf bench: Use named initializers in the trailer too 2015-10-19 18:17:25 -03:00
config perf bpf: Add BPF_PROLOGUE config options for further patches 2015-11-18 17:51:03 -03:00
Documentation perf config: Add initial man page 2015-11-23 18:31:25 -03:00
python perf python: Support the PERF_RECORD_SWITCH event 2015-10-07 19:41:50 -03:00
scripts perf tools: Add more documentation to export-to-postgresql.py script 2015-09-28 16:53:07 -03:00
tests perf test: Add callchain order setup for DWARF unwinder test 2015-11-23 18:31:01 -03:00
trace/strace/groups perf trace: Add read/write to the file group 2015-09-04 13:22:06 -03:00
ui perf ui/gtk: Support folded callchains 2015-11-19 13:19:26 -03:00
util perf machine: Adjust dso->long_name for offline module 2015-11-26 13:47:43 -03:00
.gitignore perf tools: Add Intel PT instruction decoder 2015-08-17 11:11:36 -03:00
Build perf tools: Add 'perf config' command 2015-11-23 18:31:24 -03:00
builtin-annotate.c perf env: Rename some leftovers from rename to perf_env 2015-09-14 12:50:20 -03:00
builtin-bench.c perf bench: Run benchmarks, don't test them 2015-10-19 16:10:25 -03:00
builtin-buildid-cache.c perf buildid: Introduce sysfs/filename__sprintf_build_id 2015-08-28 14:53:50 -03:00
builtin-buildid-list.c perf buildid: Introduce sysfs/filename__sprintf_build_id 2015-08-28 14:53:50 -03:00
builtin-config.c perf tools: Add 'perf config' command 2015-11-23 18:31:24 -03:00
builtin-data.c perf data: Support using -f to override perf.data file ownership for 'convert' 2015-04-02 13:18:52 -03:00
builtin-diff.c perf callchain: Allow disabling call graphs per event 2015-08-12 13:20:28 -03:00
builtin-evlist.c perf tools: Introduce usage_with_options_msg() 2015-10-27 09:28:44 -03:00
builtin-help.c perf help: Change 'usage' to 'Usage' for consistency 2015-10-19 16:51:44 -03:00
builtin-inject.c perf inject: Also re-pipe lost_samples event 2015-11-13 12:23:12 -03:00
builtin-kmem.c perf machine: Add method for common kernel_map(FUNCTION) operation 2015-09-30 18:34:29 -03:00
builtin-kvm.c tools lib api fs: Replace debugfs/tracefs objects interface with fs.c 2015-09-14 12:50:15 -03:00
builtin-list.c perf list: Do event name substring search as last resort when no events found 2015-10-01 12:12:22 -03:00
builtin-lock.c perf machine: Protect the machine->threads with a rwlock 2015-05-08 16:19:27 -03:00
builtin-mem.c perf mem: Fill in the missing session freeing after an error occurs 2015-07-01 17:53:49 -03:00
builtin-probe.c perf tools: Introduce usage_with_options_msg() 2015-10-27 09:28:44 -03:00
builtin-record.c perf record: Add clang options for compiling BPF scripts 2015-10-29 17:16:22 -03:00
builtin-report.c perf callchain: Honor hide_unresolved 2015-11-26 13:19:39 -03:00
builtin-sched.c perf sched latency: Fix thread pid reuse issue 2015-11-05 12:51:00 -03:00
builtin-script.c perf script: Remove default_scripting_ops 2015-11-26 13:33:00 -03:00
builtin-stat.c perf stat: Make stat options global 2015-11-05 17:54:34 -03:00
builtin-timechart.c perf tools: Elliminate alignment holes 2015-05-18 10:17:33 -03:00
builtin-top.c perf tools: Improve call graph documents and help messages 2015-10-22 16:23:19 -03:00
builtin-trace.c perf trace: Add cmd string table to decode sys_bpf first arg 2015-10-29 11:48:18 -03:00
builtin.h perf tools: Add 'perf config' command 2015-11-23 18:31:24 -03:00
command-list.txt perf tools: Add 'perf config' command 2015-11-23 18:31:24 -03:00
CREDITS
design.txt
Makefile perf tools: Allow shuffling the build tests 2015-11-05 11:39:54 -03:00
Makefile.perf perf build: Fix traceevent plugins build race 2015-11-26 13:35:38 -03:00
MANIFEST tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c 2015-11-18 17:51:02 -03:00
perf-archive.sh
perf-completion.sh perf tools: Avoid confusion with preloaded bash function for perf bash completion 2015-03-19 13:53:27 -03:00
perf-read-vdso.c perf tools: Build programs to copy 32-bit compatibility 2014-10-29 10:32:48 -02:00
perf-sys.h perf tools: Move generic barriers out of perf-sys.h 2015-05-08 16:05:08 -03:00
perf-with-kcore.sh perf tools: Fix perf-with-kcore handling of arguments containing spaces 2015-08-06 16:48:27 -03:00
perf.c perf tools: Add 'perf config' command 2015-11-23 18:31:24 -03:00
perf.h perf record: Add ability to name registers to record 2015-08-31 18:01:33 -03:00