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
Rustで作るLinuxトレーサ / libbpf-core-with-rust
Search
KONDO Uchio
April 27, 2021
Technology
1
1.1k
Rustで作るLinuxトレーサ / libbpf-core-with-rust
@RustのLT会 Shinjuku.rs #15
https://forcia.connpass.com/event/206698/
KONDO Uchio
April 27, 2021
Tweet
Share
More Decks by KONDO Uchio
See All by KONDO Uchio
大規模レガシーテストを 倒すための CI基盤の作り方 / #CICD2023
udzura
5
2.3k
Ruby x BPF in Action / RubyKaigi 2022
udzura
0
200
Narrative of Ruby & Rust
udzura
0
180
開発者生産性指標の可視化 / pepabo-four-keys
udzura
3
1.6k
Talk of RBS
udzura
0
400
Re: みなさん最近どうですか? / FGN tech meetup in 2021
udzura
0
710
Dockerとやわらかい仮想化 - ProSec-IT/SECKUN 2021 edition -
udzura
2
680
Device access filtering in cgroup v2
udzura
1
780
"Story of Rucy" on RubyKaigi takeout 2021
udzura
0
730
Other Decks in Technology
See All in Technology
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
560
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
480
.NET 9 のパフォーマンス改善
nenonaninu
0
950
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.3k
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
160
MLOps の現場から
asei
6
640
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
540
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
250
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
2024年にチャレンジしたことを振り返るぞ
mitchan
0
140
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
850
Featured
See All Featured
Site-Speed That Sticks
csswizardry
2
190
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Become a Pro
speakerdeck
PRO
26
5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Writing Fast Ruby
sferik
628
61k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Transcript
F#1'ͱ͔͍͏ࠓྲྀߦͬͯΔͭ 6DIJP,POEP(.01FQBCP *OD 4IJOKVLVST 3VTUͰ࡞Δ-JOVYτϨʔα 1IPUPCZ)FSCFSU#JFTFSIUUQTQJYBCBZDPNJNBHFTJE
γχΞɾϓϦϯγύϧΤϯδχΞ ۙ౻ Ӊஐ࿕ / @udzura https://blog.udzura.jp/ Uchio Kondo ٕज़෦ ٕज़ج൫νʔϜ
@ GMOϖύϘ / Ԭ ΤϯδχΞΧϑΣʢԬࢢẂנจԽձؗʣ αϙʔλʔ Duolingo Diamond Leaguer 💎 #Rust #Ruby #mruby #Containers #eBPF #CRIU #Seccomp #RubyKaigi #CloudNativeDays #Zumba #γϨϯ #FitBoxing2
ࠓճ͢ͷҎ֎ʹ࡞ͬͨͷ •octx wίϚϯυҰൃͰࡶʹ(JU)VCͷBDUJWJUZΛ$47ʹͯ͘͠ΕΔͭ ͦͷ··#JH2VFSZͰϩʔυՄೳɻ wPDUPDSBC SFRXFTU UPLJP
5P$ w࡞Ζ͏ͱ͍ͯ͠Δπʔϧͷ wF#1'ͱ wࠓࠓͰ͖͍ͯΔͷ wMJCCQGSTͷ͍ํ w3VTUͰΑ͔ͬͨ
F#1'
F#1' wFYUFOEFE#FSLMFZ1BLFU'JMUFS w͔Β-JOVYͰಋೖʢݩͷ࣮-JOVYͰ͔Βʣ wMJCQDBQͰΘΕ͍͕ͯͨɺTFDDPNQͦͷଞΧʔωϧػೳͰར༻ w-JOVYΧʔωϧ෦Ͱಈ͘ϓϩάϥϜΛɺϢʔβϥϯυͰهड़ wػೳʹ੍ݶ͕͋ΓɺϑΟϧλϦϯάूܭ͕ओͳׂ wৄࡉʮ͓͍ͯͭ͘͠Α͘ͳΔF#1'ʯͰݕࡧ
F#1'ʹΑΔτϨʔα wF#1'ͷେ͖ͳ༻్ͷҰͭʹɺΧʔωϧ෦Ͱͷؔݺͼग़͠ ੩తͳΠϕϯτͳͲΛτϨʔε͠ɺूܭ͢Δ͜ͱ͕͋Δɻ w #4%4PMBSJTͰ͍͏%5SBDF wCQGUSBDFίϚϯυ #$$ #1'$PNQJMFS$PMMFDUJPO ͷ։ൃ IUUQXXXCSFOEBOHSFHHDPNCMPHCQGQFSGPSNBODFUPPMTCPPLIUNM
#1'$03& wͦΕ·Ͱͷ#1'πʔϧɺͦͷͰ#1'ϓϩάϥϜΛੜɺίϯύΠ ϧ͢ΔͳͲʢॊೈͰ͋Δ͕ʣΦʔόʔϔου͕͋ͬͨɻ wͦͷ݁Ռɺಈ࡞ʹDMBOHόΠφϦ͕ඞཁͩͬͨΓɺಋೖ͕ϋʔυ w͏গ͠खܰʹಈ͔ͤΔΑ͏ɺΧʔωϧͷܕใΛऔಘ͢Δ#5'ɺ $03& $PNQJMF0ODF 3VO&WFSZXIFSF ͳͲͷٕज़͕ग़ͯ͘Δ w$03&ʹͳΔͱϫϯόΠφϦπʔϧ
Χʔωϧͷઃఆ͍͔ͭ͘ ΛΠ ϯετʔϧ͢ΕτϨʔε͕Ͱ͖ΔΑ͏ʹɻ
࣮ͷྫ w#1'ͷϓϩάϥϜΛϏϧυ͢Δ $Ͱॻ͘ඞཁ͕͋ΔɻϓϩάϥϜͷҰ෦ ίϯύΠϧ࣌ͷΦϓγϣϯ
࣮ͷྫ w#1'ϓϩάϥϜͷΦϒδΣΫτ͔ΒTLFMʢϔομʣΛੜ͠ɺ Ϣʔβϥϯυͷ$ϓϩάϥϜ͔Β͑ΔΑ͏ʹ͢Δ CQGUPPMͱ͍͏ίϚϯυͰੜ ϓϩάϥϜͷόΠφϦࣗମ͕ϔομʹຒΊࠐ·ΕΔ
࣮ͷྫ wͦͷϔομΛͬͯόΠφϦπʔϧΛ࡞Δɻ w$ݴޠͰɻ wͪͳΈʹCDDͰͷSFGFSFODF࣮ w IUUQTHJUIVCDPNJPWJTPSCDDUSFFNBTUFSMJCCQGUPPMT
ग़དྷ্͕ͬͨόΠφϦͷΠϝʔδ Ϣʔβϥϯυ Χʔωϧ෦ ϓϩάϥϜʢϫϯόΠφϦʣ #1'ϓϩάϥϜ ϩʔυ σʔλΓऔΓ ϓϩάϥϜ ࣮ߦɾूܭ Φϓγϣϯͷղੳ
ग़ྗ Ճ #1' ࣮ߦ࣌ݕࠪ #1'.BQ 1FSGCV⒎FS ར༻ऀ
͜͜·Ͱͷͬ͘͟Γͨ͠·ͱΊ wF#1'͍ͬͯ͏-JOVYͷτϨʔαͳͲΛ࡞Δศརٕज़͕͋Δ wF#1'πʔϧɺҎલDMBOHͰͦͷͰίϯύΠϧ͍͕ͯͨ͠ɺ ࠷ۙϫϯόΠφϦͰΕΔΑ͏ʹͳͬͨ ཁ৽͍͠Χʔωϧ wͦ͏͢ΔͱίϚϯυϥΠϯπʔϧ෦ؚΊͯϫϯόΠφϦʹ͍ͨ͠ wͦͷSFGFSFODF࣮$ݴޠɻ$ݴޠɻ ʮ1SPEVDUJPOͰ#$$ΑΓMJCCQG #1'$03&Λ͏ํ͕ྑ͍ʯ
IUUQTJUJTLKIBUFOBCMPHDPNFOUSZͳͲࢀর
Ϣʔβϥϯυ$ݴޠͰ͋Δඞཁ wͬͯɺຊʹ͋Δʁ w$ݴޠͷ͠͞ wΦϓγϣϯύʔεҰͭͰจࣈྻͷѻ͍ʹۤ࿑͢Δ wͪΐͬͱͨ͜͠ͱͰෆ҆શͳίʔυ͕ wϝϞϦͷѻ͍͕ϝϞϦ͕ w#1'ϓϩάϥϜํͳ͍ʢWFSJpFS͋Δʣ͚ͲɺϢʔβϥϯυ $ͬͯେม͡Όͳ͍ʁ
ͦ͜Ͱ3VTU
ͭͬͨ͘ͷ
DPOUBJOFSUSBDFST wίϯςφؔͷτϨʔεʹಛԽͨ͠πʔϧ܈Λ࡞Ζ͏ͱ͍ͯ͠Δ w൚༻తͳͷ͢Ͱʹ͋ΔͷͰ w3VTU MJCCQGST w$03&ͳͷͰΧʔωϧ͕ ͔ͳΓ৽͘͠ͳ͍ͱͰ͕͢ IUUQTHJUIVCDPNVE[VSBDPOUBJOFSUSBDFSTɹ
DPOTUBU wίϯςφ୯ҐͰͷ γεςϜίʔϧݺͼग़͠ͷ ౷ܭΛදࣔ͢Δ
VOTIBSFTOPPQ wVOTIBSF ͱ͍͏ɺίϯςφΛ࡞͢Δ্ͰॏཁͳγεςϜίʔϧ ͷݺͼग़͠ͱɺͦͷϑϥάΛτϨʔε͢Δ
DPOCJPHSBQI wίϯςφ୯ҐͰɺCMPDL*0ͷঢ়گΛՄࢹԽ͢Δɻ wάϥϑදࣔͰͬͪΌ͚͗ͨ͢ͷͰɺ͏গ͠ݟ͍͢දࣔΛࠓޙ࣮ ͍ͨ͠ʜ
%FNP wDPOTUBU ࠓࢥ͏ͱQFSGͰͰ͖Δؾ ҰԠύϑΥʔϚϯεʹ༏ΕΔ ͣ ˞ಈըͲ͔͜ʹΞοϓ͠·͢
MJCCQGST
MJCCQGSTͱ wF#1'ͷػೳΛ͏গ͠ΞΫηε͘͢͠ϥοϓͨ͠ϥΠϒϥϦͱ͠ ͯMJCCQGͱ͍͏ͷ͕͋Δɻ w#1'ϓϩάϥϜͷϩʔυ w#1'.BQQFSGCV⒎FSͳͲσʔλͷΓऔΓͷΠϯλϑΣʔε wMJCCQG$ϥΠϒϥϦͳͷͰɺ3VTU͔Β͍ͨ͘͢͠ͷ͕ MJCCQGSTɻ
جຊతͳ͍ํ wCQGϓϩάϥϜΛॻ͘ w cargo libbpf buildͰίϯύΠϧͰ͖Δ w cargo libbpf genͰ3VTUͷTLFMΛੜ
w͋ͱͦͷTLFMΛͬͯ3VTUϓϩάϥϜΛॻ͘ wMJCCQGSTͷػೳʹՃ͑ͯɺTUSVDUPQU DUSMD BOZIPX ͦͷଞී௨ͷ 3VTUͷίϚϯυϥΠϯπʔϧͱͯ͠ϓϩάϥϜΛॻ͚0,
NBJOͷྫ ϏϧμʔΛܦ༝ͯ͠ TLFMΛ։͘ ύϥϝʔλΛೖΕͯ TLFMΛϩʔυɺΞλον F#1'ͷΠϯλϑΣʔε͔Β σʔλΛऔಘɺදࣔ
σʔλදࣔͷྫʢQFSGCV⒎FSʣ wσʔλදࣔ༻ͷίʔϧόοΫؔΛఆٛɻσʔλࣗମ&[u8]Ͱ ͬͯ͘ΔͷͰɺQMBJODSBUFͰมͷඞཁ͕͋Δɻ SFQS D ͳߏମʹ1MBJOΛ࣮
σʔλදࣔͷྫʢ#1'.BQʣ w#1'.BQͱ͍͏σʔλूੵମΛܦ༝ͯ͠ɺΧʔωϧͰूΊͨσʔλ ʹϢʔβϥϯυ͔ΒΞΫηεɺදࣔͰ͖Δɻ ߏମఆٛΛ$3VTUͰ߹ΘͤΔ LFZWBMVFͱʹ&[u8]ͳͷͰɺ͜͜Ͱม
Ϣʔβϥϯυ͔Β#1'.BQΛߋ৽ wඵຖʹΧϯλϦηοτ͢ΔΑ͏ͳϓϩάϥϜΛॻ͚Δɻ ॻ͚Δ͚ͲɺMap::update()͕LFZWBMVFͱʹ&[u8]Λཁٻ͢Δͷ Ͱɺ͜͜ม͔͠VOTBGF plain::as_bytes()ͰͰ͖Δ͚Ͳ
<3VTUϨΠϠϝϦοτ>
θϩίετநԽͷڧ͞ w؆ܿʹએݴతʹॻ͍ͯɺεϐʔυͷ͜ͱΛؾʹ͠ͳ͍͍ͯ͘ɺͱ͍ ͏ͷ͍͍ମݧɻ wΤϥʔΛResult<T, E>Ͱѻ͑Δ͚ͩͰੜ࢈ੑΊͬͪΌߴ͍ wͪΖΜϝϞϦʢجຊతʹʣ҆શ wίϚϯυϥΠϯπʔϧͰTUSVDUPQU͕͍͍ wͱʹ͔͘TUSVDUPQU͕͍͍ʢճʣ
๛ͳDSBUFΛ͑Δ wίΞͰͳ͍෦ͷ࠶ൃ໌ਏ͍ͷͰɺ͍͍ײ͡ͷ࣮ʹ͔ͬΓ͍ͨ wΦϓγϣϯύʔαɺ''*ɺՄࢹԽ wUFYUQMPUT͍͍ wDBSHP͕ͦͦ ͍͍ɺXZDBUT
''*ʹڧ͍ wࠓճͷMJCCQGͷΑ͏ʹɺ$ݴޠϕʔεʢ͔͠-JOVYΧʔωϧͱҰॹʹ ϝϯς͞Ε͍ͯΔʣͷͰ͔͍ϥΠϒϥϦΛૉʹ͑Δͷ͍͍ w3VTU$ͰߏମɺϙΠϯλΛΓͱΓ͍͢͠ͷॿ͔Δ w࣌ʹVOTBGFʹͳΔ͚Ͳ
ࠔͬͯΔ͜ͱͱ͔ࠓޙ
ࠓޙͷ՝ wͱ͍͑VOTBGF͕ଟ͍ؾ͕͢ΔɺͳΜͱ͔ͳΒͳ͍͔ͳ w1MBJODSBUFʹཔ͍ͬͯΔͱ͜ΖΛͬͱ͏·͘Ӆ͢ͱ͍͍ͷ͔ wͱ͍͏͔ɺMJCCQG@ST͕&[u8]Λཁٻ͗͢͠ w''*पΓͷػೳ·ͩௐ࢝Ί͔ͨΓͰɺ$ݴޠΈ͍ͨͳॻ͖ํʹ ͳͬͯ͠·͏ɻཁݚڀɻ
ͦͷଞΓ͍ͨ͜ͱ wπʔϧͱͯ͠͏গ͠খճΓΛྑ͍ͨ͘͠ɻ wΦϓγϣϯ૿ͨ͠Γɺͬͱ৭ʑͳϝτϦοΫΛऔΓ͍ͨ wӳޠͱ͔ͰهࣄΛॻ͍ͨํ͕ड͚ͦ͏ɻॻ͘ɻ w͋ͱɺࣗͰ͋·Γ͑ͯͳ͍ͷͰͬͯΈΔɻ