Upgrade to Pro — share decks privately, control downloads, hide ads and more …

なんかトレースするはなし

 なんかトレースするはなし

9361878d459f1709feec780518946ee5?s=128

NARUSE, Yui

July 02, 2016
Tweet

More Decks by NARUSE, Yui

Other Decks in Programming

Transcript

  1. ͳΜ͔τϨʔε͢ Δ࿩ naruse GitHub: nurse Twitter: @nalsh

  2. ಥવͷো֐

  3. γνϡΤʔγϣϯ • ͳΜ͔͏·͘ಈ͔ͳ͍ • Ͳ͏͠Α͏

  4. ps -eFlL جຊฤ • -e: Select all processes. • -l:

    Long Format. The -y option is often useful with this. • -y Do not show flags; show rss in place of addr. • -F: Extra full format. See the -f option, which -F implies. • -f: When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added • ར఺ • ಛݖ͕͍Βͳ͍ • ର৅ϓϩηεʹ෭࡞༻͕ແ͍
  5. PS PID:14079ͷϝΠϯεϨου͕๩͘͠࢓ࣄ͍ͯ͠Δ͜ͱ͕Θ͔Δ

  6. perf top • ΊͬͪΌศར • ಈ͍͍ͯΔͱ͖ʹ͸ ༗ޮ • Կ͔Λ଴ͬͯΔͱ͖ ʹ͸Θ͔Βͳ͍

    • RHEL5ʹ͸·ͩͳ͍ • ಛݖ͕ඞཁ
  7. PROC - PROCESS INFORMATION PSEUDO-FILESYSTEM procfs(5) • ͍Ζ͍ΖΘ͔ΔɻҰԡ͠͸ stat (30)

    kstkeip %lu The current EIP (instruction pointer). ࣮ߦதͷ໋ྩͷΞυϨε͸ 140308168160605 = 0x7f9c0a85b55d
  8. procfs • /proc/<pid>/maps ΛಡΜͰͲͷϥΠϒϥϦͷൣғ͔ௐ΂Δ • Φϑηοτͱ͔ߟ͑ͯϝϞϦΞυϨεΛϥΠϒϥϦ಺ͰͷΞυϨεʹ ม׵͢Δ • 0x7f9c0a85b55d -

    0x7f9c0a84b000 = 0x1055d • γϯϘϧςʔϒϧΛோΊͯಛఆʂ • (addr2lineΛ࢖ͬͯखൈ͖ͯ͠΋Α͍)
  9. procfs • ͱ͍͏ͷΛ΍Δ΍ͭ • https://gist.github.com/nurse/0619b6af90df140508c2 • ࠷ۙͷUbuntuͷ৔߹ɺಉҰϢʔβʔͰ΋ಛݖ͕ඞཁ • gdbʹΞλονͰ͖ͳ͍ͱ͖
 ʹΧʔωϧ಺Ͱ͍ࢗͬͯ͞Δͱ͖


    ʹ͖͜͞͞Μ͕ѱ͍ͱ͖
 ͦΜͳͱ͖Ͱ΋৘ใ͕ಘΒΕΔͷ͕Α͍ • ΋ͪΖΜϢʔβʔϥϯυΛ࣮ߦதͰ΋Θ͔Δ • ΠϯετʔϧෆཁͳͷͰ͓٬͞Μͱ͔ʹࢼͯ͠΋Β͍΍͍͢
  10. • όοΫτϨʔε΋ݟ͍ͨ • ͦΜͳ΋ͷ͸ʢprocfsʹ͸ʣͳ͍ • perf_event_open(2) • sample_type=PERF_SAMPLE_CALLCHAINΛࢦఆ͢Ε͹औΕ Δؾ΋͢Δ……? •

    ͨͩ͠CͷελοΫτϨʔε͚ͩ • ptrace(2) • ϓϩηεʹγάφϧૹΔͷ͕ؾʹͳΔ • gcore(1)ͰίΞు͔ͤͯgdbͰͬ͘͡ΓΈΔͷ΋Α͍ • ͱ͔͔ͬΓͱͳΔγϯϘϧ͑͋͞Ε͹ɺʢRubyϨϕϧͷόο ΫτϨʔεͰ͋Ζ͏ͱʣͳΜͩͬͯΘ͔ΔͷͰ͕Μ͹͍ͬͯ͘
  11. Ruby༻.gdbinit ͕Μ͹ͬͨ݁Ռ ײ૝ • ஗͍ɻόοΫτϨʔε͘Β͍ ͳΒ໰୊ͳ͍͕ɺRubyΦϒ δΣΫτΛछྨผʹ਺͑Δͱ ͔͢Δͱ΄΅ۭͬΆͰ΋਺ඵ ͔͔ΔʢˡPythonͰॻ͚ʣ •

    Rubyຊମ͕มΘΔ౓ʹ௥ै ͢Δͷ͕ͭΒͦ͏ • Ͱ΋ɺcoreͰ΋ಡΊΔͷ͸ศ རͦ͏