Reliable CPU Usage Measurements on iDevices

This article is meant for advanced users and programmers.

Today, I've started investigating the CPU usage of the software decoders of the iOS multimedia players I'm reviewing for my forthcoming iOS Multimedia bible. (Of which the work-in-progress feature & benchmark measurements chart, in OpenOffice format, is already public. It's quite a bit messed up (again, it's a chart I'm actively working on) but you may already find answers to even your most unique questions.) For this, I've reviewed all the CPU measurement techniques available on iOS – a very important parameter of the players if you want to have as good battery life and low device temperature as possible. (There may be huge differences in the efficiency between even custom audio – for example, OGG or WMA – decoders, let alone video ones.)
Old methods: deriving CPU usage from charge level drops & AppStore-based “Benchmark” app

Simply tracking battery usage by running each test for at least an hour(!) to gain already somewhat reliable results and checking out the before/after battery charge levels is far too time-consuming. The “Benchmark” app I, back in 2008-early 2009 (see for example my Internet Radio roundup), used for CPU usage tracking is pretty much useless when benchmarking video decoding. (Nevertheless, the app still works pretty reliably on the latest iOS versions. It has long been removed from the AppStore, it seems, so don't even try looking for it.)

All in all, these approaches are not recommended – there are much better ones.

Instruments

First and foremost, if you have a Mac and also have a paid developer account, which means you can deploy apps from Xcode on your iDevice(s), your best friend will be the built-in Instruments. Start it and select “Activity Monitor” from the default “iOS” group:



Then, select “All Processes” from the “Target” drop-down list in the upper right (by default, it reads “Choose Target”). Now, you can click the now-enabled “Record” button and start investigating CPU usage in the lower right pane. (I recommend sorting it by CPU.) An example showing GoodPlayer (my favourite media player) playing back the standardized test demo “Suzumiya”:



The above method is by far the best:
- it doesn't require jailbreaking and, therefore, works with the iPad 3, all iOS versions of iPad 2 and iPhone 4S etc.
- it can sample an application running in the foreground (an absolute must if you benchmark video players)

Of course, if you don't have a Mac and/or don't have a paid dev account, you're pretty much shot. Then, you might want to examine the alternatives described below.

MobileTerminal / SSH / ps / top

If your device is jailbroken, you may already installed either OpenSSH or MobileTerminal (or both). (Note: if you go for the latter, you'll need to follow the steps I've outlined in THIS article.) To set up the former (the recommended approach, as it doesn't need to be run in the foreground), just follow the steps explained in the front page of Cydia, under “OpenSSH Access How-To”, annotated in the following screenshot:



As soon as you gain access to the command prompt, either local (MobileTerminal) or remote (OpenSSH), you'll notice the standard jailbroken distros lack the “ps” command, which, at least on “full” OS'es like Mac OS X, is needed to quickly check out CPU usage. It needs to be installed separately from Sections > Administration > adv-cmds. However, there's no “CPU” or “STIME” column in the iOS build of PS (check out THIS for more info on handling them) so it's completely useless for our purposes.

Top” for the rescue! While it's pretty much useless under Mac OS X (as opposed to the just-discussed PS), it delivers the same (very good) constantly-updated CPU usage results on iOS as Instruments. A screenshot of this (again, showing the CPU usage during Suzumiya decoding):



Top” is in the “top” package under Sections > Administration in Cydia. As with  adv-cmds, it's only available if you've declared yourself to be a Developer at initially starting Cydia. If you haven't, you can always change it by going to Sources > Settings.

BatteryDetective

I've also purchased the Cydia app “BatteryDetective” ($2) only to find out that it's either totally incompatible with my iPad 2 running iOS 5.0.1 or is plain useless, at least for monitoring the CPU usage of individual processes. At least I've got wildly different and contradicting values when, for example, benchmarking the battery drain caused by the built-in, always-running Mail and FaceTime processes. The battery measurement value I got after sampling GoodPlayer was also useless and orders of magnitude below the real power usage of the app.

However, there are certain advantages of the app: for example, it shows the cycle count of the battery (closely correlated to the remaining, maximal capacity), which is indeed unique:



 But, for this, unless you absolutely hate ads, you can also use the free(!) BatteryInfo Lite, also available n Cydia. I heartily recommend the latter (unlike with the former, which I couldn't really use for anything)!

iStat

This app is (still) available in the AppStore (unlike “Benchmark”) and, to some degree, it's also capable of displaying (total) system CPU load - see the annotated area in the following screenshot:



This shows the app's display when playing back the audio track of the standard test video “Monsters”.

With both CPU cores used at 100% (for example, GoodPlayer crashing after returning from playing a 1080p MKV's audio track in the bacground and, then, tapping Done), the first value is around 2.5.

The disadvantage of this app compared to all the other ones is that it's VERY slow to decrease to around 0.5-0.7 (the first number in the “Load” section) after the real load is gone, that is, the CPU-intensive app is closed. Also, by its nature, it can't run in background and, therefore, can't be used to benchmark for example video stream decoding (as opposed to audio). However, if you absolutely don't have access to a Mac with Instruments or can't / don't want to jailbreak, it might still become handy.

 

UPDATE (May/23/2013): Today, “top” has turned out to be of great help.
 
My (old bootrom) JB'n iPhone 3GS running the latest iOS version (6.1.3), which I only keep for development / lecturing purposes (without even a SIM card), has shown the typical signs of something's using the CPU all the time, draining the battery very fast and making the phone both warm and sluggish. “Top” has shown the following:
 
As you can see, it was “locationd” that has continuously used the 100%.
 
I've quickly found out that it wasn't any location service or automatic time update service (all disable-able from Settings – disabled them all for test) that forced it to continuously use the CPU. Neither did any jailbreak tweak (tested this by just running Cydia, which disables most JB tweaks). After a while, I've found out it was iCloud. After a disable in Settings (with deleting local synchronized stuff) and re-enable it with all the features (including Where's my Phone), the problem was gone.
 
During all this time, continuously watching the results returned by top was of great help. I could immediately see the effects of dis/enabling a certain, location-specific feature of iOS, third-party apps or JB tweaks. Without this, it would probably have taken days to find out it was iCloud that caused the problems.
Master your iPhone in one minute a day: Sign up here to get our FREE Tip of the Day delivered right to your inbox.

Topics

Author Details

Author Details

Werner Ruotsalainen

<p>Werner Ruotsalainen is an iOS and Java programming lecturer who is well-versed in programming, hacking, operating systems, and programming languages. Werner tries to generate unique articles on subjects not widely discussed. Some of his articles are highly technical and are intended for other programmers and coders.</p>
<p>Werner also is interested in photography and videography. He is a frequent contributor to not only mobile and computing publications, but also photo and video forums. He loves swimming, skiing, going to the gym, and using his iPads. English is one of several languages he speaks.</p>