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