HowTo - Using XCode Instruments to test your iOS app
If you have a memory intensive game, it is good practice to use Instruments to analyse how your game behaves on different devices.
The rule of thumb says that your game should not load more than 50% of available memory in game data and images. The reason for this is that it needs room to shuffle and reorganise memory as assets get swapped out of memory.
Steps 1 and 2 are also useful for those who would like to know how to load an adhoc build on their device.
Step 1 - Generating your game
Publish your game to GameSalad, then generate and sign your game.
Make sure to only use a "Development Profile" to sign your game. Adhoc profiles will not be recognised by Instruments.
Step 2 - Loading your game on your device
Connect your mobile device to your Mac and open the Device Browser from XCode
In Devices, select your connected mobile device, then find your signed game and drag it to the Installed Applications list.
Step 3 - Launch Instruments
Start Instruments from the XCode menu
When the main screen of Instruments is displayed, select "Allocations" as the template.
Step 4 - Selecting your device and game
Once the Instruments panel is loaded, you need to first select your mobile device and then the game your wish to analyse.
Do not have the game running at this time.
Step 5 - Testing
To start testing, press the record button in Instruments. This will automatically launch your game on the device and start collecting statistics.
What to look at
Apart from the mesmerising graph, it is important to keep an eye on the "Persistent Bytes" and "#Persistent" columns.
The "Persistent Bytes" column shows the memory really needed by your game at that given moment.
The "#Persistent" column shows the memory that is actually used, both by necessary data and data that is waiting to be released or swapped out. This is the number that will crash your game if it grows too big in relation to device memory. It is important to note that your game needs to leave a large portion of memory free for other system purposes. Therefore the rule of thumb "only use 50% of available memory".
What you can do
If the "#Persistent" column grows much larger than the "Persistent Bytes" column, then it is an indication that something is not well. It may be due to memory leaks, which is out of our hands.
(pre GS v 0.14)
It may also be that your images are too large, making the swapping out of images from memory problematic, even leading to the game crashing. Memory gets fragmented as images get loaded and unloaded. If there is no room to load needed images, memory needs to be reshuffled, leading to lag in the game.
Thus, avoid large images if you can. Break them into smaller sections and assemble them on the scene. It is easier playing tetris with 1x1 blocks that 16x16 blocks. Both for your device and you.
(post GS v 0.14)
From this version onward, we will not have to worry about the size of individual images any more. The new rendering engine will produce a sprite sheet of all of our images. Each sprite will have 64x64 pixel dimensions.
Instead if the old maxim of keeping image dimensions at factors of two, we now should just try to keep our image dimensions multiples of 64 pixels.
Comments
Excellent stuff @Hopscotch !
Cool, nice step by step instructions. Easy to follow!
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Thanks @Socks, @jamie_c !
I added a "What to look at" and "What you can do" section.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch I didn't know how to use the Xcode instruments. Thank you.
Thank you for the easy to follow instructions.
Fortuna Infortuna Forti Una
Going beyond the call of duty once again @Hopscotch. Awesome. Thank you!
Geez Im glad there are GS users that know about this sort of stuff. The tools are apparently there. Thanks for this thread. Just like the assets threads...these kinds of threads shoukd be compiled and added somewhere...somewhere very sticky
Complete Guide to iOS Publishing {} Complete Guide to Mac Publishing
Thank you! Coming from only knowing Android testing (just email the signed apk and click on the attachment), I've been lost with my new iphone 6+. Your beginning excellent instructions showed me how to put the app on my device, and now I can easily test it!
Great that it is of help.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Thank you for saving so much time for me!!
@Hopscotch thanks!!
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
Great info!
Transient "All Heap & Anonymous VM" grows indefinetely, even doing nothing at all.
Have you seen this?
Transient means memory that was allocated then freed. Persistent is generally the only important value since that is what is in-use at the time. Due to some lua changes the allocations view is usually quite inaccurate since the memory is allocated in a way it cannot track. The Real Mem stat in the activity monitor is closer to accurate but still not quite all of it.