22
33import os , re ,sys
44import subprocess
5- import time , os , sched ,shlex
5+ import time , os , sched ,shlex , threading
66from reportlab .graphics .shapes import *
77from reportlab .graphics .charts .lineplots import LinePlot
88from reportlab .graphics .charts .textlabels import Label
99from reportlab .graphics import renderPDF
1010
11+
12+
1113# execute command, and return the output
1214def execCmd (cmd ):
1315 r = os .popen (cmd )
@@ -37,11 +39,12 @@ def getAppPID(packagename):
3739 logcat = popen .stdout .readline ()
3840 if packagename in logcat :
3941 Status = False
40- print logcat .split (' ' )[2 ]
41- return logcat .split (' ' )[2 ]
42+ for pid in logcat .split (' ' ):
43+ if pid .isalnum ():
44+ print pid
45+ return pid
4246 except KeyboardInterrupt :
43- return logcat .split (' ' )[2 ]
44-
47+ return pid
4548
4649def getGCfile ():
4750 os .system ("adb kill-server" )
@@ -108,12 +111,18 @@ def analysisGCFile(AppPID):
108111 average_GC_time = '%.2f' % float (GC_time_all / GC_count )
109112 print GC_Freed_list ,average_GC_Freed ,GC_count_list ,GC_per_list ,average_GC_per ,GC_time_list ,average_GC_time
110113 return GC_Freed_list ,average_GC_Freed ,GC_count_list ,GC_per_list ,average_GC_per ,GC_time_list ,average_GC_time
111- #! /usr/bin/env python
112- #coding=utf-8
113- #这里需要引入三个模块
114-
115- # 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
116- # 第二个参数以某种人为的方式衡量时间
114+
115+
116+ def WriteLog (waittime ):
117+ try :
118+ subprocess .Popen ("adb logcat -v time -v threadtime *:D | grep GC>GCFile.txt" ,shell = True )
119+ print '日志正在记录中。。。请稍后'
120+ time .sleep (float (waittime )* 3600 )
121+ except KeyboardInterrupt :
122+ print '报告正在生成'
123+ os .system ('adb kill-server' )
124+
125+
117126schedule = sched .scheduler (time .time , time .sleep )
118127
119128def perform_command (cmd , inc ):
@@ -129,7 +138,7 @@ def timming_exe(cmd, inc = 60):
129138
130139if __name__ == "__main__" :
131140 app_pid = getAppPID (sys .argv [1 ])
132- getGCfile ( )
141+ WriteLog ( sys . argv [ 2 ] )
133142 GC_Freed_list ,average_GC_Freed ,GC_count_list ,GC_per_list ,average_GC_per ,GC_time_list ,average_GC_time = analysisGCFile (app_pid )
134143 MakePDF (GC_count_list ,GC_Freed_list ,'average GC Freed:' + str (average_GC_Freed )+ 'kb' ,"GC_Freed报告.pdf" )
135144 MakePDF (GC_count_list ,GC_per_list ,'average GC per:' + str (average_GC_per )+ '%' ,"GC_百分比报告.pdf" )
0 commit comments