yevgeniy solodovnikov xcode instruments_usage

15
Xcode Instruments Usage 101 Eugene Solodovnykov http://idevblog.info @sharpland

Upload: dneprciklumevents

Post on 27-May-2015

305 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Yevgeniy Solodovnikov xcode instruments_usage

Xcode Instruments

Usage101

Eugene Solodovnykovhttp://idevblog.info

@sharpland

Page 2: Yevgeniy Solodovnikov xcode instruments_usage

Instruments app purpose

Track down difficult-to-reproduce problems in your code

Do performance analysis on your program

Automate testing of your code

Stress-test parts of your application

Perform general system-level troubleshooting

Gain a deeper understanding of how your code works

Page 3: Yevgeniy Solodovnikov xcode instruments_usage

Base templates

Page 4: Yevgeniy Solodovnikov xcode instruments_usage
Page 5: Yevgeniy Solodovnikov xcode instruments_usage

Leaks

Uses console leaks application (man leaks will explain you everything)

A lot of applications contain leaks. Our target is to avoid leaks in our applications :)

Quick example – Droplr application

Page 6: Yevgeniy Solodovnikov xcode instruments_usage
Page 7: Yevgeniy Solodovnikov xcode instruments_usage

Allocations

Count each allocation in your application’s session

May help with memory leaks even if Leaks instrument doesn’t see them

Quick example – Hex Fiend application

Page 8: Yevgeniy Solodovnikov xcode instruments_usage

Hex Fiend dissection

Choose Hex Fiend application as a target

Run Leaks and Allocations instruments

Create a new window and close it (5-7 times)

Leaks just keep silence while Allocations instrument displays constant chart growth

Page 9: Yevgeniy Solodovnikov xcode instruments_usage
Page 10: Yevgeniy Solodovnikov xcode instruments_usage

Problem analyzing

Yeah, it’s difficult

Use heapshots

Page 11: Yevgeniy Solodovnikov xcode instruments_usage

- init { [super init]; lineCountingRepresenter = [[HFLineCountingRepresenter alloc] init]; hexRepresenter = [[HFHexTextRepresenter alloc] init]; asciiRepresenter = [[HFStringEncodingTextRepresenter alloc] init]; scrollRepresenter = [[HFVerticalScrollerRepresenter alloc] init]; layoutRepresenter = [[HFLayoutRepresenter alloc] init]; //is missed in representers statusBarRepresenter = [[HFStatusBarRepresenter alloc] init]; dataInspectorRepresenter = [[DataInspectorRepresenter alloc] init]; [[hexRepresenter view] setAutoresizingMask:NSViewHeightSizable]; [[asciiRepresenter view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; ... return self;}

- (NSArray *)representers { return [NSArray arrayWithObjects:lineCountingRepresenter, hexRepresenter, asciiRepresenter, scrollRepresenter, dataInspectorRepresenter, statusBarRepresenter, nil];}

- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [[self representers] makeObjectsPerformSelector:@selector(release)];

...

[super dealloc];}

And leaks won’t detect it

Page 12: Yevgeniy Solodovnikov xcode instruments_usage

Time Profiler

Periodically stops the app and records the stack trace.

Allows to determine where execution time was spent

Page 13: Yevgeniy Solodovnikov xcode instruments_usage
Page 14: Yevgeniy Solodovnikov xcode instruments_usage

Can we do more?

Different pre-defined instruments

DTrace-based custom instruments

Mix them!

Page 15: Yevgeniy Solodovnikov xcode instruments_usage

To be continued...