The Trace Document Window
The initial form of a trace document window is simple: a toolbar at the top, and a stack of instruments in the view that dominates the window. After you've recorded data into the document, the window becomes much richer. Let's go through Figure 26.2 and identify the components.
Figure 26.2 A typical Instruments window, after data has been recorded. The Extended Detail pane (at right) has also been exposed. I discuss the numbered parts in the text.
The toolbar comes in three sections. The controls at left (1) control recording and the execution of the target applications. There is a pause button for suspending and resuming data collection, a Record / Drive & Record / Stop button to start and stop data collection, and a loop button for running a recorded human-interface script repeatedly.
The Default Target pop-up designates the process or executable that all instruments in the document will target, unless you specify different targets for individual instruments. The choices are as follows:
- All Processes. Data will be collected from all the processes, user and system, on the machine. For instance, the Core Data instruments can measure the Core Data activity of all processes. Not every instrument can span processes; if your document contains no instruments that can sample systemwide, this option is disabled.
- Attach to Process. Data will be collected from a process that is already running; select it from the submenu. Some instruments require that their targets be launched from Instruments, and cannot attach to running processes. If you use only nonattaching instruments, this option is disabled.
- Launch Executable. When you start recording, Instruments will launch the selected application or tool, and collect data from it. The submenu contains items for applications you've recorded previously, and has a Choose Executable item to select a fresh application.
- Instrument Specific. Each instrument will collect data from the target specified in the Target pop-up of its configuration inspector. The instruments in a trace document do not all have to collect data from the same target.
The center section (2) relates to time (see Figure 26.3). The clock view in the center of the toolbar displays the total time period recorded in the document. If you click the clock-face icon to the right of the time display, the clock shows the position of the "playback head" in the time scale at the top of the Track pane.
Figure 26.3 The center section of a trace document's toolbar displays a clock, and controls for selecting a span of time within a recording. The clock displays the total time in the document (or, if you click the icon at the right of the clock, the position of the "playback head") and the run being displayed if there is more than one.
The clock view also controls which run of the document is being displayed. Each time you click Record, a new recording, with a timeline of its own, is added to the document. The run now being displayed is shown like "Run 1 of 2," and you can switch among them by pressing the arrowhead buttons to either side.
Most instruments will display subsets of the data they collect if you select a time span within the recording. To do so, move the playback head to the beginning of the span, and click the button on the left of the Inspection Range control; then move the head to the end of the span and click the button on the right. The selected span will be highlighted, and the Detail pane will be restricted to data collected in the span. To clear the selection, click the button in the middle.
The right section (3) provides convenient controls for display. Mini hides Instruments and displays a heads-up window for controlling recording from other applications. View pops up a menu that shows and hides the Detail and Extended Detail panes. Library shows and hides the Library window.
The Track Pane
The Track pane (4) is the focus of the document window, and the only component you see when a document is first opened. This is the pane you drag new instruments into. Each instrument occupies its own row, with a configuration block on the left, and the instrument's track on the right.
The configuration block (see Figure 26.4) shows the instrument's name and icon. To the left is a disclosure triangle so you can see the instrument's track for each run in the document. To the right is an inspector button (i) that reveals a configuration inspector for the instrument.
Figure 26.4 A stack of instrument tracks in a trace document. Each instrument has its own row, with a timeline extending to the right, calibrated in seconds. Clicking an instrument's configuration button opens an inspector containing settings for the instrument. Some of these control the style of the graph and which of its data an instrument displays, and can be changed at any time. The pop-up at the top of the inspector selects what process the instrument is to collect data from, and must be set (or left to the default, if the instrument can accept it) before recording begins.
The tracks to the right of the configuration blocks display the data collected by the instruments, on a timeline. The configuration inspector controls what data is plotted, and how it is displayed.
At the top of the timeline is a ruler matching the data to the time at which is was collected. The scale of the track can be controlled by the slider below the configuration blocks. In the ruler, you will see a white triangle, the playback head. Drag the playback head and use the Inspection Range control to select intervals within the recording. As you drag the head across the track, many instruments will label their tracks with the value of their data at that time.
The Detail Pane
The Detail pane (5 and 6) appears when you've made a recording, or when you use a control or menu item to display it. View > Detail (D), View (toolbar button) > Detail, the Detail item in the Action ) menu at the lower left of the window, and the detail button (rectangle with arrowhead) next to it, will all toggle the Detail pane. You do not lack for options.
When you select an instrument in the Track pane, the data from the instrument collection is shown in tabular form in the Detail pane. What's in the table varies among instruments. And, the Detail pane controls (9, and Figure 26.5) provide for up to three table formats.
Figure 26.5 The Detail View buttons, which appear below the table portion of the Detail View. The first three buttons select different table displays, or "modes." The modes are Table, Outline, and Diagram. The fourth button, showing a window with a portion on the right highlighted, opens or closes the Extended Detail pane. The Navigation Path breadcrumb control enables you to back a display off after you've drilled down into a detail.
Like the table itself, the alternative views vary depending on the instrument. The general pattern seems to be
- Table mode is the principal display the instrument's author has chosen for its data. For most instruments, this is the raw data they collected, such as the details of individual calls in the Reads/Writes instrument. In Sampler, the table contains a stack trace for each sample; in ObjectAlloc, the items are classes/categories of allocated blocks.
- Outline mode, in the case of instruments that collect stack traces, aggregates the traces into call trees (like the Tree and Heavy displays in Shark). When this is the case, the Call Tree controls in the Detail controls view (5) become active.
- Diagram mode is not often used. In Chapter 19, we saw that ObjectAlloc used this for a table of the individual data it collects.
The next button over, with an icon that suggests a window with a portion highlighted, displays the Extended Detail pane (7), which is covered in the next section.
When you "drill into" data in a Detail pane, such as when you obtain the history of an allocated block in ObjectAlloc, the "breadcrumb" control at the right end of the Detail controls enables you to back out to the superior view.
The left portion of the Detail pane (5) contains controls to adjust or analyze the contents of a Detail table, and in some cases to configure an instrument before it is run. The repertoire of controls varies by instrument and view, but the most commonly used controls are in the group labeled Call Tree, which is active whenever a tree of call stacks is displayed in the table.
These commands are similar to the stack data-mining options available in Shark:
- Separate by Thread. Call trees are normally merged with no regard for which thread the calls occurred in. Separating the trees by thread will help you weed out calls in threads you aren't interested in.
- Invert Call Tree. The default (top-down) presentation of call trees starts at the runtime start function, branching out through the successive calls down to the leaf functions that are the events the instrument records. Checking this box inverts the trees so that they are bottom up. The displayed tree begins at the "event" function, and branches out among its callers, thus aggregating call paths to bottleneck functions.
- Hide Missing Symbols. Checking this box hides functions that don't have symbols associated with them. If you can't determine what they are, they probably aren't part of your code. (If they are part of your code, turn off symbol stripping in your build.)
- Hide System Libraries. This skips over functions in system libraries. Reading the names of the library calls may help you get an idea of what is going on; if you are looking for code you can do something about, however, you don't want to see them.
- Show Obj-C Only. Checking this narrows the list down to calls made from Objective-C methods, whether in system libraries or not (another way to cut out the possible distraction of calls you don't care to see).
- Flatten Recursion. This lumps every call a function makes to itself into a single item. Recursive calls can run up the length of a call stack without being very informative.
You can also add call-tree constraints, such as minimum and maximum call counts. The idea is to prune (or focus on) calls that are not frequently made. Another constraint that may be available (for instance in the Sampler instrument) can filter call trees by the amount of time (minimum, maximum, or both) they took up in the course of the run.
Of course, another way to filter call trees is to restrict your attention to a particular time span, such as between the open and close calls on a particular file (which the File Activity instrument would landmark for you). Use the playback head and the Inspection Range control to select the beginning and end of the period of interest, and the call tree will reflect only the calls made between them.
The Extended Detail Pane
The Extended Detail pane (7) typically includes a stack trace when you select an item in the Detail pane that carries stack information. When the selected item is part of a call tree, the Extended Detail pane shows the "heaviest" stack, the one that accounts for the most of whatever the instrument keeps track of. Selecting a frame in the call stack highlights the corresponding call in the call-tree outline. Double-clicking a frame opens the corresponding source code in Xcode, if it can be found.
A stack trace in the Extended Detail pane has an Action () menu at the top. Most commands in this menu have to do with how the calls in the trace are displayed. An example is Color by Library, which tints each call frame by the library file (including an application's main executable) that the call came from.
A couple of items in the Action menu are of particular interest. Look Up API Documentation acts like Option-double-clicking a symbol in Xcode: Select the frame, select the command, and be directed to its documentation in Xcode's Documentation window. Trace Call Duration creates a new instrument in the current document to record the stack trace when the function was called, and how long it took to execute.
Three additional controls are to be found at the bottom-left corner of the document window (8) (see Figure 26.6).
Figure 26.6 The controls at the lower left corner of a trace document window, with the Action menu displayed.
The first is an Action () menu that affords yet another means to start recording or looping, and to control the visibility of the Detail and Extended Detail panes, and the Library window. There is a submenu for selecting an instrument to add to the document. The Spin Monitor item is a toggle; when it's checked, Instruments will automatically add a Spin Monitor instrument to the document whenever an application being traced hangs.
The second is the Full Screen toggle. Instruments' extensive display eats up a lot of screen area, and when you're concentrating on your analysis, you want the display to be as big as possible. Clicking this button fills the screen with the contents of the window. Click it again to return to normal windowing.
The third button shows and hides the Detail pane.