IOS Instruments Tools Use

Source: Internet
Author: User

iOS performance optimizations: Instruments tools

Preface: Even if the cow programmer, write the great code still there are many optimizations, not to mention our ordinary programmers write the ordinary code (such as the author) there are many optimizations and bugs need us to debug. So code optimization is the skill we have to master.

Today I introduce you to a Code Analysis Optimization tool: Xcode comes with the detection debugging tool instruments.

Instruments offers a lot of features, and I'll focus on some of the most common categories I've used:

1.Time PROFILER:CPU analysis tool analyzes the execution time of the code.

2.Core Animation: Off-screen rendering, layer blending and other GPU time-consuming.

3.Leaks: Memory detection, memory leak detection tool.

4.Energy Log: Power consumption detection Tool.

5.Network: Flow Detection Tool.

Using the instruments tool that comes with Xcode, you first need to open it.

You can then choose the appropriate debugging tool based on the different performance you want to debug.

    • 01. Scheme of the configuration item.


    • 02. Configure Project.


I. Introduction to TIME Profiler usage

Timeprofiler: Time Analysis tool, which tracks the stack information (stacktrace) for each thread at a set interval (default of 1 milliseconds), and calculates how long a method executes and gives an approximate value by comparing the stack state between intervals. The steps are as follows:

1. Double-click Timeprofiler to enter the debug screen click on the upper left corner of the Red Origin (Launcher button), you can see the time consumption.

However, we find that this information can only be shown to the underlying thread runloop time-consuming, and does not help us to navigate to the specific code, the following is the CallTree option to check the operation and meaning. These options are not selected by default, but selecting them can help you navigate to critical code more quickly, which is often the source of the problem.

Separate by thread: analysis is done separately by thread, which makes it easier to pull out the problem threads that eat resources. Especially for the main thread, it processes and renders all the interface data, and once it is blocked, the program must stutter or stop responding.

Invert Call Tree: The reverse output calls the trees. The deepest calling method is displayed at the top, which makes it easier to find the most time-consuming operations.

Hide Missing Symbols: Hides missing symbols. If the dSYM file or other system architecture is missing, there will be a number of strange hexadecimal values in the list, using this option to mask the interfering elements and let the list return to a crisp.

Hide System Libraries: Hides the systems library file. Filter out various system calls and show only your own code calls.

Flattern recursion: Flattening recursion. Combine the multiple stacks produced by the same recursive function (because the recursive function calls itself) into one.

Top Functions: Find the most time-consuming function or method.

Tick the above to see the corresponding code, at this time, select a line of time-consuming operation can be entered into the corresponding code and display detailed consumption time, such as:

Depending on the time code, some optimizations can be made to reduce repetitive time-consuming logic to optimize the CPU.

Two. Core animation animation Rendering Use Introduction:

One thing to note about the coreanimation system is that it must be a real-machine debug for debugging off-screen rendering, drawing, animation, and so on. Check the following options for debugging:

More IMPORTANT:

·" Color Blended

Layers ": Layer Blending

Shows the blended layer Blendedlayer (labeled in red), blendedlayer because the layers are transparent (Transparent) and the system needs to mix the view and the lower view when rendering the view (blend) To calculate the actual color of the pixel. So the less red, the better.

·" Color Hits

Green and Misses Red ": Layer Cache

Many view layers are rendered very high for reasons such as shadow, mask, and gradient, so Uikit provides APIs for caching these Layer:[layersetshouldrasterize:yes], These layers are cached as bitmap bitmaps for rendering use, and if they are invalidated, they are discarded bitmap regenerated. So the more green, the less red the better.

·" Color

Offscreen-rendered Yellow ": Off-screen rendering

Offscreen-rendering off-screen rendering means that when iOS wants to display a view, it needs to compute the view's bitmap in the background with the CPU, and then give the GPU a onscreen-rendering display on the screen, because displaying a view requires two calculations. So this offscreen-rendering will cause the app's graphics performance to degrade. So the less yellow the better.

Secondary:

·" Color

misaligned Images ": Picture zoom

Misalignedimage indicates that the points to be plotted cannot be mapped directly to the pixels on the frequency screen, and the system needs to do anti-aliasing anti-aliasing on the neighboring pixels, increasing the graphics burden, which is usually caused by the recalculation and setting of some view frame.

