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.

bullet
To see where you app saves information
  1. Select the File Activity trace template.

  2. Profile your app.

  3. Select the Reads/Writes instrument.

  4. Look for write calls in the Function column.

  5. Verify that write calls follow the rules stated in “File-System Usage Requirements for the Mac App Store” in Submitting to the Mac App Store.

    image: ../Art/File-system_usage.png

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.

bullet
To locate cocoa layout calls
  1. Profile your app from inside of Xcode.

  2. Exercise your app.

  3. In the Detail pane, highlight the item that is not working as intended.

  4. Pull up your code in the Detail pane’s Console area.

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.

bullet
To find unprotected file access
  1. Select the Sudden Termination trace template.

  2. Record your data.

  3. 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.

Figure 11-1  Finding an unprotected file access call

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.

bullet
To collect data using the same set of actions each time
  1. Select the User Interface instrument.

  2. Click Record to begin gathering data.

  3. Perform the events you want to record.

  4. Click Stop after the data has been recorded.

  5. Choose File > Save to save the recording.



    image: ../Art/UI_Instrument_usage.png

User interface events are color coded according to the type of event:


Did this document help you? Yes It's good, but... Not helpful...