SystemTap学习记录

SystemTap 工具

SystemTap 允许用户在不重新编译代码的情况下利用静态追踪、动态追踪工具,比如在任何地方动态插入printk,或者改变内核的关键数据结构(guru模式)。所有的操作都要以root用户模式下进行。

安装

1
$ sudo apt install systemtap systemtap-runtime

安装 kernel debug symbol

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 16.04 或更高
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C8CAB6595FDFF622
# 旧版本
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01
$ codename=$(lsb_release -c | awk '{print $2}')
$ sudo tee /etc/apt/sources.list.d/ddebs.list << EOF
deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse
EOF

$ sudo apt-get update
$ sudo apt-get install linux-image-$(uname -r)-dbgsym

基础

指令

限制

  • SystemTap 可以在内核空间进行追踪,但在用户空间追踪事件取决于内核的支持(Utrace机制)

  • 没有内置于内核中,所以性能比eBPF稍差。

示例

  • apps/gmalloc_watch.stp - Tracing glib2 memory allocations

    The gmalloc_watch.stp script from Colin Walters' blog traces the allocation of glib2 memory using the markers in glib2.

    1
    # stap gmalloc_watch.stp -T 1
  • memory/glibc-malloc.stp - Overview glibc malloc internal operations

    This script reports on internal statistics of the glibc malloc implementation, as used by a process restricted by stap -x/-c

    1
    # stap glibc-malloc.stp -c 'stap --dump-functions'
  • memory/numa_faults.stp - Summarize Process Misses across NUMA Nodes

    The numa_faults.stp script tracks the read and write pages faults for each process. When the script exits it prints out the total read and write pages faults for each process. The script also provide a break down of page faults per node for each process. This script is useful for determining whether the program has good locality (page faults limited to a single node) on a NUMA computer.

    sample usage in memory/numa_faults.txt

  • ……

火焰图

http://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html

参考

  1. Ubuntu - Systemtap

  2. SystemTap man

  3. SystemTap Tutorial

  4. SystemTap Beginners Guide

  5. SystemTap Example

  6. FlameGraph

Commentaires