Android app power consumption statistics, no USB connection required

Source: Internet
Author: User

Android app power consumption statistics has always been a headache, manual statistics time is too long, automated statistics is not very accurate (the implementation of automation code needs to connect via USB, and USB will charge, which results in statistical data is not allowed). Later from the predecessor learned that you can use the ADB connect to achieve wireless connectivity, the following means.

1, first to find a root mobile phone

2. Make the phone and PC in the same network segment

3. Download and install wireless ADB

4. Open wireless adb, tick wireless adb, set port (default 5555, set when occupied)

5. Open the cmd window of the PC and enter the ADB connect 192.168.1.100:5555 carriage return (detailed IP will be displayed in wireless adb)

6. Successful Connection

If not implement, then conflict with other software, please try to turn off the pea clip, 360 and other software

The following to perform statistical power consumption code, due to the application of the foreground operation for one hour power consumption, manual Click is obviously unrealistic, here used to monkey to match the test. This shows only the power consumption of the entire system, and the power consumption of a single application Dumpsys more complex.

#coding =utf-8 ' Create on 2015-1-7python 2.7 for Window@auther:tangdongchu ' Import osimport sysimport timeimport Reimport datetimeclass Monkeytest (): Def __init__ (self): "" "Init" "" #monkey命令, PackageName package name , Interval interval unit MS, frequency number of executions Def Monkeyapp (self,packagename,interval,frequency): Try:os.popen ("a DB Shell monkey-p%s--throttle%s--ignore-crashes--ignore-timeouts--ignore-security-exceptions-- Ignore-native-crashes--monitor-native-crashes-v-v-v%s >e:\monkeylog\monkeyscreenlog.log "% (PackageName,        interval, frequency), ' R ') except Exception,e:print e #获取当前电量 def getcurrentbattery (self): Try:for Battery in Os.popen (' adb shell dumpsys Battery ', ' R '). ReadLines (): ReList = Re.sub (' Batt                ery: ', ', Battery) reList = relist.replace (' \ n ', ') result = Re.search (' level ', reList) If result! = None:list = ReliSt.split () Level=list.pop () #删除第i个元素 and returns this element.                    If you call Pop (), delete the last element #print "battery level" + level + "%" return level        Break except Exception,e:print e #获取当前时间, used to calculate the application run time def getcurrenttime (self):            Try:currenttime = Datetime.datetime.now () return currenttime except Exception,e: Print e def main (): print "" "" "" If __name__== "__main__": PackageName = ' Ctrip.android.view ' myApp = monkeytest () level = Int (Myapp.getcurrentbattery ()) runtime = Myapp.getcurrenttime () Myapp.monke YAPP (packagename,500,2500) #0.5 seconds, run 2,500 #判断是否执行完成, power consumption for I in range (1, 1000000): Monkeylog = Open (' E:\monkeylog\monkeyScreenLog.log ') try:temp = Monkeylog.read () finally:monkeylog. Close () If Temp.count (' Monkey finished ') >0:level = Int (myApp. Getcurrentbattery ())-level runtime = Myapp.getcurrenttime ()-runtime break else:t Ime.sleep (2) print "Run Time" + str (runtime) print "Use battery" + str + "%"

  

Android app power consumption statistics, no USB connection required

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.