Instruments in Xcode 8.3.2

Purpose

Every iOS developer inevitably runs into two common issues during development:

  • Things begin slowing down, bringing with it noticeable stuttering and delays.
  • Chrashes emerge from ballooning memory usage.

If you're new to the iOS landscape I encourage you to experiment with instruments.
In this post I am going to cover 3 instruments I routinely use with every app I lay my hands on.

  • You'll learn how to use the Time Profiler to measure the time it takes to execute code.
  • You'll see how quickly memory can add up, potentially crashing your app, by using the Allocation instrument.
  • You'll discover the ARC (automatic reference counting) isn't so automatic when we dive into the Leaks instrument.

The Example App

swift demo: https://github.com/mcgraw/dojo-instruments

Open Instuments

Step By Step

  • Xcode ==> Product ==> Profile
  • Choose Time Profiler (Try another is OK)
  • navigation top right corner click the + icon, add more Profile (Such as Leaks)
    Image Show
Instruments in Xcode 8.3.2_第1张图片
Instrument-1.png

Instruments in Xcode 8.3.2_第2张图片
Instrument-2.png

Instruments in Xcode 8.3.2_第3张图片
Instrument-3.png

Time Profiler

**The Time Profile instrument captures stack trace information depending on interval (default is 1ms).
It provide a decent approximation for how much time a given method took by comparing the state of the stack trace against the interval. **
Step By Step

  • Choose Time Profiler View ==> Select the problem area ==> change the config
  • Double click the Stack Trace (or Symbol Name) ==> Code View
    Image Show
Instruments in Xcode 8.3.2_第4张图片
Timer-1.png

Instruments in Xcode 8.3.2_第5张图片
Timer-2.png

Allocation Profiler

Often times, especially with photo apps, you'll run into scenarios where you must download a lot of images from a server.
If you're not careful memory usage can ballon dramatically.
You must make sure that you are caching images to the side that you expect to reuse.

Step By Step

  • Choose Allocation Profiler View ==> Select the problem area ==> change the config
  • click the Stack Trace (or Symbol Name) ==> detail Stack Trace
  • Double click the detail Stack Trace (or Symbol Name) ==> Code View
    Image Show
Instruments in Xcode 8.3.2_第6张图片
Allocation-1.png

Instruments in Xcode 8.3.2_第7张图片
Allocation-2.png

Instruments in Xcode 8.3.2_第8张图片
Allocation-3.png

Leaking Memory

Even though Apple introduced ARC, you need to be aware that the potentail for leaks for leaks do remain. Even if you're using swift.
Step By Step

  • Choose Leak Profiler View ==> Select the problem area ==> change the config
  • Double click the Stack Trace (or Symbol Name) ==> Code View
    Image Show
Instruments in Xcode 8.3.2_第9张图片
Leak-1.png

Instruments in Xcode 8.3.2_第10张图片
Leak-2.png

Reference

  • How To Use The 3 Instruments You Should Be Using
  • 10 Actionable Performance Tips To Speed Up Your Table View

你可能感兴趣的:(Instruments in Xcode 8.3.2)