Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Linux の Debug 機能
Search
Masami Ichikawa
May 18, 2016
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Linux の Debug 機能
Masami Ichikawa
May 18, 2016
More Decks by Masami Ichikawa
See All by Masami Ichikawa
cgroupsとプロセス生成・終了処理
masami256
1
1.4k
Linux Namespaces
masami256
0
85
slub: alloc and free
masami256
0
100
SLUB data structures
masami256
0
130
SystemV IPC
masami256
0
140
Linux Namespace
masami256
0
96
とある帽子の大蛇料理Ⅱ
masami256
0
100
Gnomeとdogtail
masami256
0
110
x86 とコンテキストスイッチ
masami256
0
310
Other Decks in Programming
See All in Programming
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
信頼性の目標を誰も求めてない
shubox
0
500
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
150
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
700
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.6k
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
120
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
230
AIの中の人になってみる
htkym
0
170
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
55
36k
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
130
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.3k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Paper Plane (Part 1)
katiecoart
PRO
1
11k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
400
We Are The Robots
honzajavorek
0
350
GraphQLとの向き合い方2022年版
quramy
50
15k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
890
How to Ace a Technical Interview
jacobian
281
24k
Transcript
Linux の Debug 機能 • @masami256
Overview • Linux の Debug 機能を紹介します • Debug と言っても gdb
でデバッグという感じで はありません • 実行中のカーネルの情報を見るのに適した機 能です • スクリプト言語で処理を書けるものもあります
Importance • debug 系のパッケージがあると捗ります • -debuginfo • RHEL 系 •
-dbgsym • Ubuntu • symbol 見れないのはやっぱり辛い>< • debug 系のパッケージを提供していないディストリビューション の場合は自前でビルドしましょう
Tools • SystemTap • Perf • Ftrace • eBPF
SystemTap • 専用のスクリプト言語がある • c 言語の関数も組み込める • テトリスを書ける ( ´∀
` )b グッ !
Perf • 性能解析計測ツール • プロセスのボトルネック部分調査 • システム全体で遅い部分の調査 • キャッシュミス等の調査
Ftrace • Linux カーネルの関数のトレース • 関数のコールフローだけでなく、処理時間も計 測できる • 素の ftrace
を使うよりは trace-cmd とかを 使うほうが楽
eBPF • BSD Packet Filter • カーネルに JIT コンパイラがあり、フィルタを JIT
コンパイル • パケットフィルタとは思えない高機能さ • ループ処理は v4.5 時点では書けなかったはず • 素の eBPF を使う場合は c 言語でプログラミング • 新しいカーネルを使うほうが良い • 便利機能が追加されるし
Useful tools • perf-tools • https://github.com/brendangregg/perf-tools • ftrace ベースのスクリプト集 •
bcc • https://github.com/iovisor/bcc • Python でスクリプトを書いて eBPF を使える • Python スクリプト内に c 言語の関数を組み込める
Example:Perf
Example:Perf Cont’d
Example:Perf Cont’d
Example:Perf Cont’d
Example:bcc bcc 付属の tcp connection のモニタリングスクリプトを実行 http status 302 が最初に返
り、 Location ヘッダにある先に接続 するので 2 回分のログが出てる http status 302 が最初に返 り、 Location ヘッダにある先に接続 するので 2 回分のログが出てる
Example:systemtap #!/usr/bin/env stap global call_count = 0 probe process("/usr/lib/libruby.so.2.3.0").function("vm_exec_core") {
call_count += 1 } probe begin { printf("waiting...\n") } probe end { printf("vm_exec_core() was called %d times\n", call_count) } シンボル情報を strip していないバイナリ シンボル情報を strip していないバイナリ
Example:systemtap Cont’d %{ #include <linux/sched.h> #include <linux/thread_info.h> #include <linux/pid_namespace.h> %}
function show_pidtree:long(pn:long) %{ struct task_struct *task; int pid_nr = STAP_ARG_pn; struct pid_namespace *pid_ns; int indent_level = 0, i; struct pid *pid = find_get_pid(pid_nr); if (!pid) { STAP_PRINTF("Could not find pid %d\n", pid_nr); STAP_RETURN(-1); } task = pid_task(pid, PIDTYPE_PID); if (!task) { STAP_PRINTF("Cannot find task by pid %d\n", pid_nr); STAP_RETURN(-1); } pid_ns = task->nsproxy->pid_ns_for_children; do { pid_nr = __task_pid_nr_ns(task, PIDTYPE_PID, pid_ns); for (i = 0; i < indent_level; i++) STAP_PRINTF(" "); STAP_PRINTF("pid %d\n", pid_nr); pid_ns = pid_ns->parent; indent_level++; } while (pid_ns); STAP_RETURN(0); %} c 言語による処理の記述 STAP_XXX は systemtap 固有の書き方
Example:systemtap Cont’d プロセスが所属する全 PID 名前空間での PID を取得 コンテナ内の pid1 はホスト環境の
pid だと 5145 コンテナ内の pid1 はホスト環境の pid だと 5145
Example:ftrace(perf- tools) masami@arch perf-tools[master]$ sudo ./syscount -c ~/login.rb Tracing while
running: "/home/masami/login.rb"... SYSCALL COUNT clock_gettime 1 exit_group 1 set_tid_address 1 sysinfo 1 access 2 connect 2 getrandom 2 getsockname 2 madvise 2 pipe2 2 poll 2 setsockopt 2 socket 2 exit 3 getrlimit 3 rt_sigprocmask 3 sched_getaffinity 3 sigaltstack 3 set_robust_list 4 prctl 5 ppoll 6 lseek 7 munmap 7 getdents 8 write 10 futex 14 rt_sigaction 21 newstat 42 mprotect 62 getgid 79 getegid 80 geteuid 80 getuid 80 mmap 83 fcntl 93 brk 102 ioctl 110 close 253 newfstat 310 read 379 newlstat 553 open 984
Summary • カーネル、周辺ツールともに日々進化してます • 新し目のカーネルが必要になるけど・・・ • systemtap ならユーザーランドのコードも対応 可能 •
Happy Debugging ヽ (=´▽`=) ノ
Reference • http://www.brendangregg.com/ • http://kernhack.hatenablog.com/