improving your app with instruments - apple inc.€¦ · app extensions profiling with instruments...

103
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Improving Your App with Instruments Session 418 Daniel Delwood Software Radiologist Tools

Upload: others

Post on 13-Jun-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Improving Your App with Instruments

Session 418 Daniel Delwood Software Radiologist

Tools

Page 2: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Agenda

What's new in Instruments

Memory management

Time profiling

Performance counters

DTrace improvements

Page 3: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What's in Instruments

Page 4: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What's in Instruments

Page 5: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 6: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 7: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 8: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 9: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 10: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 11: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Memory Management

Page 12: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but
Page 13: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Objective-C's Ownership ModelRetain/Release

Reference counting ownership model based on retain, release

When the count drops to zero, object is freed

Retain/release/autorelease rules established and easy to learn• Advanced Memory Management Programming Guide

Deterministic, simple, and fast

Page 14: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Managed Retain/Release Objective-C's Ownership Model

Retain/Release

Reference counting ownership model based on retain, release

When the count drops to zero, object is freed

Retain/release/autorelease rules established and easy to learn• Advanced Memory Management Programming Guide

Deterministic, simple, and fast

Automated Reference Counting (ARC)

Page 15: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Managed Retain/Release Objective-C's Ownership Model

Retain/Release

Reference counting ownership model based on retain, release

When the count drops to zero, object is freed

Retain/release/autorelease rules established and easy to learn• Advanced Memory Management Programming Guide

Deterministic, simple, and fast

Automated Reference Counting (ARC)

• Still have to manage autorelease pools @autoreleasepool { /* code */ }

Page 16: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Reference counting ownership model based on retain, release

When the count drops to zero, object is freed

Deterministic, simple, and fast

Automated Reference Counting (ARC)

Swift's Ownership ModelManaged Retain/Release

Page 17: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Reference counting ownership model based on retain, release

When the count drops to zero, object is freed

Deterministic, simple, and fast

Automated Reference Counting (ARC)• Working with Objective-C? Still have to manage autorelease pools

autoreleasepool { /* code */ }

Swift's Ownership ModelManaged Retain/Release

Page 18: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

AllocationsWhat does it report?

Heap allocations • Class names — e.g. NSMutableArray, MyApp.MainViewController

• Reference types only (class, not struct)

• Retain/Release histories

Virtual Memory (VM) allocations • Paths for mapped files

Stack traces for all

Page 19: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

DemoAllocations + App Extension E

Page 20: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

App ExtensionsProfiling with Instruments

Specify host App • When profiling Xcode scheme

• In Instruments

Transient, but memory matters

Page 21: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

App ExtensionsProfiling with Instruments

Specify host App • When profiling Xcode scheme

• In Instruments

Transient, but memory matters

• Creating Extensions for iOS and OS X, Part 1 Mission Tuesday 2:00PM

• Creating Extensions for iOS and OS X, Part 2 Mission Wednesday 11:30AM

Page 22: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Memory Management with SwiftLanguage tools

Obj-C code can still mismatch Retain/Release

Can still form cycles in Swift

Page 23: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Memory Management with SwiftLanguage tools

Obj-C code can still mismatch Retain/Release

Can still form cycles in Swift

Manage graph, not retain/release

weak !

!

unowned

Page 24: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Memory Management with SwiftLanguage tools

Obj-C code can still mismatch Retain/Release

Can still form cycles in Swift

var x : Optional<T> / T? = objectReturns T or nil when accessed, based on existence of object

Manage graph, not retain/release

weak !

!

unowned

Page 25: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Memory Management with SwiftLanguage tools

Obj-C code can still mismatch Retain/Release

Can still form cycles in Swift

var x : Optional<T> / T? = object

let / var x : T = object

Returns T or nil when accessed, based on existence of object

Returns T always, but if object doesn't exist… deterministic 💣

Manage graph, not retain/release

weak !

!

unowned

Page 26: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

!

!

[self.currentGame registerForStateChanges:^{ if (self.currentGame == newGame) { [self.tableView reloadData]; } }];

!

'self' and 'newGame' captured strongly

^block CapturesHere be dragons

Page 27: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

!

!

[self.currentGame registerForStateChanges:^{ if (self.currentGame == newGame) { [self.tableView reloadData]; } }];

!

'self' and 'newGame' captured strongly

__weak typeof(newGame) weakGame = newGame;__weak typeof(self) weakSelf = self;

^block CapturesHere be dragons

Page 28: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

^block CapturesHere be dragons

__weak typeof(newGame) weakGame = newGame; __weak typeof(self) weakSelf = self; !

!

[self.currentGame registerForStateChanges:^{ if (weakSelf.currentGame == weakGame) { [weakSelf.tableView reloadData]; } }];

Page 29: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Swift ClosuresBehold, the power of capture lists

currentGame.registerForStateChanges() { if self.currentGame == newGame { self.tableView!.reloadData() } }

Page 30: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Swift ClosuresBehold, the power of capture lists

currentGame.registerForStateChanges() { if self.currentGame == newGame { self.tableView!.reloadData() } }

[weak self, newGame] in

Page 31: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Swift ClosuresBehold, the power of capture lists

