To do a good job, you must sharpen your tools

  • Time Profile The time profile tool is used to detect application CPU usage and can see that various methods in the application are consuming CPU time. Using a lot of CPU is not necessarily a problem. Animation on the client side is very CPU dependent, and animation itself is a very demanding and resource-intensive task.

  • Time profilers help us analyze the execution Time of our code, find out what’s causing it to slow down, and tell us “Where did the Time go?” .

  • Time Profiler analysis principle: It tracks the stack information of each thread at a fixed Time interval, and calculates how long a method has been executed by comparing the stack state between the Time interval and obtains an approximate value. It’s essentially the same as our original analysis, except it counts the time spent by each method.

Notice before using Time Profiler

  • 1. Click Time Profiler application to start running. You can get the distribution and percentage of the elapsed time of the entire application. In order to ensure that data analysis is implemented in the unified use scenario, the following points need to be paid attention to:

  • When you start your application performance analysis, be sure to use a real machine. Emulators run on Macs, which tend to have faster cpus than iOS devices. In contrast, the Mac GPU is completely different from the iOS device, and the emulator has to emulate the device’s GPU at the software level (CPU), which means gPU-related operations run slower on the emulator, especially if you’re using CAEAGLLayer to write some OpenGL code. This results in a mismatch between emulator performance data and user performance data.

  • 2. Another important thing to do before starting performance analysis is to ensure that the application is running in a Release version, not a Debug version.

  • When the release environment is packaged, the compiler introduces a number of performance-enhancing optimizations, such as removing debugging symbols or removing and reorganizing the code. IOS also introduced a “Watch Dog” mechanism. In different scenarios, the watchdog monitors application performance. If the running time for this scenario is exceeded, the watchdog forces the application to terminate. The developer can see the corresponding log in crashLog. However, Xcode will disable “Watch Dog” in debug configuration.

3. Time Profiler main interface (several key areas to focus on)

View switch: Switches of three views. Select all of them to obtain the main screen capture effect.

Search bar: If you need to quickly find a specific class or function, you can enter the name of the class or function here, will have an unexpected effect.

Data visualization Panel: This is where you can set the scope of your attention to filter out irrelevant content.

Details panel: In the Time profiler, you can mainly view the Call Tree and Sample List. Generally, you can use the Call Tree to view the details. It is simple and clear:

Running Time: The Time for the function to run. This Time is the cumulative Time

Self: the number of times at the top of the stack

Symbol Name: Symbolic information about the called function

From the details panel Call Tree and related content extend the diagram corresponding to the details panel:

Sample List

Timestamp: Start time of sampling

Dep: Stack depth

CPU: Which CPU the thread is running on

Process: Indicates the Process name

Thread: Indicates the name of the Thread

Hot Frame: The function that is called the most in the sample

Responsible Library: The Library that calls this function

Responsible Caller: The function that calls this function

Options view parameter Settings

The new version is set here

Separate by Thread (recommended) : The Thread is separated so that the Thread with the largest CPU usage can be clearly seen in the call path. Each thread should be considered separately. Only in this way can you catch the “heavy” threads that are consuming a lot of CPU. By breaking the analysis down into threads, it is easier to catch the problem threads that are eating resources. Especially for the main thread, which processes and renders all the interface data, if blocked, the program must stall or stop responding.

Invert the Call Tree (select) is not recommended: Call back to a Tree falls, the habitual cascaded down from the root of the display, such as elected will return to come over from the bottom of the Call to level 1 level display. It’s easier if you want to see which method call is the deepest.

Hide Missing Symbols (recommended) : When you don’t have an application or system dSYM file, you can’t see the method names on the details panel. You can only see the unreadable hexadecimal values. This makes no sense to us.

Hide System Libraries (recommended) : When this option is selected, it displays symbolic information about your application. Generally, you are concerned about how long your code takes to write, not how much CPU is used for your System Libraries.

Flatten Recursion: If selected, it will call the Recursion function on the stack as an entry point.

Top Functions (optional) : select this function to rank the most time-consuming Functions in descending order, and this time is cumulative. For example, if A calls B, the time of A will include the time of B.

4. Use skills

1. The ICONS with black avatars are the hints given by Time Profiler. There may be performance bottlenecks

2. Hold down the Option key on the home screen 6 and drag the mouse to select the time period to be filtered

3.command +F Specifies the name of the function or class that searches for filters

4. Associated code