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

カスタムInstrumentsでアプリをピカピカに!

Chiharu Nameki
September 07, 2019

 カスタムInstrumentsでアプリをピカピカに!

Instrumentsの基本
OSSignposts
カスタムInstrumentsの作成
活用事例
CLIPSによるModelerの自作

Sample Code
https://github.com/Ridwy/iosdc19-custom-instruments

Chiharu Nameki

September 07, 2019
Tweet

More Decks by Chiharu Nameki

Other Decks in Technology

Transcript

  1. ߦ໦ ઍय़ʢͳΊ͖ ͪ͸Δʣ
    Twitter, Qiita, GitHub @Ridwy
    גࣜձࣾαΠόʔΤʔδΣϯτ
    ΧελϜInstrumentsͰ
    ΞϓϦΛϐΧϐΧʹʂ
    iOSDC Japan 2019
    Sep. 7

    View full-size slide

  2. Agenda
    • Instrumentsͷجຊ
    • OSSignposts
    • ΧελϜInstrumentsͷ࡞੒
    • ׆༻ࣄྫ
    • CLIPSʹΑΔModelerͷࣗ࡞

    View full-size slide

  3. ύϑΥʔϚϯεͳͲͷ඼࣭վળʹ໾ཱͭ
    ࣮ߦ࣌ʹ͞·͟·ͳ৘ใΛऩू͠
    ෼ੳɾՄࢹԽͯ͘͠ΕΔπʔϧ

    View full-size slide

  4. Xcodeʹ૊Έࠐ·Ε͍ͯΔ
    ܭଌର৅ʹΞϓϦ͕ηοτ͞Εͨঢ়ଶͰىಈ
    Product > Profile

    View full-size slide

  5. ୯ಠͰ΋ىಈͰ͖Δ

    View full-size slide

  6. جຊͷ࢖͍ํ

    View full-size slide

  7. ςϯϓϨʔτΛબ୒ͯ͠Choose !

    View full-size slide

  8. ݁ՌΛݟͯίʔυΛվળ

    View full-size slide

  9. Instruments ͱ͍͏୯ޠ͸
    2ͭͷҙຯͰ࢖ΘΕ͍ͯ·͢
    ͜͜Ͱͪΐͬͱ஫ҙ

    View full-size slide

  10. Instruments.app

    View full-size slide

  11. ֤छͷ෼ੳΛߦ͏πʔϧ
    Drag & Drop
    Ͱ௥Ճʂ
    Instruments
    ϥΠϒϥϦ

    View full-size slide

  12. ը໘ߏ੒
    Track Area
    Detail Area
    Extended
    Detail Area
    Track (=࣌ܥྻͷάϥϑ) ͕ฒͿ

    View full-size slide

  13. Instrument Track
    graph
    lane
    lane
    άϥϑ͕ෳ਺͋Δͱ͖͸
    ͜͜Ͱ੾Γସ͑

    View full-size slide

  14. Leaks
    Standard ςϯϓϨʔτ ❌ϝϞϦ࢖༻ྔ͕ӈݞ্͕Γ
    ❌ϦʔΫʂ

    View full-size slide

  15. Time Profiler
    Standard ςϯϓϨʔτ CPU࢖༻཰ΛՄࢹԽ
    ࣌ؒͷ͔͔Δؔ਺ͷಛఆʹ
    Application status΋දࣔ͞ΕΔ
    Backgroundதͷڍಈ΋֬ೝ͠΍͍͢

    View full-size slide

  16. ίΞΛޮ཰Α͘
    ࢖͍͑ͯΔ͔ʁ
    ؔ਺ͷ࣮ߦʹ͔͔ͬͨ࣌ؒ

    View full-size slide

  17. AVPlayerItemOutputPullDelegate outputSequenceWasFlushed(_:)
    ಈըͷը͕Ͱ͖ͨΒݺ͹ΕΔ = ܁Γฦ࣮͠ߦ͞ΕΔՕॴ
    [AVVideoAsset minFrameDuration]
    1ϑϨʔϜ͕Կඵ͔
    1ճ͋ͨΓ͸େͨ͜͠ͱͳ͍͕
    ਖੵͰҙ֎ͱ͕͔͔͍࣌ؒͬͯΔ
    → ϧʔϓͷ֎ʹग़ͦ͏ʂ

    View full-size slide

  18. Energy Log
    Standard ςϯϓϨʔτ ֤ϋʔυ΢ΣΞͷঢ়ଶ
    ΧλϩάతͳςϯϓϨʔτʁ

    View full-size slide

  19. ΧελϜςϯϓϨʔτ
    ݱࡏͷ૊Έ߹ΘͤΛΧελϜςϯϓϨʔτͱͯ͠ॻ͖ग़ͤΔ
    Hoge.tracetemplate
    File > Save As Template…
    อଘ৔ॴ
    ~/Library/Application Support/Instruments/Templates
    ͜͜ʹஔ͘ͱςϯϓϨʔτબ୒ը໘ʹݱΕΔ
    μϒϧΫϦοΫͰ΋ىಈ

    View full-size slide

  20. ϐΧϐΧʹ͠Α͏ʂ
    جຊฤ ͜͜·Ͱ

    View full-size slide

  21. ԿΛ͚ͨ࣌ͩͬ͠…ʁʁ
    ͲΜͳૢ࡞Λͯ͠ɺը໘͸Ͳ͏͔ͩͬͨ?
    ޙ͔ΒݟΔͱ…

    View full-size slide

  22. Command Line࣮ߦ
    ޙ͔Β݁ՌΛΈΔέʔε ̍
    $instruments -t "Allocations" -l 10000 -D SaveFileName.trace PathToYourApp
    ςϯϓϨʔτ ه࿥࣌ؒ(ϛϦඵ)
    อଘઌ ଌఆର৅

    View full-size slide

  23. Deferred Recording Mode
    ޙ͔Β݁ՌΛΈΔέʔε ̎
    Instrumentsࣗମͷಈ࡞ʹΑΔӨڹΛ
    ࠷௿ݶʹ཈͑ΔͨΊ෼ੳΛ஗Ԇ࣮ߦͰ͖Δ
    or File > Recording Options…

    View full-size slide

  24. OSSignposts
    ʮίʔυ͕ԿΛ͍ͯ͠Δॴ͔ʯΛ
    Instrumentsʹ఻͑Α͏

    View full-size slide

  25. Point
    os_signpost(.event, log: logHandle, name: "Seek","to: %f", t)
    os_signpost()ΛίʔυʹຒΊࠐΉ
    Կ͕ൃੜͨ͠ͷ͔ʁΛૹΔ

    View full-size slide

  26. let spid = OSSignpostID(log: logHandle)
    os_signpost(.begin, log: logHandle, name: "Scene Detection”,
    signpostID: spid, "url: %{public}s", urlString)
    os_signpost(.end, log: logHandle, name: "Scene Detection”,
    signpostID: spid, "count: %d", sceneCount)
    detector.start(url: url) {
    }
    // ඇಉظॲཧ
    • .beginͱ.endͰғΉ
    • ରԠؔ܎͸ಉ͡OSSignpostIDΛ౉͢͜ͱͰ୲อ
    Interval
    os_signpost()ΛίʔυʹຒΊࠐΉ

    View full-size slide

  27. ϨίʔσΟϯάதͰͳ͍ͱ͖ͷ
    ίʔυͷ࣮ߦʹΠϯύΫτΛ༩͑ͳ͍Α͏ʹ஫ҙ
    os_signpost(.event, log: logHandle, name: “Seek”,
    "to: %f", marker.startTime.seconds)
    NG
    ͕͜͜ධՁ͞Εͯ͠·͏
    if OSLogHandle.pointsOfInterest.signpostsEnabled {
    let seekTime = marker.startTime.seconds
    os_signpost(.event, log: logHandle, name: “Seek",
    “to: %f", seekTime)
    }
    // ϨίʔσΟϯάதͷΈ࣮ߦ͞ΕΔ
    OK

    View full-size slide

  28. ϝοηʔδ΋දࣔ͞ΕΔ
    Instrument ͷ os_signpost ΍
    Points of Interest ʹදࣔ͞ΕΔ

    View full-size slide

  29. • άϥϑͷ৭, Ϧετͷ಺༰, etc.
    • Signposts͸ڞ௨ͷϦιʔεͳͷͰɺࣗ෼͕௥Ճͨ͠΋ͷ

    Ҏ֎΋ग़ͯ͘Δ
    ͖ͬ͞௥Ճͨ͠ͷɺͲΕ?

    ͍Ζ͍Ζɺݟ΍ͨ͘͘͢͠ͳͬͯ͘Δ

    શ෦੨͍…

    View full-size slide

  30. ΧελϜInstruments

    View full-size slide

  31. Instruments Architecture
    Data Stream Table Modeler Table Standard UI
    Signposts, ktraceͳͲͷσʔλͷιʔε
    Data Stream
    Table σʔλͷೖΕ෺ɼܕ͸εΩʔϚͰఆٛ
    Modeler ೖྗσʔλΛධՁͯ͠ग़ྗσʔλΛੜ੒
    Standard UI InstrumentsΞϓϦͷUI

    View full-size slide

  32. Instruments Architecture
    Dynamic Track-wide Binding
    1. InstrumentsʹඞཁͳςʔϒϧΛ༻ҙ
    2.ͦͷςʔϒϧͷεΩʔϚͷσʔλΛੜ੒Ͱ͖Δ

    Modeler / Data StreamΛ୳ͯ͠όΠϯσΟϯά
    ޮ཰ԽͷͨΊɺಉ͡಺༰ͷςʔϒϧ͸ڞ༗͢Δ

    View full-size slide

  33. ΧελϜInstrumentsΛ࡞Δ
    InstrumentsͱඞཁͳModeler, εΩʔϚͳͲΛؚΉ

    ύοέʔδΛ࡞Δ
    =

    View full-size slide

  34. ࡞੒खॱ Xcode Ͱ File > New > Project…
    macOS಺ͷ Instruments Package Λબ୒

    View full-size slide

  35. instrpkgϑΝΠϧʹXMLͰ

    εΩʔϚ΍Modeler, InstrumentsͳͲΛهड़
    Snippet͕ॆ࣮ʂ

    View full-size slide

  36. • Run → σόοάϞʔυͰInstruments͕ىಈ
    • Archive → ഑෍༻ύοέʔδΛੜ੒
    ActionLogs.instrdst
    ར༻࣌͸͜ΕΛ
    μϒϧΫϦοΫͯ͠Πϯετʔϧ

    View full-size slide

  37. ΠϯετʔϧࡁΈͷύοέʔδ͸
    ؀ڥઃఆͷPackagesλϒͰ֬ೝͰ͖Δ

    View full-size slide

  38. XMLཁૉͷϦϑΝϨϯε
    Instruments Developer Help
    Package Definition Reference
    Engineering TypeʢΧϥϜͷσʔλछผʣͷϦετ΋ͪ͜Βʂ

    View full-size slide

  39. εΩʔϚ




    εΩʔϚ





    Instruments Package
    ͷߏ੒ྫ

    View full-size slide

  40. εΩʔϚΛهड़͢ΔͨΊͷXMLཁૉ
    XML Element
    Automatic
    Modeler
    Memo



    ○ Xcode 11~

    Automatic Modeler = ModelerΛࣗಈੜ੒ͯ͘͠ΕΔػೳ
    os_signpost΍os_log͔Βఆٛ͞ΕͨεΩʔϚʹม׵ʂ

    View full-size slide

  41. εΩʔϚ Ұཡ
    Instrument > Instrument Inspector Schemasλϒ
    100+ Built-in Schemas !

    View full-size slide

  42. طଘεΩʔϚͷར༻ํ๏
    os-signpost
    ඞཁͳΒBuild SettingsͰύοέʔδΛϦϯΫ

    View full-size slide



  43. jp.co.chiharu-nameki.ScenePlayerBehavior
    ScenePlayerBehavior

    Chiharu Nameki

    os-signpost

    scene-detection
    Scene Detection
    "jp.co.chiharu-nameki.ScenePlayer"
    "Behavior"
    "Scene Detection"

    "url: " ?url


    "count: " ?count


    url
    Video URL
    string
    ?url


    scene-count
    Scene Count
    uint32
    ?count


    result-color
    Color
    event-concept
    (if (= ?count 0) then "Red" else "Green")



    jp.co.chiharu-nameki.ScenePlayerBehavior.ScenePlayerBehavior
    ScenePlayer Behavior
    Behavior
    Visualize what's happen in ScenePlayer app
    Points of Interest

    user-actions
    os-signpost

    subsystem
    jp.co.chiharu-nameki.ScenePlayer


    category
    UserAction



    scene-detections
    scene-detection


    ScenePlayer Behavior

    User Actions
    user-actions

    name



    Scene Detection
    scene-detections

    url
    result-color




    User Actions
    user-actions
    time
    name
    message


    Scene Detection
    scene-detections
    start
    duration
    url
    scene-count



    ScenePlayerBehavior.tracetemplate


    ←116ߦ
    ScenePlayerBehavior.instrpkg

    View full-size slide

  44. API௨৴ͷՄࢹԽ
    ϓϩμΫτͰͷ׆༻ࣄྫ ̍
    ޮ཰ͷѱ͍ϦΫΤετͷ࢓ํΛ͍ͯ͠ͳ͍͔ʁ

    View full-size slide

  45. Ϣʔβʔͷߦಈϩάͷ࣮૷֬ೝ
    ϓϩμΫτͰͷ׆༻ࣄྫ ̎
    ՄࢹԽػೳʹண໨
    λΠϛϯά΍಺༰͕ਖ਼͍͔͠νΣοΫ

    View full-size slide

  46. ΋ͬͱݡ͘͠Α͏ʂ
    ΧελϜModeler

    View full-size slide

  47. A Tool for Building Expert Systems
    www.clipsrules.net

    View full-size slide

  48. Expert System
    ઐ໳Ոͷ൑அೳྗΛΤϛϡϨʔτ͢Δ΋ͷ
    ࣗಈి࿩Ԡ౴ɺੲͳ͕ΒͷAIʢ͍ΘΏΔਓ޻ແ೴ʣͳͲʹԠ༻
    ൃੜͨ͠ࣄ࣮ʢfactʣΛϧʔϧʹैͬͯॲཧ
    Working memory
    fact
    f-2
    Rule B
    Rule A
    fact
    f-1
    fact
    f-3

    View full-size slide

  49. CLIPS
    ࣜ͸()ͰғΉ ( ࣜ )
    ม਺ ?hoge
    ԋࢉࢠ͸લஔ͖
    (+ ?a ?b)
    (> ?t1 ?t2)
    factૢ࡞
    ; ௥Ճ
    (assert hello)
    ; ࡟আ
    (retract ?hoge)
    ; มߋ
    (modify ?hoge (fuga 123))

    View full-size slide

  50. ϧʔϧΛఆٛ
    (defrule rule1
    (car_problem (name ignition_key) (status on))
    (car_problem (name engine) (status wont_start))
    =>
    (assert (car_problem (name starter) (status faulty)))
    )
    (pattern 1)
    (pattern 2)

    (pattern N)
    (action 1)

    (action M)
    =>
    શͯͷύλʔϯʹϚονͨ͠Β
    ΞΫγϣϯΛ࣮ߦ

    View full-size slide

  51. ۩ମྫ
    ߦಈϩάͷ࣮૷ϛεΛݕ஌ͤ͞Δ
    • λοϓͷϩάʹ͸Page IDʢͲͷը໘Ͱߦͳ͔ͬͨʣͷ৘ใؚ͕·ΕΔ
    • Page ID͸දࣔதͷը໘ͱಉ͡Ͱ͋Δ΂͖

    View full-size slide

  52. ཁૉʹೖग़ྗͷεΩʔϚͱCLIPSͷϑΝΠϧ΁ͷύεΛهड़

    View full-size slide

  53. page-id-validator.clp શจ
    ϧʔϧΛهड़

    View full-size slide

  54. ݕग़͞Εͨʂ

    View full-size slide

  55. Recap
    • Instrumentsͷجຊ
    • OSSignposts
    • ΧελϜInstrumentsͷ࡞੒
    • ׆༻ࣄྫ
    • CLIPSʹΑΔModelerͷࣗ࡞

    View full-size slide

  56. Sample Code
    https://github.com/Ridwy/iosdc19-custom-instruments
    ActionLogs
    ScenePlayer.app
    w/ Instrument
    Custom Modeler Sample

    View full-size slide

  57. Getting Started with Instruments WWDC19, 411
    Instruments֓ཁ, Time ProfilerͷσϞ, Signpostsͷ঺հ, XCTestͰͷར༻ྫ
    Measuring Performance Using Logging WWDC18, 405
    Signposts APIৄࡉ
    Developing a Great Profiling Experience
    Telling your story with Custom Instruments
    WWDC19, 414
    SignpostsʹΑΔσʔλऩूͷϕετϓϥΫςΟε, ΧελϜInstruments֓ཁ, ৘ใͷՄࢹԽ
    Creating Custom Instruments WWDC18, 410
    InstrumentsͷΞʔΩςΫνϟ, ΧελϜInstrumentsͷ࡞੒
    CLIPS User’s Guide www.clipsrules.net
    CLIPSݴޠͷجຊతͳ࢖͍ํͱγϯλοΫε
    Modeling in Custom Instruments WWDC19, 421
    CLIPSʹΑΔModelerͷ࡞੒
    ࢀߟࢿྉ ↓ ্͔ΒॱʹݟΔͱཧղ͠΍͍͢ͱࢥ͍·͢

    View full-size slide

  58. Instruments Help
    جຊͷ࢖͍ํ
    Instruments Developer Help
    ύοέʔδͷXMLཁૉ, Engineering TypeҰཡ
    ࢀߟࢿྉ

    View full-size slide

  59. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide