SlideShare a Scribd company logo
a little systemtap
detailyang@gmail.com
2016 11-24
什什么是 systemtap
Linux 下万能的 Trace ⼯工具。
Linux 下⽬目前的 Tracer
systemtap 能做什什么
跟踪系统调⽤用
stap -e 'probe syscall.open {printf("%s(%d) is opening
%sn", execname(), pid(), user_string($filename))}'
vminfo(710) is opening /var/run/utmp
less(11933) is opening /root/.lesshst
cat(12198) is opening /etc/ld.so.cache
cat(12198) is opening /lib64/libc.so.6
cat(12198) is opening /usr/lib/locale/locale-archive
cat(12198) is opening /tmp/123
跟踪内核态
probe kernel.function("tcp_retransmit_skb") {
rto = tcp_get_info_rto($sk)
saddr = format_ipaddr(__ip_sock_saddr($sk), __ip_sock_family($sk))
daddr = format_ipaddr(__ip_sock_daddr($sk), __ip_sock_family($sk))
sport = __tcp_sock_sport($sk)
dport = __tcp_sock_dport($sk)
lastrto = record[saddr, sport, daddr, dport]
state = tcp_ts_get_info_state($sk)
if (lastrto != rto) {
if (lastrto) {
printf("%s:%d => %s:%d STATE:%s RTO:%d -> %d (ms)n", saddr, sport,
daddr, dport, tcp_sockstate_str(state), lastrto/1000, rto/1000)
} else {
printf("%s:%d => %s:%d STATE:%s RTO:%d (ms)n", saddr, sport,
daddr, dport, tcp_sockstate_str(state), rto/1000)
}
}
record[saddr, sport, daddr, dport] = rto
}
跟踪应⽤用程序
probe process(“/usr/bin/redis-server”).function(“getConmmand") {
printf(“id:%d %s %sn", $c->id, user_string($c->argv[0]-
>ptr), user_string($c->argv[1]->ptr))
}
id:2 get abcd
id:2 get a
systemtap 安装
yum install -y systemtap
早先的内核版本依赖utrace补丁
3.50 使⽤用内核 uprobes 和 uretprobes
systemtap 原理理
调试符号是什什么
Linux ⽬目前的调试格式 dwarf
调试符号是什什么
源代码中每个对象的名称。例例如变量量、函数、类型等,它们都有⼀一个名称,
以及其它的相关信息:变量量有类型、地址等信息;函数有返回值类型、参
数类型、地址等信息;类型有⻓长度等信息。编译器器在编译每个源⽂文件的时
候都会收集该源⽂文件中的符号的信息,在⽣生成⽬目标⽂文件的时候将这些信息
保存到符号表中。链接器器使⽤用符号表中的信息将各个⽬目标⽂文件链接成可执
⾏行行⽂文件,同时将多个符号表整合成⼀一个⽂文件,这个⽂文件就是⽤用于调试的符
号⽂文件,它既可以嵌⼊入可执⾏行行⽂文件中,也可以独⽴立存在
stap -L 'process("/usr/bin/redis-
server").function("zzlPrev")'
process("/usr/bin/redis-server").function("zzlPrev@/usr/
src/debug/redis-2.8.19/src/t_zset.c:720") $zl:unsigned
char* $eptr:unsigned char** $sptr:unsigned char**
分离的 debug info
因为程序带上调试符号会⾮非常⼤大,⽽而且不不是所有的⽤用户需要调试符号。
所以有了了分离的 debug info。
RPM的机制
/usr/lib/rpm/find-debuginfo.sh --strict-build-id xx
extracting debug info from xx
RPM的机制
奥秘在于⼆二进制中的 build-id
objcopy xx xx.debug
strip --strip-debug ./xx
RPM的机制
奥秘在于程序中的 build-id
objcopy xx xx.debug
strip --strip-debug ./xx
objdump -s -j .note.gnu.build-id /usr/bin/redis-server
RPM的机制
build-id =
0x13f3f3476a9a652bc2bb96eba1d0e1d89c570d3966
ls /usr/lib/debug/.build-id/13/
f3476a9a652bc2bb96eba1d0e1d89c570d3966
0x13 f3f3476a9a652bc2bb96eba1d0e1d89c570d3966
RPM的机制
ngx-req-watch
[root@localhost systemtap-toolkit]# ./ngx-req-watch -p 5614
WARNING: watching /opt/nginx/sbin/nginx(8521 8522 8523 8524) requests
nginx(8523) GET URI:/123?a=123 HOST:127.0.0.1 STATUS:200 FROM 127.0.0.1 FD:16 RT:
0ms
nginx(8523) GET URI:/123?a=123 HOST:127.0.0.1 STATUS:200 FROM 127.0.0.1 FD:16 RT:
0ms
libcurl-watch-req
[root@localhost systemtap-toolkit]# ./libcurl-watch-req
WARNING: Tracing libcurl (0) ...
curl(23759) URL:http://www.google.com RT:448(ms) RTCODE:0
curl(23767) URL:http://www.facebook.com/asdfasdf RT:596(ms) RTCODE:0
curl(23769) URL:https://www.facebook.com/asdfasdf RT:902(ms) RTCODE:0
redis-watch-req
[root@localhost systemtap-toolkit]# ./redis-watch-req -p 23261
WARNING: watching /usr/bin/redis-server(23261) requests
redis-server(23261) RT:30(us) REQ: id:2 fd:5 ==> get a #-1 RES: #9
redis-server(23261) RT:23(us) REQ: id:2 fd:5 ==> set a #12 RES: #5
pdomysql-watch-query
[root@localhost systemtap-toolkit]# ./pdomysql-watch-query -l /usr/lib64/php/modules/
pdo_mysql.so
Tracing pdo-mysql (0)
php-fpm(12896) 172.17.10.196:3306@root: SELECT * from person RT:0(ms) RTCODE:1
php-fpm(12896) 172.17.10.196:3306@root: SELECT * from person RT:8(ms) RTCODE:1
php-fpm(12896)172.17.10.196:3306@root: SELECT sleep(5) RT:5012(ms) RTCODE:1
TCP-Retrans
[root@localhost systemtap-toolkit]# ./tcp-retrans
Printing tcp retransmission
10.0.2.15:49896 -> 172.17.9.41:80 state:TCP_SYN_SENT rto:0 -> 1000 ms
10.0.2.15:49896 -> 172.17.9.41:80 state:TCP_SYN_SENT rto:1000 -> 2000 ms
10.0.2.15:49896 -> 172.17.9.41:80 state:TCP_SYN_SENT rto:2000 -> 4000 ms
beyond c land
MySQL DTRACE
Python DTRACE
Java DTRACE
Q&A

More Related Content

PDF
PFIセミナー資料 H27.10.22
PDF
Osol Pgsql
PDF
nouka inventry manager
PPTX
agri inventory - nouka data collector / yaoya data convertor
PDF
Killing any security product … using a Mimikatz undocumented feature
PDF
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
PDF
The true story_of_hello_world
PDF
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
PFIセミナー資料 H27.10.22
Osol Pgsql
nouka inventry manager
agri inventory - nouka data collector / yaoya data convertor
Killing any security product … using a Mimikatz undocumented feature
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
The true story_of_hello_world
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...

What's hot (19)

ODP
Proxy arp
PDF
Haproxy - zastosowania
PPTX
PDF
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
PDF
Vm ware fuzzing - defcon russia 20
PDF
Jvm的最小使用内存测试
PDF
5 issues
ODP
Tools used for debugging
PDF
Importance of linux system fundamental in technical documentation reading
PDF
Recent my sql_performance Test detail
PDF
Reverse engineering Swisscom's Centro Grande Modem
PDF
Building a DSL with GraalVM (VoxxedDays Luxembourg)
PDF
Redis as a message queue
PDF
Fixed in drizzle
PDF
My sql fabric ha and sharding solutions
PDF
37562259 top-consuming-process
PPT
E nodeb useful commands for rf engineer
PDF
Chap 19 web
Proxy arp
Haproxy - zastosowania
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Vm ware fuzzing - defcon russia 20
Jvm的最小使用内存测试
5 issues
Tools used for debugging
Importance of linux system fundamental in technical documentation reading
Recent my sql_performance Test detail
Reverse engineering Swisscom's Centro Grande Modem
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Redis as a message queue
Fixed in drizzle
My sql fabric ha and sharding solutions
37562259 top-consuming-process
E nodeb useful commands for rf engineer
Chap 19 web
Ad

Similar to A little systemtap (20)

PDF
Crash_Report_Mechanism_In_Tizen
PDF
Debugging Ruby
PDF
Debugging Ruby Systems
PDF
Linux Tracing Superpowers by Eugene Pirogov
PDF
Performance tweaks and tools for Linux (Joe Damato)
PPT
Systemtap
DOC
X64服务器 lnmp服务器部署标准 new
PDF
Kernelvm 201312-dlmopen
PDF
Kernel crashdump
PPTX
hacking-embedded-devices.pptx
PDF
Pentesting111111 Cheat Sheet_OSCP_2023.pdf
PPT
Basic Linux kernel
PDF
OSDC 2017 - Werner Fischer - Linux performance profiling and monitoring
PDF
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
PDF
Kernel Recipes 2015 - Kernel dump analysis
PDF
Multipath
PDF
Linux: LVM
PDF
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
PPT
Qemu - Raspberry | while42 Singapore #2
PPTX
Debug generic process
Crash_Report_Mechanism_In_Tizen
Debugging Ruby
Debugging Ruby Systems
Linux Tracing Superpowers by Eugene Pirogov
Performance tweaks and tools for Linux (Joe Damato)
Systemtap
X64服务器 lnmp服务器部署标准 new
Kernelvm 201312-dlmopen
Kernel crashdump
hacking-embedded-devices.pptx
Pentesting111111 Cheat Sheet_OSCP_2023.pdf
Basic Linux kernel
OSDC 2017 - Werner Fischer - Linux performance profiling and monitoring
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
Kernel Recipes 2015 - Kernel dump analysis
Multipath
Linux: LVM
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
Qemu - Raspberry | while42 Singapore #2
Debug generic process
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Monthly Chronicles - July 2025
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
NewMind AI Monthly Chronicles - July 2025

A little systemtap