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
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
110
Wantedly での Datadog 活用事例
bgpat
1
410
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
160
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
CustomCopを使ってMongoidのコーディングルールを整えてみた
jinoketani
0
220
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
160
Qiita埋め込み用スライド
naoki_0531
0
860
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
The Cult of Friendly URLs
andyhume
78
6.1k
We Have a Design System, Now What?
morganepeng
51
7.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
A Tale of Four Properties
chriscoyier
157
23k
KATA
mclloyd
29
14k
Six Lessons from altMBA
skipperchong
27
3.5k
How to train your dragon (web standard)
notwaldorf
88
5.7k
How STYLIGHT went responsive
nonsquared
95
5.2k
The Invisible Side of Design
smashingmag
298
50k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Unsuck your backbone
ammeep
669
57k
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͋ͱɺࣗͰ͋·Γ͑ͯͳ͍ͷͰͬͯΈΔɻ