Interpretation of results of "Energy Usage" instrument tool - ios

I am running "energy usage" instrument over ios application using a device, I wanted to use it to check how much battery is getting drained because of the app I am testing. It shows "Energy usage level" which is giving me numbers like 13/20 , 12/20 , etc over different points of time.
How to interpret the results(I know, it gives relative energy usage on a scale of 0-20) in terms of :
1) How much battery is getting drained because of the app and particular operation.
2) Which operation / function is causing this drain.
3) What number is considered as safe and what number should be considered as high / too high.
4) Any other conclusion that we can make ?
I would appreciate if some one can answer above questions or give me link for reference. I have searched around and could not find answers to above questions, I just found how to find out those relative energy usage numbers only.

My 2 cents:
1) You can create a UIAutomation script to repeatedly run some actions, and collect 'energy usage' upon each action. So that you can say "if make a call of 5 minutes, it takes xxx battery", "if keep navigating for 5 minutes, it takes xxxx battery".....
2) As I mentioned above; You can collect data against each action
3) I would say, try to find similar apps, and bench mark, compare with theirs.
4) Try to use different devices, iOS, and you can probably tell customers that what device/iOS is minimal required or recommended.

Energy Diagnostics reports power consumption number (we call them "electricities" at my office) are fairly unreliable. Powergremlin gives you some insight into the actual numbers that make up said "electicity" units. That won't answer parts 2-4 of our question, but it does provide more detail and accuracy than Energy Diagnostics.

The scale of Batter Consumption of IOS App is given by max 20 points.
if your app is running at 1/20,it means your app takes 20 hours to complete the batter
if it is running at 20/20 it takes 1 hour to complete the full batter.

Related

Break points of load testing

