Skip to content

Commit 724bf40

Browse files
MonkeyMonkey
authored andcommitted
fix the PID bug and add multi process write the log
1 parent 32f7ae5 commit 724bf40

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

‎Test_File.py‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import os, re,sys
44
import subprocess
5-
import time, os, sched,shlex
5+
import time, os, sched,shlex,threading
66
from reportlab.graphics.shapes import *
77
from reportlab.graphics.charts.lineplots import LinePlot
88
from reportlab.graphics.charts.textlabels import Label
99
from reportlab.graphics import renderPDF
1010

11+
12+
1113
# execute command, and return the output
1214
def 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

4649
def 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+
117126
schedule = sched.scheduler(time.time, time.sleep)
118127

119128
def perform_command(cmd, inc):
@@ -129,7 +138,7 @@ def timming_exe(cmd, inc = 60):
129138

130139
if __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

Comments
 (0)