[知其然不知其所以然-25] How to setup systemtap

Systemtap is great, record these steps for future backup:

1.

uname -a
Linux MacBookPro-A1502 4.6.0-mainline+ #184 SMP Fri May 27 13:34:14 CST 2016 x86_64 x86_64 x86_64 GNU/Linux

2.

recompile kernel 4.6 with:

CONFIG_DEBUG_INFO, CONFIG_KPROBES, CONFIG_RELAY, CONFIG_DEBUG_FS, CONFIG_MODULES, CONFIG_MODULE_UNLOAD, CONFIG_UPROBES

3.

git clone git://sourceware.org/git/systemtap.git

4. when you configure the systemtap code, you might get:

configure: error: missing elfutils development headers/libraries (install elfutils-devel, libebl-dev, libdw-dev and/or libebl-devel

actually you need to install elfutils and :

apt-get install libdw-dev

5.

make
make install

6.

stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}'

7, but the following script would cause problems when using print_backtrace, so I reported this bug to

systemtap maillist, and someone fixed it  in commit 15de83a by updating the runtime to handle 

the change in the function signature needed by stacktrace_ops.

https://sourceware.org/bugzilla/show_bug.cgi?id=20158

8.

cat tstate.stp
#! /usr/bin/env stap

probe kernel.function("acpi_processor_reevaluate_tstate"){
        print("----------------START-------------------------\n")
        printf("In process [%s]\n", execname())
        printf("on CPU [%d]\n", cpu())
        print_backtrace()
        print("----------------END-------------------------\n")
        //exit()
}
then unplug/plug the CPU, we got backtrace:

./tstate.stp
----------------START-------------------------
In process [bash]
on CPU [0]
 0xffffffff8147645a : acpi_processor_reevaluate_tstate+0x0/0x4b [kernel]
 0xffffffff81474a87 : acpi_cpu_soft_notify+0xd9/0xe4 [kernel]
 0xffffffff8109a4c9 : notifier_call_chain+0x49/0x70 [kernel]
 0xffffffff8109a5ce : __raw_notifier_call_chain+0xe/0x10 [kernel]
 0xffffffff8107aff5 : __cpu_notify+0x35/0x50 [kernel]
 0xffffffff8107b575 : cpu_notify_nofail+0x15/0x20 [kernel]
 0xffffffff8107b5a6 : notify_dead+0x26/0xe0 [kernel]
 0xffffffff8107b7d9 : cpuhp_invoke_callback+0x49/0x100 [kernel]
 0xffffffff8107b95e : cpuhp_down_callbacks+0x4e/0x90 [kernel]
 0xffffffff817bab96 : _cpu_down+0xc6/0x150 [kernel]
 0xffffffff8107c03c : do_cpu_down+0x3c/0x60 [kernel]
 0xffffffff8107c070 : cpu_down+0x10/0x20 [kernel]
 0xffffffff81511724 : cpu_subsys_offline+0x14/0x20 [kernel]
 0xffffffff8150c23a : device_offline+0x8a/0xb0 [kernel]
 0xffffffff8150c330 : online_store+0x40/0x80 [kernel]
 0xffffffff815096c8 : dev_attr_store+0x18/0x30 [kernel]
 0xffffffff812777fa : sysfs_kf_write+0x3a/0x50 [kernel]
 0xffffffff81276e1b : kernfs_fop_write+0x11b/0x1a0 [kernel]
 0xffffffff811fc208 : __vfs_write+0x28/0x120 [kernel]
 0xffffffff811fce42 : vfs_write+0xb2/0x1b0 [kernel]
----------------END-------------------------
----------------START-------------------------
In process [cpuhp/2]
on CPU [2]
 0xffffffff8147645a : acpi_processor_reevaluate_tstate+0x0/0x4b [kernel]
 0xffffffff81474a6a : acpi_cpu_soft_notify+0xbc/0xe4 [kernel]
 0xffffffff8109a4c9 : notifier_call_chain+0x49/0x70 [kernel]
 0xffffffff8109a5ce : __raw_notifier_call_chain+0xe/0x10 [kernel]
 0xffffffff8107aff5 : __cpu_notify+0x35/0x50 [kernel]
 0xffffffff8107b0ac : notify_online+0x1c/0x20 [kernel]
 0xffffffff8107b7d9 : cpuhp_invoke_callback+0x49/0x100 [kernel]
 0xffffffff8107b9e2 : cpuhp_up_callbacks+0x42/0xb0 [kernel]
 0xffffffff8107bb3c : cpuhp_thread_fun+0xec/0x100 [kernel]
 0xffffffff8109ca1f : smpboot_thread_fn+0x10f/0x160 [kernel]
 0xffffffff81099519 : kthread+0xc9/0xe0 [kernel]
 0xffffffff817c65df : ret_from_fork+0x1f/0x40 [kernel]
 0xffffffff81099450 : kthread+0x0/0xe0 [kernel] (inexact)
----------------END-------------------------


你可能感兴趣的:([知其然不知其所以然-25] How to setup systemtap)