currentGame.registerForStateChanges() { if self?.currentGame == newGame { self?.tableView!.reloadData() } }

[weak self, newGame] in

Page 32: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Swift ClosuresBehold, the power of capture lists

currentGame.registerForStateChanges() { if self?.currentGame == newGame { self?.tableView!.reloadData() } }

[weak self, newGame] in

• Swift Interoperability In-Depth Presidio Wednesday 3:15PM

• Advanced Swift Presidio Thursday 11:30AM

• Fixing Memory Issues Session 410 WWDC13 Videos

Page 33: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Time Profiling

Kris Markel Performance Tools Engineer

Page 34: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Why?

Page 35: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Why?

To provide a great user experience

Page 36: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Why?

To provide a great user experience• Faster app launch times

Page 37: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Why?

To provide a great user experience• Faster app launch times

• Keep the frame rate at 60fps

Page 38: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Why?

To provide a great user experience• Faster app launch times

• Keep the frame rate at 60fps

• Buttery-smooth scrolling

Page 39: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Why?

To provide a great user experience• Faster app launch times

• Keep the frame rate at 60fps

• Buttery-smooth scrolling

• Responsive UI

Page 40: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What?

An instrument that samples stack trace information at prescribed intervals

Provides an idea of how much time is spent in each method

Page 41: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When?

Page 42: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When?

Investigate specific problems

Page 43: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When?

Investigate specific problems• If you see stuttering or frame rate slowdowns

Page 44: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When?

Investigate specific problems• If you see stuttering or frame rate slowdowns

• Some part of your app is taking too long

Page 45: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When?

Investigate specific problems• If you see stuttering or frame rate slowdowns

• Some part of your app is taking too long

Identify and fix hotspots before they become problems

Page 46: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When?

Investigate specific problems• If you see stuttering or frame rate slowdowns

• Some part of your app is taking too long

Identify and fix hotspots before they become problems• Keep an eye on the CPU gauge in Xcode

Page 47: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

DemoTime Profiler in action

Page 48: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewTrack view

Identify and zoom into problem areas • Drag to apply a time range filter

• Shift+drag to zoom in

• Control+drag to zoom out

Page 49: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewNew Inspector panes

Use keyboard shortcuts to quickly move between panes

Page 50: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewNew Inspector panes

Use keyboard shortcuts to quickly move between panes

• ⌘1—Record settings

Page 51: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewNew Inspector panes

Use keyboard shortcuts to quickly move between panes

• ⌘1—Record settings

• ⌘2—Display settings

Page 52: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewNew Inspector panes

Use keyboard shortcuts to quickly move between panes

• ⌘1—Record settings

• ⌘2—Display settings

• ⌘3—Extended detail

Page 53: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewStrategy views

Page 54: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewStrategy views

• Cores strategy

Page 55: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewStrategy views

• Cores strategy

• Instruments strategy

Page 56: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewStrategy views

• Cores strategy

• Instruments strategy

• Threads strategy

Page 57: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewStrategy views

• Cores strategy

• Instruments strategy

• Threads strategy

- Enable Record Waiting Threads to expose blocked threads

Page 58: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewCall Tree settings

Page 59: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewCall Tree settings

• Expensive calls are frequently near the end of the call stack

Page 60: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

ReviewCall Tree settings

• Expensive calls are frequently near the end of the call stack

• Focus on your own code

Page 61: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

TipsFocus and Prune

Ignore unwanted data • Charge moves the associated cost

• Prune removes the associated cost

• Focus is “prune everything but”

Page 62: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When using Time Profiler

Two More Guidelines

Page 63: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When using Time Profiler• Profile Release builds

Two More Guidelines

Page 64: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

When using Time Profiler• Profile Release builds

• For iOS, profile on the device

Two More Guidelines

Page 65: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance Counters

Joe Grzywacz Performance Tools Engineer

Page 66: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers

Page 67: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers• Typically only four to eight per core

Page 68: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers• Typically only four to eight per core

• Separate from the integer and floating point registers

Page 69: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers• Typically only four to eight per core

• Separate from the integer and floating point registers

Each register can be configured to either:

Page 70: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers• Typically only four to eight per core

• Separate from the integer and floating point registers

Each register can be configured to either:• Count one of a small number of events

Page 71: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers• Typically only four to eight per core

• Separate from the integer and floating point registers

Each register can be configured to either:• Count one of a small number of events

- Instructions executed, L2 Cache Misses, Branches Taken, …

Page 72: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What Are Counters?

Each processor core contains a small number of 64-bit hardware registers• Typically only four to eight per core

• Separate from the integer and floating point registers

Each register can be configured to either:• Count one of a small number of events

- Instructions executed, L2 Cache Misses, Branches Taken, …

• Take a callstack every time a predetermined number of events occurs

Page 73: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance Monitoring Interrupts(PMIs)

Time

# Branches

Executed

Page 74: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance Monitoring Interrupts(PMIs)

Time

# Branches

Executed

Time-Based

Sampling

Page 75: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance Monitoring Interrupts(PMIs)

Time

# Branches

Executed

