14
Debugging Tools

In Chapter 7, you learned about using the debugger to find and fix problems in your code. Now we are going to look at other tools available to iOS programmers and how you can integrate them into your application development.

Gauges

Xcode 5 introduced debug gauges that provide at-a-glance information about your application’s CPU and memory usage.

Open your TouchTracker project and run it, preferably on a provisioned iOS device rather than the iOS Simulator. In the navigator, select the Gauges tab to open the debug navigator.

Figure 14.1  Gauges

Gauges

While the application is running (not paused or crashed), the debug navigator shows CPU and memory gauges (Figure 14.1). Each of these shows a live-updating graph of resource usage over time, as well as a numerical figure describing that resource’s current usage.

Important note: these gauges scale based on the hardware that is actually running your application. Your Mac has much more available RAM and likely more CPU cores than iOS devices do, so if you run your application in the iOS Simulator, your CPU and memory usage will appear to be very low.

Click on the CPU Debug Gauge. This will present the CPU Report in the Editor pane (Figure 14.2).

Figure 14.2  CPU report

CPU report

The report contains four basic sections:

Percentage Utilized

shows your CPU utilization relative to the number of CPU cores your device has. For example, dual-core devices will show CPU usage out of 200%. While your application is idle, this should read 0%.

Utilization Comparison

allows you to see your application’s CPU usage as it impacts the rest of the system. At any given time, your application is not the only cause of activity on the device. Some applications may be running in the background, putting their own pressure on the system. If your app feels slow but is not using much CPU on its own, this may be why.

Utilization over Time

graphs your application’s CPU usage and shows how long the application has been running, as well as peak and trough usage values over the course of the current run.

Threads

shows a the breakdown of the Utilization over Time graph on a per-thread basis. Multithreading is outside the scope of this book, but this information will become useful to you as you continue your iOS development education and career.

To make the graph a bit less boring, begin drawing a line but continue moving your finger without ever letting the line lock into place. This will cause a sustained spike in CPU usage.

Why? Each point on the screen that your finger moves on causes a turn of the application’s run loop beginning with a touchesMoved:withEvent: message, which in turn causes drawRect: to be sent to your BNRDrawView instance. The more work that you do in these methods, the more CPU utilization your application will require while lines are being drawn.

Next, in the debug navigator, click on the Memory Debug Gauge to present the Memory Report (Figure 14.3).

Figure 14.3  Memory report

Memory report

Like the CPU Report, the Memory Report is broken down into easy-to-read sections. Do not be alarmed if your Memory graph (the bottom section) appears to be at 100%; this graph scales so that your peak memory usage represents 100% visually.

It is a general goal of software development for any platform to keep both CPU and memory utilization as low as possible, to maximize application performance for the user. It is a good idea to get in the habit of checking these gauges and reports early and often in your projects so that you will be more likely to notice when a change that you have made to your code has resulted in an unexpected change in your application’s resource usage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset