method One--Hardware detection
The power consumption of the application can be accurately obtained through hardware powermonitor.
The steps are as follows: Open the shell of the iOS device and locate the power pins on the back of the battery. Device to connect power monitor pin run apply to measure electricity consumption
The following figure shows the Power Monitor tool connected to the iphone's battery pins. Enter image description here
Refer to:Using monsoon power Monitor with IPhone 5s. The power consumption of the application can be obtained accurately. Equipment price $771.00 USD need to disassemble mobile link: https://www.jianshu.com/p/851b0acde9c3
Method Two--instruments Steps
1.iOS setup Options-> Developer Options->logging->start Recording Enter image description here
2. Go to the developer option after a scene operation that requires a test charge click Stop Recording
3. Connect iOS device and Mac
4. Open instrument, choose Energy Diagnostics
5. Select File > Import logged Data from Device enter image description
6. The data stored in the timeline output to the instrument panel in the case of power measurements, you must disconnect the iOS device and PC connection, so you can not use the UI Automation test way to perform the app operation;
2) The rate of charge sampling is 1s/times, the use level of electricity is 0-20,1/20: said that the operation of the app, battery life will have 20 hours; 20/20: To run the app, the battery charge is only 1 hours of life
The test accuracy is 5%;
3 Power test data can only be viewed through energy diagnostics instruments, can not be exported to CVS files, can not calculate the overall power consumption, average power consumption, can only manually calculate the average
method Three---api interface invocation Way
At first we used the Uidevice class Batterylevel interface. This interface will only get the remaining power percentage, and all iOS system versions available to the world today are usable, as mentioned above, he is almost indistinguishable from the values displayed on the system interface, except that he is measured in mah, and the remaining percentage of power calculated by this value is the one shown on the system. In this way, this interface does not have much meaning. We have to keep trying.
We then use the Iopmpowersource interface in Iokit, the private interface, which is invoked as follows:
The information available on iOS 10 and above is as follows:
Look at the key information:
The third line currentcapacity is the current remaining charge;
The fullycharged of the line VI is full of electricity;
Line eighth ischarging whether the charge is being charged;
Line Nineth maxcapacity maximum battery capacity;
Line tenth voltage current voltage.
The information is more, there is the current voltage value, there is residual electricity. What's the use of this? We first science a little bit of knowledge.
First, the voltage of a device is basically a variable, relatively stable value within a certain range. Like the iphone 6P voltage, basically in the 4V up and down. When the battery remains low, the voltage will become smaller, but not very volatile. Voltage over an hour, may cause the cell phone to shut down directly, this is why sometimes there are 20% of electricity, but the phone is not open machine. New batteries, voltage fluctuations will be smaller, the more aging, voltage fluctuations may be greater. So the voltage value can be used to determine the current health of the battery.
Then the remaining charge is 2548, and his unit is mah. Mobile phone batteries commonly used like 1000mAh such a logo, this is not the specific power, light to see this value, can be understood to the meaning of the current to 1000mA to discharge, can put 1 hours. Alternatively, a steady current of 200mA can be discharged for 5 hours. But this is obviously not very meaningful. Because we do not know how many MA electric current the battery will work, so we do not know how long it will take, we want to know, the battery in the end how much electricity, this is a specific value. mentioned above, the voltage is relatively fixed, we can calculate the number of specific remaining electricity to 1000mAh, rough gauge voltage stability of 4V, calculated according to the formula W=U*I*T=4V*1000MAH=4000MWH. This is the current battery's remaining charge. When calculating the percentage of the remaining power, the same value is used.
Above is the information that the Iopmpowersource interface obtains on IOS10 and above system. But in fact, on iOS 9 and the previous system, can get more and more detailed information, most of which are fixed information of some hardware, is not helpful to our test. But there are some other useful information, such as current temperature, current, are very useful information, the following figure:
Temperature can be used to directly determine the current heating situation, the current can directly determine the current battery power, can effectively determine the current use of the battery status.
But this interface to get the data, is still not specific enough, all the whole machine battery situation, not specific to an application or other dimensions of the electricity statistics. So, we have to continue to grope.
This time we are applying the plbatteryusageuiquery in Batteryusageui.bundle and also a private interface. Here to sell a case, implementation will not post, the students can be based on my key words to find specific things. This interface is very powerful, specifically, he can get every app's cpu\gpu\ display \ Network \ Storage, etc. before and after all the details, a huge table.
As we explore this step, we are excited to think that the light is in sight. But the fact is that this interface was completely blocked as early as the first version of IOS9, only to get data on a machine on iOS 8. And after many confirmation, we found that this data is updated once per hour, not in real time.
But still, it has greatly enhanced our confidence to continue to explore, and for the first time we've got the power consumption of each app, and we're pretty sure that the list of the Apple iOS is based on that data. Because, we have found in the jailbreak environment has a tool, called detailedbatteryusage, this plugin only did one thing, is the system settings, the battery display mode set to "2", and the default display mode is "0". Set to "2", you can see the battery settings in a very detailed information, the following figure:
It's consistent with the data we've got with the interface, so we're confirming that the power rating data comes to this interface, and that the system has been calling this interface to count the power-related information, but it's not visible to the user, and the interface is not visible. To get this data in a jailbreak environment, for us to locate the problem has been very helpful, but on the one hand, these data are displayed by the system, we deal with very inconvenient, inefficient, on the other hand, the data can only be taken on the jailbreak machine, and the current mainstream system is still unable to escape. We have to go further.
method Four--IOS Diagnostics What is iOS diagnostics
iOS Diagnostics is the iOS system itself with a set of diagnostic systems, in this diagnostic system also recorded the information of electricity, the information is stored in the form of SQLite, and regularly passed to the Apple server for analysis by Apple related personnel. This can be done by reading the data recorded in the iOS system for the Power test, which is provided by the iOS system, and records the power consumption of each app, so that more accurate power consumption information can be obtained.
The battery diagnostics available on Apple's website are as follows:
How to get the diagnostics power database
1. Equipment above iOS10
By looking at Apple's official Bugreport website, one of the items found is: Battery life. By looking at official documents, this way you can get the details of the Power database for iOS diagnostics, and sync to local via itunes to get the relevant power data.
Apple's official Description:
The steps are as follows:
A. Download profile using the developer account
Https://developer.apple.com/services-account/download?path=/iOS/iOS_Logs/BatteryLife.mobileconfig, installed on the phone via airdrop or email.
B. Sit down for about half an hour and sync to your computer via itunes
C. Obtaining electricity from the computer database file
The corresponding directory is as follows:
macos:~/library/logs/crashreporter/mobiledevice/[your_device_name]/
Windows:c:\users\[your_user_name]\appdata\roaming\apple computer\logs\crashreporter\mobiledevice\ [Your_Device_ Name]\
D. The electricity database starts with "Powerlog_" and ". Plsql "or". Plsql.gz "End
2. IOS9 and the following equipment
Provide a way of thinking:
can be obtained through Mitmproxy (Grab kit) + diags://123456 Intercept Interface:
https://iosdiags.apple.com/ios/TestConfiguration/1.2
The following figure:
Interpretation and analysis of electricity database
After getting the power database, all we have to do is to use the information stored in the database to help us analyze the actual usage of the app. You can download sqllitestudio.dmg to open the. Plsql database file. Download Address: Http://sqlitestudio.pl/index.rvt?act=download
Here are a few tables related to electricity:
Placcountingoperator_eventnone_nodes |
The Noteid of all applications is documented. |
Placcountingoperator_aggregate_rootnodeenergy |
Recorded the power consumption of each Noteid |
Plapptimeservice_aggregate_appruntime |
Log the running status of the app, record it once an hour |
Plbatteryagent_eventbackward_battery |
Recorded the electrical changes in the whole machine, 20 seconds record (voltage, current, temperature, etc.) |
Plbatteryagent_eventbackward_batteryui |
The total remaining power percentage of the machine is recorded and recorded once in 20 seconds. (The remaining power on the phone screen is based on this data) |
Plioreportagent_eventbackward_energymodel |
Recorded IO-related power consumption (SoC, DRAM, IPS, etc.) |