應用啓動時間-性能測試

main.bat

::接受幾個參數,一個循環次數,一個包名,一個日誌存放路徑
::循環次數
@echo off
adb push startmanytimes.sh /data/local/tmp 2>nul
adb shell chmod 755 /data/local/tmp 2>nul
adb shell sh /data/local/tmp/startmanytimes.sh 300 cn.nubia.v5light.preset/cn.nubia.v5light.MainActivity /data/local/tmp/test 2>nul
adb pull /data/local/tmp/test.txt .  2>nul
::解析時間文件生成PDF
python jasonstudyreprotlab_chart.py 2>nul

main.sh

##接受幾個參數,一個循環次數,一個包名,一個日誌存放路徑
#循環次數
cycle=$1
echo cycle:$1
#需要測試的啓動包名
pkgname=$2
echo pkgname:$2
#日誌存放路徑
path=$3.txt
echo path:$3
#刪除原來的日誌
rm -f $path
i=0
while [ $i != $cycle ]
do
	#清理日誌緩存
	logcat -c
	echo am start --activity-clear-task -n $pkgname
	am start --activity-clear-task -n $pkgname
	sleep 3
	#記錄啓動信息
	logcat -d -v raw -s ActivityManager:I I:s | grep "Displayed" | grep -o '[0-9]\{3\}' >> $path
	input keyevent KEYCODE_HOME
	sleep 3
	#增加計數
	i=$(($i+1))
done


得到的啓動時間的文本文件使用python腳本進行解析:

#Autogenerated by ReportLab guiedit do not edit
from reportlab.graphics.charts.legends import Legend
from reportlab.graphics.charts.lineplots import LinePlot
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin, String
from reportlab.graphics.charts.textlabels import Label
from reportlab.graphics.samples.excelcolors import *

class ChatStudy(_DrawingEditorMixin,Drawing):
    def __init__(self,date,avedata,width=200,height=150,*args,**kw):
        Drawing.__init__(self,width,height,*args,**kw)
        self._add(self,LinePlot(),name='chart',validate=None,desc="The main chart")
        self.chart.width      = 115    #set the chat width
        self.chart.height     = 100    #set the chat height
        self.chart.x          = 25     #set the xAxis location
        self.chart.y          = 30     #set the yAxis location
        self.chart.xValueAxis.forceZero= 1
        self.chart.yValueAxis.forceZero= 1
        self.chart.xValueAxis.visibleGrid=1
        self.chart.yValueAxis.visibleGrid=1
        self.chart.data=date
        self._add(self,Label(),name='XLabel',validate=None,desc="The label on the horizontal axis")
        self.XLabel.fontName       = 'Helvetica'
        self.XLabel.fontSize       = 2
        self.XLabel.x              = 85
        self.XLabel.y              = 10
        self.XLabel.textAnchor     ='middle'
        self.XLabel.maxWidth       = 100
        self.XLabel.height         = 2
        self.XLabel._text          = "times"
        self._add(self,Label(),name='YLabel',validate=None,desc="The label on the vertical axis")
        self.YLabel.fontName       = 'Helvetica'
        self.YLabel.fontSize       = 2
        self.YLabel.x              = 12
        self.YLabel.y              = 80
        self.YLabel.angle          = 90
        self.YLabel.textAnchor     ='middle'
        self.YLabel.maxWidth       = 100
        self.YLabel.height         = 2
        self.YLabel._text          = "start_time"
        self._add(self,Label(),name='Title',validate=None,desc="The title at the top of the chart")
        self.Title.fontName   = 'Helvetica-Bold'
        self.Title.fontSize   = 5
        self.Title.x          = 100
        self.Title.y          = 135
        self.Title._text      = 'Chart Title'
        self.Title.maxWidth   = 180
        self.Title.height     = 20
        self.Title.textAnchor ='middle'
        self._add(self,Legend(),name='Legend',validate=None,desc="The legend or key for the chart")
        self.Legend.colorNamePairs = [(color01, 'average_time:'+str(avedata))]
        self.Legend.fontName       = 'Helvetica'
        self.Legend.fontSize       = 2
        self.Legend.x              = 153
        self.Legend.y              = 85
        self.Legend.dxTextSpace    = 5
        self.Legend.dy             = 5
        self.Legend.dx             = 5
        self.Legend.deltay         = 5
        self.Legend.alignment      ='right'
def readfile(filename):
        f=file(filename,'r')
        list=[];
        while True:
            line = f.readline()
            if len(line) == 0: # Zero length indicates EOF
                break
            list.append(float(line))
        f.close()
        return list
#return average of list
def ave(list):
  return float(sum(list))/len(list)
def anaysis(list):
        counter=0
        listtmp=[]
        length=len(list)
        while counter<length:
            listtmp.append((counter+1,list[counter]))
            counter=counter+1
        return listtmp
if __name__=="__main__": #NORUNTESTS
    date=anaysis(readfile('test.txt'))
    avedata=ave(readfile('test.txt'))
    print avedata
    ChatStudy([date],avedata).save(formats=['pdf'],outDir=None,fnRoot='LovePython')

最後生成啓動時間的曲線圖



發佈了133 篇原創文章 · 獲贊 17 · 訪問量 116萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章