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
Instrument-1.png
Instrument-2.png
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
Timer-1.png
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
Allocation-1.png
Allocation-2.png
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
Leak-1.png
Leak-2.png










网友评论