Analyze iOS App Power Usage - ios

My app currently shows up at around top 5 in power usage under settings->Battery. On that screen it says the app spends many hours in the background. Ive tried using Instruments however the analytics provided are not enough to draw any meaningful conclusions or pinpoint any sections of code. Any suggestions how to further investigate power consumption. A tool that ties power consumption to specific source code would be the best?

I would use Xcode Instruments - Energy Diagnostics for what your looking for.
The process is - Open instruments and load the "Energy Diagnostics" template. From there, you record data in instruments and use the app. After your finished you can analyze the data.
Also, right in Xcode you can use the Energy Debug Tool now:
Debug Energy During Development
The debug navigator in Xcode includes an Energy Impact gauge, which
provides a high-level overview of energy usage as you test your app.
Consult this gauge regularly throughout your app’s testing cycle to
assess your app’s energy impact and identify potential problem areas
up-front. If necessary, dive into Instruments for more in-depth
analysis.
This will give you a good starting point to diagnose, from there you may need to look and analyze deeper (Activity Monitor, File Activity, Time Profiler, etc..) in Instruments.
Here is a User Guide from Apple on how to do this in greater detail and it also shows how to analyze the data using Instruments.

Related

Continuous allocation of 500kb from libBacktraceRecording.dylib

I have a problem in iOS application that I am currently developing.
While running applications I am continuously having mysterious allocations of ~500kb.
I used instruments to track these allocations down, but the results are above of my knowledge.
So the instruments results looks like that:
As you can see there is continuos growth. Each "Generation" shows growth of approximately 500-600kb.
When I look into generation I see that the allocated memory goes to VM: Performance tool data:
If I go deeper inside I see that the responsible library is libBacktraceRecording.dylib:
And then if I want to check the responsible for allocation place in my code sometimes I see calls which are related to GCD:
And sometimes I get some kind of Stack Trace which doesn't directly relate to my code:
What could be the reason of these allocations?
It is not big amount, these 500-600 kb, but as it keeps growing after some time it kind of makes me worried.
As I understand these allocations probably are not caused by me but by some kind of xCode performance monitoring tools or something like that. But is it true?
And why it keeps growing without limit?
GMSPhoenixRenderer is the Google Maps rendering engine. More likely than not, it is gathering statistics related to performance or, as you say, it is the iOS dev tools doing so on its behalf.
You'll have to look in the GM* API to see if there is some way of disabling this. I would suspect it is only turned on in DEBUG builds.

Where can I find the Memory Monitor Instrument on the Mac?

I am having a hard time debugging memory crashed on an GPU-intensive app.
This answer talks about the Memory Monitor Instrument:
https://stackoverflow.com/a/10951144/1167349
So does this docu page from Apple:
https://developer.apple.com/library/ios/documentation/AnalysisTools/Reference/Instruments_User_Reference/MemoryMonitorInstrument/MemoryMonitorInstrument.html
However, when I open up Instruments, there is no Memory Monitor to select:
(yes, I also used the scroll bar)
When I open up the Library, I can not find it there, either. Although the "VM Tracker" and "Shared Memory" instruments have the same icon, they do not provide the same functionality:
Am I missing something really obvious here??
I am using XCode Version 6.1.1 and Instruments Version 6.1.
Thank you a lot for all answers!
Select the Activity Monitor template. Older versions of Instruments had separate monitoring instruments for activity, memory, network usage, and file usage. In Xcode 6 Apple combined these monitoring instruments into one Activity Monitor instrument that you can configure to show the data you are interested in, which is memory usage in your case.
The Activity Monitor instrument is not initially set to graph memory usage. You will have to go to the Record Settings section of the detail view on the right side of the trace window and tell the instrument to graph and list memory usage.

app works fine on iPad 2, crashes on iPad 3, with low memory warning

