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
120
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
89
slub: alloc and free
masami256
0
100
SLUB data structures
masami256
0
140
SystemV IPC
masami256
0
140
Linux Namespace
masami256
0
97
とある帽子の大蛇料理Ⅱ
masami256
0
100
Gnomeとdogtail
masami256
0
110
x86 とコンテキストスイッチ
masami256
0
310
Other Decks in Programming
See All in Programming
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
290
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.6k
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
30
14k
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.2k
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.2k
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
510
一人だけ、Kiroが静止する日
hideg
0
140
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
9.3k
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
370
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
460
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.5k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
290
A designer walks into a library…
pauljervisheath
211
25k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
The browser strikes back
jonoalderson
0
1.7k
Utilizing Notion as your number one productivity tool
mfonobong
4
610
How GitHub (no longer) Works
holman
316
150k
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Thoughts on Productivity
jonyablonski
76
5.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
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/