Python analytics android logs get Activit load time

Source: Internet
Author: User

Recently, there is a need to compare the time of a single activity load of two versions before and after

In the Android log we can see similar Info/activitymanager (2486): Displayed activity com.teleca/. contextmenuactivity:240 MS (total 41289 ms) log, which is the load time of the activity

First get the log through adb logcat > xx.txt, and then analyze the log with the following code:

#-*-coding:utf-8-*-#analyze Android adb logcat log extract activity displayed logImportOSImportRedefAndroiddisplayedlog (ApplicationName, logfile):ifos.path.exists (logfile): with open (logfile) as F:log=f.readlines () activityloadtime= []         forLineinchlog:ifRe.search (R"Displayed%s"%ApplicationName, line): Activitymanagerlog= Line.split (":") Activity= Activitymanagerlog[1].split ("/") [-1] Loadtimestr= Activitymanagerlog[-1].strip (). Strip ('Ms'). Strip ('+')                #An integer that converts the log time to Ms                Try: T=Int (LOADTIMESTR)ifT:loadtime=TexceptValueError:#Filter resident system activity for more than a minute                    Try: Loadtime= Int (Loadtimestr.split ('s') [0]) * + + int (loadtimestr.split ('s') [1])                    exceptValueError:Pass                Printactivity, Loadtime activityloadtime.append (activity, Loadtime)returnActivityloadtimeElse:        Print "log file does not exist"a= Androiddisplayedlog ("com.aaa.bbbb","D:\\log.txt")

Python analytics android logs get Activit load time

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.