as the title says, I have an app which works on iPad 2, but crashes on iPad 3. when running it the console gives me a low memory warning message. When the crash happens I symbolicate it, but there's really nothing that I can relate to the code, like it shows
process name, UUID, rpages, recent_max, [reason] (state)
and under those column headers just hexadecimal stuff, nothing showing method calls or lines in the project.
Any ideas? am I missing some flags in the code that allows for a better crash log?
Thanks.
If you're getting low memory warnings and fail to release enough memory to resolve the issue, your app will almost certainly crash. The thing is, I don't think that the particulars of how or why it crashed can possibly be illuminating. At that point, you're evaluating secondary symptoms. You really need to go back and figure out why you got the low memory warning in the first place and fix that problem.
As Daniel said, you can look at Technical Note 2151, but as it says:
When you see a low memory crash, rather than be concerned about what part of your code was executing at the time of termination, you should investigate your memory usage patterns and your responses to low memory warnings. Memory Allocations Help lists detailed steps on how to use the Leaks Instrument to discover memory leaks, and how to use the Allocations Instrument's Mark Heap feature to avoid abandoned memory. Memory Usage Performance Guidelines discusses the proper ways to respond to low-memory notifications as well as many tips for using memory effectively. It is also recommended that you check out the WWDC 2010 session, Advanced Memory Analysis with Instruments.
So, a couple of thoughts:
Have you looked for leaks? The Finding Leaks article walks you through how to use instruments to find your leaks.
If you turned on zombies, have you turned them off? Zombies is a great diagnostic tool, but just consumes memory.
Have you run your code through the static analyzer (shift+command+B or select "Analyze" on the "Product" menu)? Especially if using non-ARC code, this can find lots of memory issues.
Have you examined your allocations for unexplained increases without offsetting decreases with the Instrument's Allocations tool. Using that, you can run the program, look at the consumption of memory on the graph and see if you see any increases that aren't offset at some point by the corresponding decreases. And if so, highlight those increases in the graph:
For example, when running the Allocations tool, hold down the option key and then click-and-drag with your mouse to highlight a portion of the timeline, to identify what you want to inspect. You probably want to focus on one of your spikes in allocations. For example, I found a bump in my allocations and highlighted it as such (this was a ludicrously simple example where I create a huge array in viewDidLoad, but hopefully it give you the idea):
Note, I find it useful to show the call tree in the lower panel, it's often useful to select "Hide System Libraries", to focus on your code (and "Invert Call Tree", too). And if you double click on the method name in Instruments (in my example, here, it would be viewDidLoad), Instruments will then show you your code that's doing the allocation:
Low memory warnings generate a different kind of log than standard crashes. Take a look at the "Understanding Low Memory Reports" section of this article to understand what happened with your application and how you can debug it using Instruments: http://developer.apple.com/library/ios/#technotes/tn2151/_index.html

Explain the statistics of Energy Usage Instrument in iOS

I am trying to find Energy Usage for my iOS App using Instrument.
I got the statistics like Time, Total Activity, Foreground App Activity, Audio Processing and
Graphics in Percentage format. The sum of Foreground App Activity, Audio Processing and
Graphics is different from Total Activity !
But I am not understanding what are the meaning of these columns? Can anybody please explain me the meaning of these statistics and how to use this?
Latest Energy Diagnostics documentation says:
The Energy Usage instrument shows a level from 0 to 20, indicating how
much energy your app is using at a given time. These numbers are
subjective. If your app’s energy usage level is occasionally high, it
doesn’t necessarily mean that your app has a problem. Your app may
simply require more energy for some of the tasks it performs. For
example, it may use GPS while performing complex network operations.
This is valid energy use. What you should look for are spikes or areas
of high energy use that are unexpected or that could be performed at
more optimal times.
yes, sure there is difference. The best way to use it; do one at a time. observe each Activity Consumption and target optimizing that.

iOS Testing with Instruments - Best Practices

Since I'm developing iOS based applications, I'm also spending much time on getting started with testing applications and debugging performance issues.
After reading the instruments user guide, I'm now able to detect memory leaks, record the current memory size and cpu-usage and much more, which quiet helps a lot!
Now, in order to improve my testing strategy, I'm looking for a kind of bench mark values or standard values for the different instruments (such as cpu- usage, energy consumption, ...). You know what I mean? For example: I have a cpu-usage of 80% over a period of 10 seconds. Is that okay or should I think about performance optimization? Sure, in case of cpu-usage, it depends on the action that the app does over that period of time (e.g. reloading some data or something like that) but is there any rule of thumb or best practices for that?
I already did a research on the internet and only found a video of the iOS tech talk in london from Michael Jurewitz. In that talk, i figured out the following statements that are properly useful for me:
Activity Monitor: Can only be used to compare your app's resource usage to other apps
Allocations: A constantly growing allocations chart is obviously a bad sign for memory leaks. Allocations does not show the real memory size the app uses
VM Tracker: Show overall memory size; Rule of thumb: more than 100 MB dirty size of an app is far too much
...
Now I need some "rules of thumb", especially for the CPU Monitor (where is the boundary between good case and bad case?) and Energy Consumption (Level..?).
Do you have any tips for me or do you know some articles I can read through?
Thanks a lot!
Philipp

Resources