Instrument is a flexible performance-analysis and testing tool that’s part of the Xcode tool set. You can detect memory allocation leaks, check CPU usage, energy usage.., you can use this tool to improve your codes, and use the best solution for your apps and your users. Start with basics, which can be helpful later. In this tutorial we launch Instruments at different ways, and set some really great settings.
As the User Guide says and you can see at the Instruments Workflow:
"At a high level, it consists of the following main phases:
So you need to rewrite your own source code after analyze. Instrument will not do that for you!
If you want to use your Instruments App, instead of start your App a usual way(click on play, to run), click on Product at Xcode menu and select "Profile".
Your Instruments App open, and you have to select a type of analysis. You can use Tim Profile, which is the fast way to detect our CPU usage problem. Or Core Animation, which can detect your bad Image loading or caching methods, or some allocation issues too.
You can choose of "Standard", "Custom" and "Recent" profiling templates.
If you created your own mixed profiling template, later you can use that with ease from "Custom".
At Standard profiling templates, you can choose from these types:
|This is a blank profiling template containing no instruments. Select this template if you can’t find a template to meet your needs, or if you want full control over what individual instruments and configuration settings are used to profile your app.|
|This template monitors the overall CPU, memory, disk, and network usage statistics of the specified process or processes. This template may be used with OS X or iOS.|
|This template tracks the anonymous virtual memory and heap of a specified process. It provides class names and, optionally, retain and release histories for objects. This template may be used with OS X or iOS.|
|This template executes a script that simulates user interface interaction in an iOS app launched by Instruments. This template may be used with iOS only.|
|This template observes changes made to layout constraint objects in order to determine when and where a layout constraint is not working as intended. This template may be used with OS X only.|
|This template uses time profiling to measure graphics performance and CPU usage in an app. This template may be used with iOS only.|
|This template monitors Core Data activity in the file system, including fetches, cache misses, and saves. This template may be used with OS X only.|
|This template monitors counter (PCM) events using time- or event-based sampling methods. This template may be used with OS X only.|
|This template gathers diagnostics regarding energy usage and the on/off state of major hardware components, such as Bluetooth and Wi-Fi. This template profiles device behavior, not individual app behavior. This template may be used with iOS only.|
|This template monitors file and directory activity, including file opens and closes, permission modifications, directory creation, file moves, and more. This template may be used with OS X only.|
|This template measures GPU driver statistics and samples active CPU usage. This template may be used with OS X or iOS. Included GPU Driver, Time Profiler.|
|This template measures general memory usage and checks for leaked memory. It provides statistics on object allocations by class, as well as memory address histories for all active allocations and leaked blocks. This template may be used with OS X or iOS.|
|This template profiles the performance of iOS Metal applications by providing tracing information from the application, driver, and GPU layers. This template may be used with iOS only.|
|This template analyzes the TCP/IP and UDP/IP connections an app uses. This template may be used with iOS only.|
|This template measures and analyzes OpenGL ES activity in order to identify performance and other OpenGL ES problems, and offer recommendations for resolving them. This template may be used with OS X or iOS. - Included GPU Driver, OpenGl ES Analyzer.|
|This template provides comprehensive information about system behavior. It shows when threads are scheduled, and shows thread transitions from user to system code via system calls and memory operations. This template may be used with OS X or iOS. - Included Scheduling, System Call, VM Tracker.|
|This template monitors an app and records system I/O activity related to files, sockets, and shared memory. This includes inputs, outputs, duration, backtrace, call tree, and more for each call. This template may be used with iOS only.|
|This template performs low-overhead time-based sampling of running processes. This template may be used with OS X or iOS.|
|This template measures general memory usage of an app, focusing on the detection of over-released objects, known as zombies. It provides statistics on object allocations by class, as well as memory address histories for active allocations. This template may be used with OS X or iOS.|
1. Profile - select Xcode Product menu and choose Profile - choose Blank or other profiling Template, and start the Test with red record icon.
2. Run your App and at Debug session, choose "Profile in Instruments" button.
You can restart the Application or transfer the current debug session, and you can see the already exists debug session in Instruments.
3. You can launch from Dock or from Launchpad from Xcode Developer Tool
4. You can launch Instruments with Command Line:
In Terminal, in Applications/Utilities run this line: open /Applications/Xcode.app/Contents/Applications/Instruments.app
The most important thing, if you want to get really accurate data, check at Instruments performance - Recording - "Always use deferred mode".
"Increase the accuracy of performance-related data by deferring data analysis until you quit the app you are testing. Typically, Instruments analyzes and displays data while your app runs, allowing you to view the data as it is collected. Performing analysis live slows down the target process by taking up CPU time and memory, which leaves you with measurements that may not reflect how the process would normally behave. Running Instruments in deferred mode delays the analysis of data until the data collection is done, either after your app has finished running or after you click Stop. While in deferred mode, you are blocked from interacting with the instruments that are collecting data.
In deferred mode, after Instruments finishes collecting data, Instruments processes the data and displays it onscreen. Deferring data analysis adds time to the later stages of the data collection process, but it helps ensure that performance-related data is accurate."
The next part of the series: Instruments tutorial Part 2 - Navigate Timeline Pane, Detail Pane- soon!
If you would like to be notified of my new solutions, please subscribe to my Newsletter or my youtube channel and/ or follow me on Facebook or Twitter! Check Footer section for these opportunities!