Monitoring OS X App Activity
Monitor your app to find problems with it before you release it to the world. To monitor your app in OS X, you profile it with the file system and behavior trace templates supplied by Instruments. Using these templates, you manipulate your app and watch as your code reacts to the manipulation. For example, you can make sure your app doesn’t suddenly terminate, make sure it writes to approved directories only, and then have Instruments run it for you.
Tracking File System Usage
The File Activity trace template monitors file and directory activity, including file open/close calls, file permission modifications, directory creation, and file moves. It consists of the File Activity, Reads/Writes, File Attributes, and Directory I/O instruments.
Every app submitted to the App Store is required to save information in specific directories unless the user explicitly chooses to save the information in another location. Apps that do not save their information in the correct directories are rejected during submission. Use the File Activity trace template to ensure that your app follows the rules found in “File-System Usage Requirements for the Mac App Store” in Submitting to the Mac App Store.
Select the File Activity trace template.
Profile your app.
Select the Reads/Writes instrument.
writecalls in the Function column.
writecalls follow the rules stated in “File-System Usage Requirements for the Mac App Store” in Submitting to the Mac App Store.
Identifying Layout Changes with the Cocoa Layout Trace Template
To properly profile your app, you must identify what your app is doing when layout changes occur. The Cocoa Layout trace template accomplishes this by observing the changes to
NSLayoutConstraint objects in order to help you debug your code. When you run your app, if the layout is not acting the way you expect, then chances are there is an error in your layout. The Cocoa Layout instrument makes it easy to identify these errors by taking a snapshot whenever the layout changes and providing you with information about what is happening.
Preventing Sudden Termination
Preventing your app from suddenly terminating should be a high priority when creating your app because no person enjoys using an app that has a tendency to shut down while in use. Often, sudden termination is caused when the file system is accessed and the system is not protected by calls designed to prevent the sudden termination of the app.
Select the Sudden Termination trace template.
Record your data.
In the Detail pane, sort by Function, Mode, or Safety Rating.
After you have identified an unprotected file access, select the section in the Detail pane to bring up more information in the Extended Detail pane. Here you can see the stack trace at the time of the access and know what thread was running when it happened. The Activity Monitor instrument allows you to see more detailed information about what was happening at the time of the call. Figure 11-1 shows Instruments finding unprotected file access calls.
Using Instruments to Run Your App
The UI Recorder trace template records the user interface events of a process launched from Instruments. You can then play this recording back in order to drive the user interface of the target process while other instruments record new data. It consists of the User Interface instrument only.
To properly test an app, you may need to interact with it multiple times. Using the same actions each time you test provides you with a consistent testing platform. You can then compare your testing results reliably to previous results to ensure that any changes made to your code have not adversely affected the app.
Select the User Interface instrument.
Click Record to begin gathering data.
Perform the events you want to record.
Click Stop after the data has been recorded.
Choose File > Save to save the recording.
User interface events are color coded according to the type of event:
Blue. Mouse events
Green. Key events
Yellow. System events
© 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-04-23)