PMI-Based

Sampling

Time-Based

Sampling

Page 76: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance CountersHow are they useful?

Page 77: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance CountersHow are they useful?

Provide a deeper understanding of your app’s performance beyond just time

Page 78: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance CountersHow are they useful?

Provide a deeper understanding of your app’s performance beyond just time• How well CPU resources are being used

- Caches, execution units, TLBs, …

Page 79: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Performance CountersHow are they useful?

Provide a deeper understanding of your app’s performance beyond just time• How well CPU resources are being used

- Caches, execution units, TLBs, …

• Runtime process traits - Branch frequency, instruction mix, …

Page 80: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What’s New with Counters

Formulas support

IPC =Instructions

Cycles

=BranchesMispredicted

Branch Mispredict RateBranchesExecuted

=(L1CacheLoadMisses + L1CacheStoreMisses)

L1 Cache Miss %(L1CacheLoads + L1CacheStores)

100 ×

Page 81: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What’s New with Counters

iOS 8 support • 64-bit ARM devices only

Page 82: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What’s New with Counters

iOS 8 support • 64-bit ARM devices only

Event Profiler instrument is deprecated • Same PMI functionality is available within the Counters instrument

Page 83: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

DemoiOS Performance Counters

Page 84: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Page 85: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler

Page 86: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler• This is a statistical representation of your application

Page 87: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler• This is a statistical representation of your application

Counters supports Performance Monitoring Interrupts (PMI)

Page 88: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler• This is a statistical representation of your application

Counters supports Performance Monitoring Interrupts (PMI)• Allows sampling based on the number of events

Page 89: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler• This is a statistical representation of your application

Counters supports Performance Monitoring Interrupts (PMI)• Allows sampling based on the number of events

• Note that PMI instruction locations can be imprecise

Page 90: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler• This is a statistical representation of your application

Counters supports Performance Monitoring Interrupts (PMI)• Allows sampling based on the number of events

• Note that PMI instruction locations can be imprecise

Formulas allow you to combine raw event counts in custom ways

Page 91: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Counters Summary

Collects data in a similar manner to Time Profiler• This is a statistical representation of your application

Counters supports Performance Monitoring Interrupts (PMI)• Allows sampling based on the number of events

• Note that PMI instruction locations can be imprecise

Formulas allow you to combine raw event counts in custom ways• Be sure to save your common formulas in a template

Page 92: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What’s New with DTrace

Page 93: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

What’s New with DTrace

Page 94: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Dynamic tracemem

Dynamic tracemem, provides a way to trace dynamically sized arrays • tracemem(address, nbytes_max, nbytes)

- nbytes_max: maximum size of the array, must be known at compile time

- nbytes: the actual size of the array you want to copy

- Example: void CGContextFillRects(CGContextRef c, const CGRect rects[], size_t count); pid$pid_MyAppName::CGContextFillRects:entry { this->array = copyin(arg1, sizeof(struct CGRect) * arg2); tracemem(this->array, 512, sizeof(struct CGRect) * arg2); }

Page 95: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Improved Histograms

Histogram improvements: agghist, aggzoom, aggpack

http://dtrace.org/blogs/bmc/2013/11/10/agghist-aggzoom-and-aggpack/

Page 96: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Other New Features

Wait for process to start with –W dtrace -Z —W MyAppName ‘pid$target::*CALayer*:entry’

Page 97: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Other New Features

Wait for process to start with –W dtrace -Z —W MyAppName ‘pid$target::*CALayer*:entry’

Tunable internal DTrace variables # List the tunable variables sysctl kern.dtrace

Page 98: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Other New Features

Wait for process to start with –W dtrace -Z —W MyAppName ‘pid$target::*CALayer*:entry’

Tunable internal DTrace variables # List the tunable variables sysctl kern.dtrace

Updated documentation man dtrace

Page 99: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Summary

Profile Swift and Objective-C alike

Be proactive

Don't assume—profile, change, and iterate

Page 100: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

More Information

Dave DeLong Developer Tools Evangelist [email protected]

Instruments Documentation Instruments User GuideInstruments User Reference http://developer.apple.com

Apple Developer Forums http://devforums.apple.com

Page 101: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Related Sessions

• Creating Extensions for iOS and OS X, Part 1 Mission Tuesday 2:00PM

• Integrating Swift with Objective-C Presidio Wednesday 9:00AM

• Creating Extensions for iOS and OS X, Part 2 Mission Wednesday 11:30AM

• Swift Interoperability In-Depth Presidio Wednesday 3:15PM

• Advanced Swift Debugging in LLDB Mission Friday 9:00AM

Page 102: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but

Labs

• Swift Lab Tools Lab A All Week

• Instruments Lab Tools Lab B Wednesday 9:00AM

• Power and Performance Lab Core OS Lab B Wednesday 2:00PM

• Instruments Lab Tools Lab B Thursday 9:00AM

• Power and Performance Lab Core OS Lab A Thursday 3:15PM

Page 103: Improving Your App with Instruments - Apple Inc.€¦ · App Extensions Profiling with Instruments Specify host App • When profiling Xcode scheme • In Instruments Transient, but