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

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

4ef794bdea63fc6153845bb26bac38a2?s=47 Chiharu Nameki
September 07, 2019

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

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

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

4ef794bdea63fc6153845bb26bac38a2?s=128

Chiharu Nameki

September 07, 2019
Tweet

Transcript

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

    iOSDC Japan 2019 Sep. 7
  2. Instruments

  3. Agenda • Instrumentsͷجຊ • OSSignposts • ΧελϜInstrumentsͷ࡞੒ • ׆༻ࣄྫ •

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

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

  6. ୯ಠͰ΋ىಈͰ͖Δ

  7. جຊͷ࢖͍ํ

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

  9. ϝΠϯը໘

  10. Record !

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

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

  13. Instruments.app

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

  15. ը໘ߏ੒

  16. ը໘ߏ੒ Track Area Detail Area Extended Detail Area Track (=࣌ܥྻͷάϥϑ)

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

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

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

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

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

    → ϧʔϓͷ֎ʹग़ͦ͏ʂ
  22. Energy Log Standard ςϯϓϨʔτ ֤ϋʔυ΢ΣΞͷঢ়ଶ ΧλϩάతͳςϯϓϨʔτʁ

  23. ΧελϜςϯϓϨʔτ ݱࡏͷ૊Έ߹ΘͤΛΧελϜςϯϓϨʔτͱͯ͠ॻ͖ग़ͤΔ Hoge.tracetemplate File > Save As Template… อଘ৔ॴ ~/Library/Application

    Support/Instruments/Templates ͜͜ʹஔ͘ͱςϯϓϨʔτબ୒ը໘ʹݱΕΔ μϒϧΫϦοΫͰ΋ىಈ
  24. ϐΧϐΧʹ͠Α͏ʂ جຊฤ ͜͜·Ͱ

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

  27. Command Line࣮ߦ ޙ͔Β݁ՌΛΈΔέʔε ̍ $instruments -t "Allocations" -l 10000 -D

    SaveFileName.trace PathToYourApp ςϯϓϨʔτ ه࿥࣌ؒ(ϛϦඵ) อଘઌ ଌఆର৅
  28. Deferred Recording Mode ޙ͔Β݁ՌΛΈΔέʔε ̎ Instrumentsࣗମͷಈ࡞ʹΑΔӨڹΛ ࠷௿ݶʹ཈͑ΔͨΊ෼ੳΛ஗Ԇ࣮ߦͰ͖Δ or File >

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

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

  31. 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()ΛίʔυʹຒΊࠐΉ
  32. ϨίʔσΟϯάதͰͳ͍ͱ͖ͷ ίʔυͷ࣮ߦʹΠϯύΫτΛ༩͑ͳ͍Α͏ʹ஫ҙ 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
  33. ϝοηʔδ΋දࣔ͞ΕΔ Instrument ͷ os_signpost ΍ Points of Interest ʹදࣔ͞ΕΔ

  34. • άϥϑͷ৭, Ϧετͷ಺༰, etc. • Signposts͸ڞ௨ͷϦιʔεͳͷͰɺࣗ෼͕௥Ճͨ͠΋ͷ
 Ҏ֎΋ग़ͯ͘Δ ͖ͬ͞௥Ճͨ͠ͷɺͲΕ? ͍Ζ͍Ζɺݟ΍ͨ͘͘͢͠ͳͬͯ͘Δ શ෦੨͍…

  35. ΧελϜInstruments

  36. Instruments Architecture Data Stream Table Modeler Table Standard UI Signposts,

    ktraceͳͲͷσʔλͷιʔε Data Stream Table σʔλͷೖΕ෺ɼܕ͸εΩʔϚͰఆٛ Modeler ೖྗσʔλΛධՁͯ͠ग़ྗσʔλΛੜ੒ Standard UI InstrumentsΞϓϦͷUI
  37. Instruments Architecture Dynamic Track-wide Binding 1. InstrumentsʹඞཁͳςʔϒϧΛ༻ҙ 2.ͦͷςʔϒϧͷεΩʔϚͷσʔλΛੜ੒Ͱ͖Δ
 Modeler /

    Data StreamΛ୳ͯ͠όΠϯσΟϯά ޮ཰ԽͷͨΊɺಉ͡಺༰ͷςʔϒϧ͸ڞ༗͢Δ
  38. ΧελϜInstrumentsΛ࡞Δ InstrumentsͱඞཁͳModeler, εΩʔϚͳͲΛؚΉ
 ύοέʔδΛ࡞Δ =

  39. ࡞੒खॱ Xcode Ͱ File > New > Project… macOS಺ͷ Instruments

    Package Λબ୒
  40. instrpkgϑΝΠϧʹXMLͰ
 εΩʔϚ΍Modeler, InstrumentsͳͲΛهड़ Snippet͕ॆ࣮ʂ

  41. • Run → σόοάϞʔυͰInstruments͕ىಈ • Archive → ഑෍༻ύοέʔδΛੜ੒ ActionLogs.instrdst ར༻࣌͸͜ΕΛ

    μϒϧΫϦοΫͯ͠Πϯετʔϧ
  42. ΠϯετʔϧࡁΈͷύοέʔδ͸ ؀ڥઃఆͷPackagesλϒͰ֬ೝͰ͖Δ

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

  44. εΩʔϚ <instruments> <create-table> <graph> <lane> εΩʔϚ <create-table> <list> <package> <lane>

    <list> Instruments Package ͷߏ੒ྫ
  45. εΩʔϚΛهड़͢ΔͨΊͷXMLཁૉ XML Element Automatic Modeler Memo <point-schema> <interval-schema> <os-log-point-schema> ◦

    <os-signpost-point-schema> ◦ Xcode 11~ <os-signpost-interval-schema> ◦ Automatic Modeler = ModelerΛࣗಈੜ੒ͯ͘͠ΕΔػೳ os_signpost΍os_log͔Βఆٛ͞ΕͨεΩʔϚʹม׵ʂ
  46. εΩʔϚ Ұཡ Instrument > Instrument Inspector Schemasλϒ 100+ Built-in Schemas

    !
  47. طଘεΩʔϚͷར༻ํ๏ <import-schema>os-signpost</import-schema> ඞཁͳΒBuild SettingsͰύοέʔδΛϦϯΫ

  48. <?xml version="1.0" encoding="UTF-8" ?> <package> <id>jp.co.chiharu-nameki.ScenePlayerBehavior</id> <title>ScenePlayerBehavior</title> <owner> <name>Chiharu Nameki</name>

    </owner> <import-schema>os-signpost</import-schema> <os-signpost-interval-schema> <id>scene-detection</id> <title>Scene Detection</title> <subsystem>"jp.co.chiharu-nameki.ScenePlayer"</subsystem> <category>"Behavior"</category> <name>"Scene Detection"</name> <start-pattern> <message>"url: " ?url</message> </start-pattern> <end-pattern> <message>"count: " ?count</message> </end-pattern> <column> <mnemonic>url</mnemonic> <title>Video URL</title> <type>string</type> <expression>?url</expression> </column> <column> <mnemonic>scene-count</mnemonic> <title>Scene Count</title> <type>uint32</type> <expression>?count</expression> </column> <column> <mnemonic>result-color</mnemonic> <title>Color</title> <type>event-concept</type> <expression>(if (= ?count 0) then "Red" else "Green")</expression> </column> </os-signpost-interval-schema> <instrument> <id>jp.co.chiharu-nameki.ScenePlayerBehavior.ScenePlayerBehavior</id> <title>ScenePlayer Behavior</title> <category>Behavior</category> <purpose>Visualize what's happen in ScenePlayer app</purpose> <icon>Points of Interest</icon> <create-table> <id>user-actions</id> <schema-ref>os-signpost</schema-ref> <attribute> <name>subsystem</name> <string>jp.co.chiharu-nameki.ScenePlayer</string> </attribute> <attribute> <name>category</name> <string>UserAction</string> </attribute> </create-table> <create-table> <id>scene-detections</id> <schema-ref>scene-detection</schema-ref> </create-table> <graph> <title>ScenePlayer Behavior</title> <lane> <title>User Actions</title> <table-ref>user-actions</table-ref> <plot> <value-from>name</value-from> </plot> </lane> <lane> <title>Scene Detection</title> <table-ref>scene-detections</table-ref> <plot> <value-from>url</value-from> <color-from>result-color</color-from> </plot> </lane> </graph> <list> <title>User Actions</title> <table-ref>user-actions</table-ref> <column>time</column> <column>name</column> <column>message</column> </list> <list> <title>Scene Detection</title> <table-ref>scene-detections</table-ref> <column>start</column> <column>duration</column> <column>url</column> <column>scene-count</column> </list> </instrument> <template> <import-from-file>ScenePlayerBehavior.tracetemplate</import-from-file> </template> </package> ←116ߦ ScenePlayerBehavior.instrpkg
  49. None
  50. API௨৴ͷՄࢹԽ ϓϩμΫτͰͷ׆༻ࣄྫ ̍ ޮ཰ͷѱ͍ϦΫΤετͷ࢓ํΛ͍ͯ͠ͳ͍͔ʁ

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

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

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

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

    B Rule A fact f-1 fact f-3
  55. CLIPS ࣜ͸()ͰғΉ ( ࣜ ) ม਺ ?hoge ԋࢉࢠ͸લஔ͖ (+ ?a

    ?b) (> ?t1 ?t2) factૢ࡞ ; ௥Ճ (assert hello) ; ࡟আ (retract ?hoge) ; มߋ (modify ?hoge (fuga 123))
  56. ϧʔϧΛఆٛ (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) => શͯͷύλʔϯʹϚονͨ͠Β ΞΫγϣϯΛ࣮ߦ
  57. ۩ମྫ ߦಈϩάͷ࣮૷ϛεΛݕ஌ͤ͞Δ • λοϓͷϩάʹ͸Page IDʢͲͷը໘Ͱߦͳ͔ͬͨʣͷ৘ใؚ͕·ΕΔ • Page ID͸දࣔதͷը໘ͱಉ͡Ͱ͋Δ΂͖

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

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

  60. ݕग़͞Εͨʂ

  61. Recap • Instrumentsͷجຊ • OSSignposts • ΧελϜInstrumentsͷ࡞੒ • ׆༻ࣄྫ •

    CLIPSʹΑΔModelerͷࣗ࡞
  62. Sample Code https://github.com/Ridwy/iosdc19-custom-instruments ActionLogs ScenePlayer.app w/ Instrument Custom Modeler Sample

  63. 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ͷ࡞੒ ࢀߟࢿྉ ↓ ্͔ΒॱʹݟΔͱཧղ͠΍͍͢ͱࢥ͍·͢
  64. Instruments Help جຊͷ࢖͍ํ Instruments Developer Help ύοέʔδͷXMLཁૉ, Engineering TypeҰཡ ࢀߟࢿྉ

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