Core Animation debug mode
If you’re into optimizing scrolling or drawing performance on the iPhone, then you know that blended layers (ie, non-opaque) can really slow things down. Sometimes it’s hard to know what is opaque and what is being blended, however.
The good news is that there is a tool for this! You can easily get a visual readout of all of the layers in your app and their blending. Here is an example:
The red areas are being blended, whereas the green areas are totally opaque, giving the best performance.
Here’s how to set it up:
Debug Mode On-Device
Open up the Instruments tool, and select an iPhone or iPod touch as the applicable device, then add a new Core Animation instrument.
You’ll then need to show Detail (View > Detail, or the button in the bottom bar). Then there is a checkbox for “Color blended layers.” This is what you want.
Your iPhone or iPod Touch should now switch into red-green mode. This setting is persistent, so you can detach your phone and use it now. To disable, attach to Instruments again and uncheck the box or restart the phone.
Debug Mode in Simulator
Turns out, there is an easier way! You can do all of this fun in the simulator. Just launch it with the CA_COLOR_OPAQUE environment variable set:
CA_COLOR_OPAQUE=1 /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator
And, boom! You can now run your apps as usual using Xcode and they’ll show up in the simulator with color blended layers enabled. To disable it, just quit and relaunch Simulator.




[...] Andrew Pouliot comes a great tip about using the Core Animation debug mode both on a touch device or in the simulator. This really [...]
Pingback by iPhone Dev Tip: Core Animation debug mode » señor taco’s travels — June 29, 2009 @ 1:32 pm
With this trick, i’m building a really fast table view with grouped style and custom background images.
Thanks
Comment by Dzamir — July 1, 2009 @ 4:22 am
Killer trick! Thank you much for sharing. I’ll definitely be using this over always having to tether a device.
Comment by Jake Behrens — September 18, 2009 @ 8:03 pm
Yeah this is great. Made an automator application to run this command and copied and pasted the icon from the iPhone simulator on it. Now I have a iPhone Debug Mode Simulator application.
Thanks man.
Comment by Eric Boehs — September 18, 2009 @ 8:35 pm
@Eric Boehs—
can you tell me how do i set this environment variable? or if you can give me your app it will be helpful for me.
Comment by rahulvyas — October 31, 2009 @ 2:51 am
rahlvyas - you export an environment variable before launching it from the shell or a script. E.g.:
> export CA_COLOR_OPAQUE=1
> /Path/To/Simulator &
I first heard of this technique Jake Behren’s interview at MobileOrchard Episode 360iDev Episode 27, it’s great. Some of the other debug options like “Flash updated regions” are useful when considering how drawrect: could be finetuned too.
Comment by Robert Clark — November 22, 2009 @ 10:15 pm
Awesome… very fantastic theme. I will blog about it as well!
Comment by Leffreedo — December 11, 2009 @ 1:47 pm