Saturday, September 5, 2009

Debugging Drawing

Apple has a nice little utility called QuartzDebug in /Developer/Applications/Graphics Tools, and one of the features of this program is that it will highlight all redrawing that gets done in every application. Every time a view is redrawn, it flashes. This is a great tool for determining if you're doing unnecessary drawing in your drawRect: method, or if you're somehow triggering unneeded redraws some other way.

I've had a lot of people ask me about doing this on the iPhone. I've been told by several people that they saw this functionality demonstrated at the iPhone tech talks, which had me stumped. I completely forgot that you can get very similar functionality by passing an argument called NSShowAllDrawing to your application on launch. This is mentioned in this excellent technote on debugging.

Michael Fey has a (somewhat holder) blog post, complete with video, that shows how to use NSShowAllDrawing. His example shows using it in a Cocoa application, but the process is exactly the same for using it in an iPhone application.

Update: A couple of people pointed out in the comments that this option is also available using Instruments. If you run with the Core Animation template, there's a checkbox labeled "Flash Updated Regions", which is checked in the screenshot below:



I haven't been able to get the Core Animation template to work for me on the Simulator, though. I'm not sure if that's by design, or a problem with my installation.



12 comments:

Dzamir said...

There's a simpler solution:
Run -> Run With Performance Tool -> Core Animation
From Instruments make sure that "Flash Updated Region" is checked.

Jeff LaMarche said...

Dzamir:

The Core Animation performance tool is greyed out for my iPhone projects.

ejalbert said...

Jeff, I'm surprised the Core Animation tool isn't working for you. Try launching Instruments and selecting the iPhone version of the Core Animation tool and see if that works. We added it to address the scenario you posted about, so it really should work, and if it doesn't, please file a bug. Thanks!

Danny said...

When I try to use Quartz Debug with iphone simulator, no mater what, the entire screen always flashes which doesn't seem right. Am I doing something wrong or is it because the actual simulator is flashing updates. Is it then not possible to use this tool with the simulator ?

Jeff LaMarche said...

ejalbert:

Let me clarify - when my active SDK is Device, I have the option to use the Core Animation template, but not when the device is Simulator.

It works fine on the device, though.

ejalbert said...

Interesting...I'm a bit surprised it doesn't work in the simulator. Can you file a bug? We'll take a look at it.

Jeff LaMarche said...

Eric:

I'm happy to file a bug, but I have a sneaking suspicion that the problem may be with my dev tool installation. I'm having some other problems that other people don't seem to be having (e.g. problems opening .xcdatamodel files from 3.0 in 3.1). I've just been too lazy to do a clean re-install because I'm so far behind on my book right now.

If the problem persists after reinstall, I'll file a bug, but I don't want to make somebody chase down a problem on my end.

Thanks for the help.
Jeff

Danny said...

Actually I get the same thing. For simulator it's grayed out.

michael said...

Thanks for the link, Jeff.

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

JeansPilot said...

JeansPilot offers the chance to buy a large variety of men’s and women’s jeans clothing from the world famous Italian Brands.
Online jeans clothing store looks for original fashion clothing sales and clearances of worldwide known designers. We participate in fashion auctions to get the lowest possible price for Top quality Clothes, Shoes and Accessories.
Buy Jeans

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels