When you create a new Instruments document, a sheet drops down offering a choice among templates, preconfigured sets of instruments for common tasks (see Figure 26.10). Click the configuration of your choice, and then click one of the buttons at the bottom of the sheet:
- Open an Existing File... abandons the new document and presents a standard file-selection dialog for opening an old one. This is simply a convenience, effectively canceling the sheet and performing File > Open....
- Cancel closes the untitled document without saving.
- Choose creates the document and populates it with the instruments for the selected template.
- Record does a lot of work. It creates the document and populates it with the selected template's instruments. Then it starts recording. When a trace document doesn't have a default target application—as a newly instantiated document would not—Instruments has to associate an application with each instrument in the document. A variant on the standard open-file dialog appears, enabling you to pick the target application or tool, and to specify arguments and environment variables. You can specify one target for all the instruments by checking the Apply to All Instruments box. When all the targets are set, Instruments launches them and starts recording.
Figure 26.10 The choose-template sheet that introduces each new trace document in Instruments. There are eight standard templates, including a blank template that has no instruments in it at all. Selecting a template fills the lower view with a brief description of the template.
These are the standard templates Apple supplies. As mentioned in "Saving and Reopening," you can create templates of your own by composing a trace document to your needs, and using File > Save as Template... to save it.
- Blank contains no instruments at all. You add the ones you want by dragging them in from the Library.
- Activity Monitor contains the Activity Monitor instrument. It's a comprehensive instrument, and this template can be thought of as a recordable version of the Activity Monitor application, or as a nicer version of BigTop.
- CPU Sampler gives you the Sampler and CPU Monitor instruments. The one provides a statistical by-function profile of the target application, and the other, the CPU load at the same times. The Sampler application now launches Instruments and opens this template.
- File Activity sets you up with File Activity, Reads/Writes, File Attributes, and Directory I/O.
- Leaks is the template we used in Chapter 19. It provides the ObjectAlloc and Leaks instruments to track the rate of object creation, and to verify that what you allocate, you also free. If you are interested in what your application is doing with memory, this is the template to use, rather than Object Allocations, which provides only ObjectAlloc.
- Object Allocations contains only the ObjectAlloc instrument. It is intended as a substitute for the ObjectAlloc application from earlier editions of the developer tools, and in fact running the current version of the ObjectAlloc application simply runs Instruments and instantiates this template.
- UI Recorder provides the User Interface instrument only. This template can be used to construct lifetime or looping scripts to verify the correct operation of a program, or you can add tracks to capture data as events occur.
- Core Data includes Core Data Fetches, Core Data Cache Misses, and Core Data Saves. It does not include Core Data Faults (you could drag it in), but it hits all the events that really impact the performance of a Core Data application.