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

Measuring Performance Using Logging / 20180619 #roppongiswift

Measuring Performance Using Logging / 20180619 #roppongiswift

ROPPONGI.swift 第4回 WWDC振り返り会(VISITS・Origami共催) - connpass
https://visits.connpass.com/event/90254/
の発表資料です。

# 参考リンク

Measuring Performance Using Logging - WWDC 2018 - Videos - Apple Developer
https://developer.apple.com/videos/play/wwdc2018/405/

704056da9a4c4e075ad14479beaebab7?s=128

takasek

June 19, 2018
Tweet

Transcript

  1. Measuring Performance Using Logging by. 2018/6/19 Roppongi.swift 1

  2. takasek @takasek Works OSS: ActionClosurable౳ App: PasteTheType Articles ʮίϯύΠϧΤϥʔ΍ϥϯλΠϜΤϥʔΛ௚͍ͯ͘͠ ͚ͩͰiOSΞϓϦͷ࡞Γํ͕Θ͔ΔϓϩδΣΫτʯ

    ʮ͓લΒ͕ModelͱݺͿΞϨΛͳΜͱݺͿ΂͖͔ʯ ! ʮiOSΞϓϦઃܭύλʔϯೖ໳ʯʢڞஶʣ 2
  3. os_log 3

  4. os_log WWDC2016͔Βಋೖ͞Εͨ let logHandle = OSLog( subsystem: "com.example.widget", category: "Setup"

    ) os_log(.info, log: logHandle, "Hello, %{public}s!", world ) 4
  5. signpost 5

  6. signpost • os_log family • InstrumentsͰύϑΥʔϚϯεܭଌʹ࢖͑ΔΑ͏ʹ֦ு • ͍ܰ 6

  7. ϧʔϓॲཧͷ࣌ؒΛ ܭଌ͍ͨ͠ 7

  8. for element in panel.elements { fetchAsset(for: element) } 8

  9. import os.signpost for element in panel.elements { fetchAsset(for: element) }

    9
  10. import os.signpost let refreshLog = OSLog( // ! subsystem: "com.example.your-app",

    category: "RefreshOperations" ) for element in panel.elements { fetchAsset(for: element) } 10
  11. import os.signpost let refreshLog = OSLog( subsystem: "com.example.your-app", category: "RefreshOperations"

    ) for element in panel.elements { os_signpost(type: .begin, log: refreshLog, // name: " " ") fetchAsset(for: element) os_signpost(type: .end, log: refreshLog, // name: " " ") } 11
  12. ॲཧશମͷ࣌ؒΛ ܭଌ͍ͨ͠ 12

  13. for element in panel.elements { os_signpost(type: .begin, log: refreshLog, name:

    " ") fetchAsset(for: element) os_signpost(type: .end, log: refreshLog, name: " ") } 13
  14. os_signpost(type: .begin, log: refreshLog, name: " ") // for element

    in panel.elements { os_signpost(type: .begin, log: refreshLog, name: " ") fetchAsset(for: element) os_signpost(type: .end, log: refreshLog, name: " ") } os_signpost(type: .end, log: refreshLog, name: " ") // 14
  15. ඇಉظॲཧʹ͍ͨ͠ ! ͕ಉ࣌ʹ૸Δ͜ͱ΋͋Δ… 15

  16. os_signpost(type: .begin, log: refreshLog, name: " ") for element in

    panel.elements { os_signpost(type: .begin, log: refreshLog, name: " ") fetchAssetAsync(for: element) { os_signpost(type: .end, log: refreshLog, name: " ") } } notifyWhenDone { os_signpost(type: .end, log: refreshLog, name: " ") } 16
  17. let !♻ = OSSignpostID(log: refreshLog) // os_signpost(type: .begin, log: refreshLog,

    name: " ") for element in panel.elements { let !$ = OSSignpostID(log: refreshLog, object: element) // os_signpost(type: .begin, log: refreshLog, name: " ") fetchAssetAsync(for: element) { os_signpost(type: .end, log: refreshLog, name: " ") } } notifyWhenDone { os_signpost(type: .end, log: refreshLog, name: " ") } 17
  18. let !♻ = OSSignpostID(log: refreshLog) os_signpost(type: .begin, log: refreshLog, name:

    " ", signpostID: !♻ ) // # for element in panel.elements { let !$ = OSSignpostID(log: refreshLog, object: element) os_signpost(type: .begin, log: refreshLog, name: " ", signpostID: !$ ) // # fetchAssetAsync(for: element) { os_signpost(type: .end, log: refreshLog, name: " ", signpostID: !$ ) // # } } notifyWhenDone { os_signpost(type: .end, log: refreshLog, name: " ", signpostID: !♻ ) // # } 18
  19. Example Represents Log category "RefreshOperatio ns" ؔ࿈͢Δॲཧͷ ·ͱ·Γ Signpost name

    "!" ܭଌର৅ Signpost ID "! ܭଌ͢Δॲཧ ͻͱͭͻͱͭ 19
  20. ϝλσʔλΛ ೖΕ͍ͨ 20

  21. os_signpost( type: .begin, log: log, name: "Compute Physics", "for %{public}@

    at (%.1f, %.1f)" + "with mass %.2f and velocity (%.1f, %.1f)", description, x1, y1, m, x2, y2 ) • %.1f , %.2f , %d ... • %{public}@ • %{xcode:size-in-bytes}llu • Instrumentsʹ෼ੳσʔλͱͯ͠ೝࣝͤ͞Δ 21
  22. ୯ൃΠϕϯτΛ ه࿥͍ͨ͠ 22

  23. os_signpost( .event, log: log, name: "Swipe", "For action 0x%x", actionCode

    ) 23
  24. ϩάΛoffʹ͍ͨ͠ 24

  25. let refreshLog: OSLog if ProcessInfo.processInfo.environment.keys.contains("SIGNPOSTS_FOR_REFRESH") { refreshLog = OSLog( subsystem:

    "com.example.your-app", category: "RefreshOperations" ) } else { refreshLog = .disabled } 25
  26. ϩάͷͨΊʹίετͷ͔͔ΔॲཧΛ͍ͯ͠Δ৔߹… if refreshLog.signpostsEnabled { let information = copyDescription() os_signpost(..., information)

    } 26
  27. Instruments 27

  28. • Instruments → Blank → [+] → "os_signpost" ͰϑΟϧλ •

    signposts͕֬ೝͰ͖Δʢ˞࣮ػͰಈ͔͢͜ͱʣ • Time Profiler • ͰΠϕϯτΛ֬ೝͰ͖ΔOSLog΋͋Δ • OSLog(subsystem: ..., category: .pointsOfInterest) ʹ .event ΛૹΔ • Custom Instruments • ϏδϡΞϥΠζͷํ๏ΛΧελϚΠζͰ͖Δ • ʮnඵҎ্͔͔͍ͬͯΔॲཧΛ੺͘දࣔ͢Δʯͱ͔ 28
  29. ·ͱΊ signpostsͰίʔυΛΞϊςʔτ͠Α͏ • ؆୯ʹॲཧͷϧʔϓΛϩάͰ͖Δ • ϝλσʔλ΋ؚΊΒΕΔ InstrumentsͰ֬ೝ͠Α͏ • ॲཧ࣌ؒΛϏδϡΞϥΠζͰ͖Δ •

    ϓϩάϥϜ͕ԿΛ͍ͯ͠Δ͔Θ͔Δ 29
  30. Refer to Measuring Performance Using Logging https://developer.apple.com/videos/play/ wwdc2018/405/ • ͜ͷࢿྉ͸ʢ΄΅ʣηογϣϯͷҾ͖ࣸ͠Ͱ͢

    • InstrumentsͷσϞ͸Tips΋ॆ࣮ͯͯ͠ඞݟ • ͱ͍͏Θ͚ͰݩηογϣϯΛݟ·͠ΐ͏ 30