Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Linux の Debug 機能
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
82
slub: alloc and free
masami256
0
100
SLUB data structures
masami256
0
130
SystemV IPC
masami256
0
140
Linux Namespace
masami256
0
94
とある帽子の大蛇料理Ⅱ
masami256
0
100
Gnomeとdogtail
masami256
0
110
x86 とコンテキストスイッチ
masami256
0
300
Other Decks in Programming
See All in Programming
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
200
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
530
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
450
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
4
1.3k
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
200
作るコストが小さくなった時代 幸せに働くために改めて考えたいこと 〜エンジニアとして価値を出し続けるために注視している二分野〜
yuppeeng
0
190
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
430
What's New in Android 2026
veronikapj
0
250
仕様駆動開発の消費期限
watany
7
3.5k
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
750
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
610
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
First, design no harm
axbom
PRO
2
1.2k
Darren the Foodie - Storyboard
khoart
PRO
3
3.5k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
400
Game over? The fight for quality and originality in the time of robots
wayneb77
1
240
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/