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
190
Narrative of Ruby & Rust
udzura
0
170
開発者生産性指標の可視化 / pepabo-four-keys
udzura
3
1.6k
Talk of RBS
udzura
0
390
Re: みなさん最近どうですか? / FGN tech meetup in 2021
udzura
0
710
Dockerとやわらかい仮想化 - ProSec-IT/SECKUN 2021 edition -
udzura
2
670
Device access filtering in cgroup v2
udzura
1
770
"Story of Rucy" on RubyKaigi takeout 2021
udzura
0
720
Other Decks in Technology
See All in Technology
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
130
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
AGIについてChatGPTに聞いてみた
blueb
0
130
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
220
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Designing for Performance
lara
604
68k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Six Lessons from altMBA
skipperchong
27
3.5k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Being A Developer After 40
akosma
87
590k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Embracing the Ebb and Flow
colly
84
4.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
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͋ͱɺࣗͰ͋·Γ͑ͯͳ͍ͷͰͬͯΈΔɻ