My application is overloaded or not able to do actions after some time what type of errors we will have and how do we identify breakpoints of application with the load test. what types of tests we can do to identify breakpoints. thanks in advance
If you're wanting to overload a web front end application you can try set up concurrent users in a selenium test and seeing how it might break.
If you're wanting to test back end applications then you could write unit / integration tests in a multi-threaded approach and hit it with a lot of queries.
Your question does however need to be a bit more specific or provide some additional info though.
There are 2 main performance testing types:
Load testing - when you put the system under anticipated load, i.e. exactly mimic its real usage by real users and check whether it is capable of supporting X concurrent users providing reasonable response time
Stress testing - when you identify the application under test boundaries and breaking points by putting it under heavier load. I.e. start from anticipated number of users (if you don't have an "anticipated" number - start from 1) and gradually increase the load at the same time keeping an eye on performance metrics.
Ideally when you increase the load by factor of 2x the throughput (number of requests per second) should increase by the same factor. When you increase the load but throughput does not increase it means that you found so called saturation point - it is basically the maximum number of users your system can efficiently support prior to degradation.
If you continue increasing the load you will observe increased response time. Also errors can start occurring. When response starts exceeding the maximum defined in NFR or SLA - you can call this "breaking point".
There is also one more "interesting" performance testing type - Soak Testing which is basically the same as Load Testing (or a little bit more users) but for prolonged period of time, this way you can detect the majority of memory leaks.

Power consumption of an iOS application

I want check power usage of my iOS application.
I tried with the Instruments.
In the 'Energy Usage Level' it shows values 1/20 (0 to 20),indicating how much energy your app is using at any given time.
What the value meant 0 to 20?.
And how Can I export the value in to text document
Edit : How can I convert it to percentage of energy usage ?
What Apple mentioned is the following :
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.
the numbers are subjective it just can be used as an indicator on how high your usage is, thats all.
the link also provides a way to log the energy usage level.

Is "Running Time", "CPU Usage" a useful metric under Instruments to draw any conclusions?

Have profiled an app on an iPhone 4 using "Time Profiler" and "CPU Monitor" and trying to make sense of it.
Given that execution time is 8 minutes, CPU "Running Time" is around 2 minutes.
About 67% of that is on the main thread, out of which 52% is coming from "own code".
Now, I can see the majority of time being spent in enumerating over arrays (and associated work), UIKit operations, etc.
The problem is, how do I draw any meaningful conclusions out of this data? i.e. there is something wrong going on here that needs fixing.
I can see a lot of CPU load over that running time (median at 70%) that isn't "justifiable" given the nature of the app.
Having said that, there are some things that do stand out. Parsing HTTP responses on the main thread, creating objects eagerly (backed up by memory profiling as well).
However, what I am looking for here is offending code along with useful conclusions solely based on CPU running time. i.e. spending "too much" time here.
Update
Let me try and elaborate in order to give a better picture.
Based on the functional requirements of this app, I can't see why it shouldn't be able to run on an iPhone 3G. A median CPU usage of around 70%, with a peak of 97% only looks like a red flag on an iPhone 4.
The most obvious response to this is to investigate the code and draw conclusions from that.
What I am hoping for is a categorical answer of the following form
if you spend anywhere between 25% - 50% of your time on CA, there is something wrong with your animations
if you spend 1000ms on anything related to UIKit, better check your processing
Then again, maybe there aren't any answers only indications of things being off when it comes to running time and CPU usage.
Answer for question "is there something wrong going on here that needs fixing" is simple: do you see the problem while using application? If yes (you see glitches in animation, or app hang for a while), you probably want to fix it. If not, you may be looking for premature optimization.
Nonetheless, parsing http responses in main thread, may be a bad idea.
In dev presentations Apple have pointed out that whilst CPU usage is not an accurate indicator in the simulator it is something to hold stock of when profiling on device. Personally I would consider any thread that takes significant CPU time without good reason a problem that needs to be resolved.
Find the time sinks, prioritise by percentage, and start working through them. These may not be visible problems now but they will begin to, if they have not already, degrade the user's experience of the app and potentially the device too.
Check out their documentation on how to effectively use CPU profiling for some handy hints.
If enumeration of arrays is taking a lot of time then I would suggest that dictionaries or other more effective caches could be appropriate, assuming you can spare some memory to ease CPU.
An effective approach may be to remove all business logic from the main thread (a given) and make a good boundary layer between the app and the parsing / business logic. From here you can better hook in some test suites that could better tell you if the code is at fault or if it's simply the significant requirements of the app UI itself...
Eight minutes?
Without beating around the bush, you want to make your application faster, right?
Forget looking at CPU load and wondering if it's the right amount.
Forget guessing if it's HTTP parsing. Maybe it is, but guessing won't tell you.
Forget rummaging around in the code timing things in hopes that you will find the problem(s).
You can find out directly why it is spending so much time.
Here's the method I use,
and here's an (amateurish) video of it.
Here's what will happen if you do that.
First you will find something you would never have guessed, and when you fix it you will lop a big chunk off that 8 minutes, like maybe down to 6 minutes.
Then you do it again, and lop off another big chunk.
You repeat until you can't find anything to fix, and then it will be much faster than your 8 minutes.
OK, now the ball is in your court.

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.

In iOS, how do I get the current CPU Utilization from inside an app that is running?

I'm looking for a way to get the CPU Utilization numbers like in Instruments and Activity Monitor with C/C++/Obj-C so I can do some automated testing with it. I'm looking for somewhere around a 1 second granularity, though 100 ms would be ideal. Another way to look at this question would be "How does Activity Monitor get the info it gets?".
Here's what I have found out so far:
Many of the *nix equivalents don't seem to work with iOS
sysctl
doesn't have KERN_CPTIME
iOS doesn't have the proc filesystem so I can't use
/proc/stat.
This eliminates a lot of programs like vmstat and iostat
MacOSX's
sample
doesn't exist in iOS.
I found out the answer. There is an undocumented API, host_processor_info() with the PROCESSOR_CPU_LOAD_INFO flavor, that can give you the number of system, user, nice, and idle ticks. You have to subtract the number of ticks from a previous call to it to get the current CPU utilization. Remember to call vm_deallocate on the array you get.
You cannot. The standard Un*x access to this information is not available within an iOS app.

Resources