#! /usr/bin/env python #! -*- cording:utf-8 -*- import csv import os import time class Control(object): def __init__(self): self.alldate=[("id",'vss','ass')] def run(self): cmd = 'adb shell top -d 1 > D:python_projectlaunchtimememinfo' os.popen(cmd) time.sleep(10) cmd1='adb shell stop' os.popen(cmd1) def analyzedata(self): content=self.readfile() i=0 for line in content: if 'com.sec.android.app.sbrowser'in line: print(line) line='#'.join(line.split()) # 用#连接两个字符串,以#开头,K结尾,vss虚拟内存,RSS物理内存,取值处理后,做成表格。 vss=line.split('#')[5].strip('k') rss = line.split('#')[6].strip('k') self.alldate.append(i,vss,rss) i=i+1 def SaveDataToCSV(self): with open("memory.csv",'w') as f: writer=csv.writer(f) writer.wrterows(self.alldate) f.close() #读取数据文件,然后丢给analyzedata函数去处理 def readfile(self): with open("meminfo","r")as f: content=f.readlines() f.close() return f if __name__=="__main__": control=Control() control.run() control.analyzedata() control.SaveDataToCSV()