·" Color Copied

Images ": Callout image copied by core animation when drawing is applied

·" Color

Immediately ": Instruments cancel 10 millisecond delay while doing color-flush operation

·" Color

Compositing Fast-path Blue ": marks the path drawn by the hardware

·" Flash Updated

Regions ": redrawing the area

Tick these different options to see rendering annotations of different colors on the real machine.

Three. Leaks Memory debugging usage Introduction

Leaks is a tool used in iOS programs to detect memory leaks, and the flexible use of leaks can help prevent memory leaks in programs from being hung up too much. First double click on the leaks click on the upper left corner of the red dot run, and select CallTree, in the calltree option tick invertcalltree and hidesystemlibraries options as shown in

Then the program runs up and we look at the area of memory changes above, the tool in the time to the amount of memory consumed in the form of a fill graph, when the mouse moved to the position of the graph to show the memory of that moment, if the memory is shown below the Red Cross indicates there is a memory leak here. This area can be circled in the diagram by the mouse, at which point the following calltree will print out the corresponding function stack call and the memory size information, double-click to go to the corresponding code area to view. Such as:

Double-click the function name to enter the location of the code to view the specific:

In this case, you can do the memory debugging according to the corresponding location in the code.

Four. Energy log power consumption test usage Introduction:

Double hit open energylog directly click on the red dot run program, the left to see the CPU activity ratio, network activity ratio, brightness status, mobile phone sleep status, mobile phone connection bluetooth status, mobile phone connection Wi-Fi status, mobile phone GPS status is the component of the mobile phone power consumption. Such as:

We can also click on the left-hand status bar of the XOCE when launching the program, select the Energyimpact option, and on the right you can see the real-time power consumption of the phone. Such as:

The upper left is the resource real-time consumption of the dashboard, the upper right part of the average resource consumption situation, below is the specific consumption of resources.

Pay attention to real-time resource consumption the area in the dashboard where the pointer is pointing

Green-Reasonable

Yellow-resource consumption is high. Your program consumes less power.

Red-resource consumption is very high. With only a slight use of your app, the user can obviously feel the power consumption.

For specific power consumption conditions:

The four main reasons for power consumption are CPU (wake-up and use), Network (Internet access), location (positioning function), Background (background run function).

Refreshes per second. The resource consumption of the different functions. If the resource small block shows dark gray, the small squares show white when the resource is not consumed.

Five. Introduction to network detection using:

Double hit open network directly click on the red dot run program at the top of the mobile network can see the input and output size, with the mouse to intercept an area to see whether our app occurred in the network consumption or other processes occur, we can also see the network request local address and service address, Information such as the size of the input and output details of the various viewing tests are described below:

If you want to circle a place that consumes network resources, there are three options below:

The first: processes represents a view of the network process, which is the total amount of traffic used by your app and other programs.

The second: connections represents all access to the network request port, input and output size, local address, packet size, round trip time and other information.

The third: interfaces is the overall network usage of the current phone at the user's point of view (do not differentiate threads, only differentiate between network usage type-WiFi or traffic).

1. Select processes

We can find that the tool divides the entire network access into two parts, and our app and other processes show them separately:

1.process: Process name.

2.data in Request data size.

3.packets in Request packet size.

4.data out send data size.

5.packets out send packet size.

6.duplicate data recv The size of a retransmission.

7.out-of-order data transmission failure size.

8.retransmissions Network retransmission times.

2. Select Connections

This option to print out all the data interaction details of the network request, so that we can see at a glance where the data comes from, where to go, what the size is, and how much the frame rate is.

The connections option is more than the processes option

1.local represents the local access address.

2.remote Remote Service address.

3.shortest roundtrip: Shortest round trip time.

4.avg. Roundtrip: Average round trip time.

3. Select interfaces

Interfaces represents the network usage of the phone at the user level, where the interface option represents the network environment, and connections represents the total number of connections other options are the same as above.

Based on the different information of the above three options, we can fully and systematically master the network usage of our app and the user's current phone.



Olivia_zqy
Links: https://www.jianshu.com/p/4b882f1bd1a9
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

IOS Instruments Tools Use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.