python通過adb命令獲取實際內存數據
1.在執行代碼前,需要確保能夠在doc窗口執行adb命令,開始的數據可能會有問題(目前知識不夠,以后再做更改)
#coding=utf-8import timeimport subPRocessimport xlwtpackage_name_mysdk = 'com.tcl.live'def getPSS(package_name): #用adb獲取信息adb shell "dumpsys meminfo com.tcl.live | grep "TOTAL"" p = subprocess.Popen('adb shell "dumpsys meminfo ' + package_name + ' | grep "TOTAL""',stdout = subprocess.PipE, stderr = subprocess.PIPE) text = p.stdout.read() listoftext = text.split() print 'PSS=' + listoftext[1] return int(listoftext[1])time_start = 0time_end = 0#創建新的工作薄book = xlwt.Workbook(encoding = 'utf-8', style_compression = 0)#創建新的sheet,并命名為PSSsheet_sdk = book.add_sheet('PSS-SDK', cell_overwrite_ok = True)sheet_sdk.write(0, 0, "time")sheet_sdk.write(0, 1, "PSS")#Excel表格的行(row)、列(col)row = 1col = 0#測試時間為3600s=1hwhile time_end <= 3600: #獲取當前時間 timeNow = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print timeNow sheet_sdk.write(row, col, timeNow) try: pss_sdk = getPSS(package_name_mysdk) sheet_sdk.write(row, col + 1, pss_sdk) except: print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) +"process has been shuoutdown!" row += 1 time_end += 1 #獲取pss total值時間間隔10s time.sleep(10) book.save(r"d://pss.xls")2.在D盤根目錄找到pss.xls對數據進行簡單的修改和分析
新聞熱點
疑難解答