Programming RbBCC

Programming RbBCC

@ Ruby Association Activity Report
https://rubyassociation.doorkeeper.jp/events/107156

2cf373725ded741824c50fd571eda6e1?s=128

KONDO Uchio

July 17, 2020
Tweet

Transcript

  1. -JOVYͷτϨʔγϯάٕज़Λ
 $3VCZ͔Βར༻͢Δ؀ڥͷ੔උ 6DIJP,POEP(.01FQBCP *OD !3VCZ"TTPDJBUJPO"DUJWJUZ3FQPSU 1SPHSBNNJOH3C#$$

  2. େࣄͳ͓஌Βͤ

  3. 3C#$$ຊ೔ϦϦʔε 3C#$$͸ 3VCZͰ͸ಈ͖·ͤΜ pEEMF** charܕʹͳ͍ͬͯΔҾ਺ʹ ۭจࣈΛ౉͢ͱɺ͸0,ɺ͸4&(7

  4. wۙ౻Ӊஐ࿕,POEP6DIJP w(.0ϖύϘٕज़ج൫νʔϜ wຊۀ%VPMJOHPͱ0WFSDPPLFE wझຯ-JOVYɺ$POUBJOFSTɺγεϓϩ w3VCZ,BJHJ  

  5. ΞδΣϯμ wF#1'ͱ3C#$$ͷ঺հʢdNʣ wຊॿ੒ʹΑΔ੒Ռ෺ͷ঺հʢdNʣ w؆୯ͳ3C#$$ͷϥΠϒίʔσΟϯάʢNdʣ w·ͱΊɺࠓޙʢdNʣ

  6. F#1'ͷ࿩

  7. F#1'ͱ͸ w#FSLFMFZ1BDLFU'JMUFS wຊདྷ͸ɺύέοτϑΟϧλͷͨΊͷΞϧΰϦζϜɾٕज़ͷ໊લ w೥ʹ-JOVYʹҠ২͞ΕɺMJCQDBQͷதͳͲͰར༻ wঃʑʹTFDDPNQ΍ɺΧʔωϧΠϕϯττϨʔεʹར༻͞ΕΔ

  8. Ͱ͖Δ͜ͱ wF#1'͸ɺಠࣗͷ໋ྩηοτΛ࣋ͭ7.ͱߟ͑ͯྑ͍ɻ wΧʔωϧͷதͰಈ͍ͯɺߴ଎ʹ༷ʑͳ΋ͷΛϑΟϧλϦϯά͢Δ wύέοτϑΟϧλʔʢUDQEVNQɺUDɺ9%1ʣ wγεςϜίʔϧͷϑΟϧλʔʢTFDDPNQʣ wΧʔωϧΠϕϯτͷϑΟϧλʔʢ#$$CQGUSBDFʣ wͦͷଞʢDHSPVQͷσόΠεΞΫηε੍ޚͰ࢖ͬͨΓʣ

  9. IUUQXXXCSFOEBOHSFHHDPNCMPHCQGQFSGPSNBODFUPPMTCPPLIUNM

  10. #$$ͱ͸ʁ wF#1'ͷϓϩάϥϜΛಈ͔͢ʹ͸ɺCQG  γεςϜίʔϧʹόΠτ ίʔυΛ౉͢ܗʹͳΔɻόΠτίʔυΛਓ͕ॻ͘ͷ͸೉͍͠ wͦ͜Ͱ#1'$PNQJMFS$PMMFDUJPO w$ϕʔεͷҰछͷ%4-ʴεΫϦϓτݴޠʢ1ZUIPOɺ-VBͷϥΠϒϥϦ ΛಉࠝʣͰF#1'ͷπʔϧΛॻ͘͜ͱ͕Ͱ͖Δ

  11. طଘٕज़ͱͷҧ͍ wطଘͷτϨʔγϯάٕज़͕͍͔ͭ͋͘Δ wTUSBDF HECQUSBDF  ϕʔεͷ΋ͷ͸ɺҰॠࢭΊͯݕࠪ͢ΔΞʔΩςΫνϟ ͳͷͰɺΦʔόʔϔου͕ແࢹͰ͖ͳ͍ϨϕϧʹͳΔ wQFSGجຊతʹ͸ूܭ͕ϢʔβϥϯυͳͷͰɺෛՙʹͳΔ͜ͱ͕͋Δ wTZUFNUBQ GUSBDFF#1'ͱಉ౳ͷιʔεΛ࢖͍ΠϕϯτΛऔΔɻͨͩɺ

    F#1'ͷ࣋ͭόϦσʔγϣϯʹΑΔ҆શੑɺΧʔωϧଆͰͷूܭʹΑΔߴ଎ੑ ͳͲ͸ϝϦοτ͔
  12. ൺֱਤ 5PPMT 3FMBUFETZTDBMMT 4JEF&⒎FDU /PUF gdb strace ptrace(2) େ ର৅ΛҰ࣌తʹࢭΊͯɺ


    ৘ใΛऔಘ͠࠶։͢Δ perf perf_event_open(2) தʙখ جຊతʹूܭ͔Βઌ͸
 Ϣʔβϥϯυ systemtap ftrace (kern module) (tracefs) தʙখ F#1'ΑΓݹΊͷΧʔωϧ
 Ͱ΋ར༻Մೳ bpftrace BCC bpf(2) perf_event_open(2) খ WBMJEBUPSɺ#1'NBQͳͲ
 ར༻ՄɺݴޠόΠϯσΟϯάଟ
  13. طଘٕज़ͱͷҧ͍  wF#1'ΧʔωϧͰϓϩάϥϜΛಈ͔͢࢓૊Έ wΧʔωϧͰϓϩάϥϜΛಈ͔͢ͱ͍͏ҙຯͰ͸ૉ௚ʹϞδϡʔϧΛॻ ͘͜ͱ΋Ͱ͖Δ wΧʔωϧϞδϡʔϧ͸౰વɺඇৗʹଟ͘ͷ͜ͱ͕Մೳ͕ͩɺόά΍
 ةݥͳίʔυ΋࣮ߦՄೳͰɺΧʔωϧύχοΫ౳ͷڪΕ͕͋Δ wF#1'ͷ࣮ߦػߏʹ͸WFSJpFS͕ଘࡏ͠ɺةݥͳίʔυΛݕ஌͢Δ ʢFHແݶϧʔϓʣ

  14. IUUQXXXCSFOEBOHSFHHDPNCMPHCQGBOFXUZQFPGTPGUXBSFIUNM

  15. F#1'ࣗମͷઆ໌ࢿྉʢࢀߟʣ wIUUQTTQFBLFSEFDLDPNDIJLVXBJUMFBSOFCQG

  16. Ϟνϕʔγϣϯ

  17. #$$ͱ͸ʢ࠶ܝʣ wF#1'ͷϓϩάϥϜΛಈ͔͢ʹ͸ɺCQG  γεςϜίʔϧʹόΠτ ίʔυΛ౉͢ܗʹͳΔɻόΠτίʔυΛਓ͕ॻ͘ͷ͸೉͍͠ wͦ͜Ͱ#1'$PNQJMFS$PMMFDUJPO w$ϕʔεͷҰछͷ%4-ʴεΫϦϓτݴޠʢ1ZUIPOɺ-VBͷϥΠϒϥϦ ΛಉࠝʣͰF#1'ͷπʔϧΛॻ͘͜ͱ͕Ͱ͖Δ

  18. ͑ͬ3VCZ͸

  19. ॻ͔͘͠ͳ͍ ʢ͍ͭͰʹษڧ͠Α͏ʣ

  20. F#1'Y3VCZͷϞνϕʔγϣϯ w3VCZΛಈ͔͢04ͱͯ͠ॏཁͳɺ-JOVYͷਐԽͷԸܙΛɺ3VCZ։ൃऀ ʢݴޠίΞ։ൃऀɺϢʔβ྆ํʣ͕ڗडͰ͖ΔΑ͏ʹ͍ͨ͠ w3C#$$Ͱɺ3VCZίΞ։ൃऀͷڞ௨ݴޠͰ͋Δ$ݴޠͱ3VCZͷ
 ஌͚ࣝͩͰෳࡶͳτϨʔγϯά͕Ͱ͖ΔΑ͏ʹͳΔ w%4-ͷΑ͏ͳ࢓૊Έͱ૊Έ߹ΘͤΔ͜ͱͰɺτϨʔγϯάΛ΋ͬͱ
 &OKPZBCMFͳ΋ͷʹͰ͖ͳ͍͔

  21. ੒Ռ

  22. ୡ੒ͨ͜͠ͱ w#$$ͷ1ZUIPO࣮૷Λ࣮༻ʹे෼ͳػೳʹ͍ͭͯ3VCZʹҠ২ͨ͠ wαϯϓϧϓϩάϥϜɺԿΑΓνϡʔτϦΞϧΛ࡞੒ͨ͠ w೔ຊޠ൛νϡʔτϦΞϧؚΉ w3C#$$Λར༻ͨ͠1P$Ϩϕϧͷ࣮ྫɾπʔϧΛ։ൃ

  23. #$$3C#$$ w#$$͸
 جຊతʹ
 MJCCDDͷ''*

  24. #$$3C#$$ w3VCZඪ४ͷ
 pEEMFͰ
 1ZUIPOͷ
 DUZQFTΛஔ׵

  25. pEEMFͷར༻ w3C#$$͸3VCZͷඪ४ϥΠϒϥϦͷΈͰಈ࡞͢Δ
 ʢ΋ͪΖΜMJCCDDTP͕ೖ͍ͬͯΔલఏͰ͸͋Δɻϔομ͸ෆཁʣ

  26. 1ZUIPO൛ͷϦϑΝϨϯεʹ͋Δؔ਺͸໢ཏ

  27. αϯϓϧ͍͔ͭ͘ɺνϡʔτϦΞϧ

  28. ೔ຊޠνϡʔτϦΞϧ

  29. 1ZUIPO൛ͱͷൺֱ wఏग़ͨ͠࠷ऴใࠂΛ͝ཡ͍ͩ͘͞

  30. ։ൃͨ͠πʔϧ#1'2- wCQGUSBDFͷ͋ͷݴޠͰ͸ͳ͘:".-3VCZͰτϨʔεͰ͖ΔίϚϯυ CQGUSBDF #1'2-3VCZ%4-

  31. ಈը

  32. ։ൃͨ͠πʔϧ3BDL&#1' w64%5ʢޙड़ʣΛར༻͠ɺ3BDL.JEEMFXBSFʹ1SPCFΛ࢓ࠐΈܭଌ
 ूܭ͢Δαϯϓϧ

  33. 3BDL&#1'ͷಈ࡞ݪཧ w੍ݶεϨουʹϦΫΤετͱ͍͏લఏ͕͋Δ

  34. ಈը

  35. 3C#$$ͷ ར༻ʹ͋ͨͬͯ

  36. ϙΠϯτ͍͔ͭ͘ wΠϕϯτιʔεͰओཁͳ΋ͷ͸ͭ͋Δɺ஌͓ͬͯ͘ wLQSPCFɺUSBDFQPJOUɺVQSPCFɺ64%5 wΠϯετʔϧखॱͳͲ͸(FUUJOH4UBSUFEͰ6CVOUVָ͕ wMJCCDDͷόʔδϣϯ͸ɹਪ঑0, wιϑτ΢ΣΞͷੑ্࣭ɺ୯७ʹ%PDLFSԽͮ͠Β͍ w݁ہ஌Γ͍ͨͷ͸ϗετ͕Ͳ͏ͳͬͯΔ͔ͩͬͨΓ͢ΔΜͰ

  37. LQSPCFLSFUQSPCF wΧʔωϧ಺෦ͷؔ਺Λ௚઀ѻ͏QSPCFɻ wόʔδϣϯͰΠϯλϑΣʔε͕มΘΔ͔΋͠Εͳ͍ɻ wLQSPCF͕ؔ਺Τϯλʔ࣌ɺLSFUQSPCF͕Ϧλʔϯ࣌ wͲͷΑ͏ͳLQSPCF͕Կʹ࢖ΘΕ͍ͯΔ͔͸αϯϓϧͰษڧ

  38. USBDFQPJOU w3VCZͷ5SBDF1PJOUͱ͸ҧ͏֓೦Ͱɺ-JOVYͷQSPCFͷ͜ͱ wΧʔωϧʹ੩తʹ૊Έࠐ·Εɺ໊લ΍Ҿ਺͸جຊతʹมΘΒͳ͍ wυΩϡϝϯτ͕ίϝϯτʹ͋Δ৔߹΋͋Δ wαϯϓϧͰͷ࢖ΘΕํΛݟΔ΄͏͕ૣ͍͜ͱ͕ଟ͍ wྫ wTZTDBMMTTZT@FOUFS@ cTZT@FYJU@ γεςϜίʔϧͷ௥͍͔͚ wSBOEPNVSBOEPN@SFBEVSBOEPN΁ͷಡΈऔΓ

    wTDIFETDIFE@QSPDFTT@FYJUϓϩηεͷऴྃͳͲ
  39. VQSPCFVSFUQSPCF wϢʔβϓϩάϥϜͷؔ਺ͳͲʹϑοΫͨ͠ΠϕϯτΛɺΧʔωϧͰ௥ ͍͔͚ΒΕΔػೳɻ wجຊతʹ͸FYQPSU͞ΕͯΔγϯϘϧΛQSPCF͢Δ wͪ͜Β΋VQSPCF͕ΤϯλʔɺVSFUQSPCF͕Ϧλʔϯ

  40. 64%5 wϢʔβϓϩάϥϜͷ೚ҙͷՕॴʹQSPCFΛຒΊࠐΉػೳɻ wͲ͜ʹຒΊࠐ·Ε͍ͯΔ͔͸&-'ϔομͰ֬ೝͰ͖Δɻ wτϨʔε༗ޮ࣌ʹॳΊͯτϨʔε໋ྩ͕ಈ࡞͠ɺීஈ͸OPQ໋ྩʹ ͳ͍ͬͯΔɻ͕ͨͬͯ͠ແޮ࣌͸Φʔόϔου͕ͳ͍ɻ

  41. 3VCZͷ64%5 w--enable-dtraceΦϓγϣϯΛ༗ޮʹͯ͠Ϗϧυ͢Ε͹༗ޮʹ wSCFOWͳΒɺ36#:@$0/'*(63&@0154؀ڥม਺Ͱࢦఆ wԿ͕ຒ·͍ͬͯΔ͔͸%5SBDFଆͷυΩϡϝϯτΛࢀর wTFFʮ3VCZͷ%5SBDFͷ঺հʯ w IUUQTNBHB[JOFSVCZJTUOFUBSUJDMFT4QFDJBMEUSBDFIUNM w 8JLJ΋IUUQTCVHTSVCZMBOHPSHQSPKFDUTSVCZXJLJ%5SBDF1SPCFT

  42. 3VCZͷ64%5

  43. ϥΠϒͰͷ πʔϧ࡞੒σϞ

  44. Ͳ͏΋ʂ VE[VSBͰ͢

  45. ࠓޙͷల๬ ʢ͕࣌ؒ͋Ε͹ʣ

  46. 3FE%BUB5PPMT࿈ܞ w۩ମతʹ͸ɺ$IBSUZͷσʔλߏ଄ʹɺ3C#$$ʹ͓͚Δ#1'NBQΛ දݱͨ͠ΫϥεΛରԠ͍ͤͨ͞ w$IBSUZ5BCMF"EBQUFST#$$తͳΞμϓλΛ࣮૷͢ΔͱΑ͍ w$IBSUZͷࢿ࢈Λͦͷ··࢖ͬͯʢFHVOJDPEF@QMPUSCʣ
 τϨʔε݁ՌͷՄࢹԽ͕Ͱ͖Δ

  47. ωοτϫʔΫτϨʔεपล wຊՈͷFYBNQMFTOFUXPSLJOH഑Լʹ͋ΔΑ͏ͳαϯϓϧͷҠ২ wগ͚ͩ͠։͍࢝ͯ͠Δ w9%1΋ྲྀߦͬͯΔͷͰ wط஌ͷ໰୊఺QZSPVUF૬౰ͷHFN͕3VCZʹͳ͍ͷͰɺҰ෦ͷαϯ ϓϧ͸؆୯ͳҠ২ͱ͍͏Θ͚ʹ͍͔ͣ೰·͍͠ɻ wOFUMJOLTPDLFUͱ͓͠Ό΂Γ͢ΔHFN͕ཉ͍͠ɻ

  48. ΋ͬͱকདྷVQTUSFBN΁ͷߩݙ wকདྷ͸JPWJTPSϓϩδΣΫτʹدଃ͠ɺ
 #$$։ൃίΞͱาௐΛ߹ΘͤΔͳͲ͍ͨ͠ wͦͷલʹ඼࣭Λ্͍͛ͨʢݴ͍༁ʣ wͲ͏͍͏खଓ͖ΛͱΕ͹͍͍ͷͩΖ͏ʁ w͜ͷࢿྉΛݟͨํͰॿݴ͕͋Ε͹ͱࢥ͍·͢

  49. ँࣙ

  50. ँࣙ wϝϯλʔͷ࡫ాߞҰ͞Μ w͘͞ΒΠϯλʔωοτͷদຊ྄հ͞Μɺ۝भେֶ৘ใج൫ݚڀ։ൃ ηϯλʔͷౢ٢ོ෉ઌੜɺּݪٛߊઌੜ wಛʹɺ#1'2-͸ౢ٢ઌੜͷΞυόΠεΛԼෑ͖ʹ͍ͯ͠·͢

  51. &OKPZ 5SBDJOH