基於sprd平台,根據關鍵字檢查開機耗時
#coding=utf-8
__author__="ao.deng"
import ctypes, sys,os
import re
std_input_handle = -10
std_output_handle = -11
std_error_handle = -12
# 字型顏色定義 text colors
foreground_blue = 0x09 # blue.
foreground_green = 0x0a # green.
foreground_red = 0x0c # red.
foreground_yellow = 0x0e # yellow.
# 背景顏色定義 background colors
background_yellow = 0xe0 # yellow.
# get handle
std_out_handle = ctypes.windll.kernel32.getstdhandle(std_output_handle)
def set_cmd_text_color(color, handle=std_out_handle):
bool = ctypes.windll.kernel32.setconsoletextattribute(handle, color)
return bool
# reset white
def resetcolor():
set_cmd_text_color(foreground_red | foreground_green | foreground_blue)
# green
def printgreen(mess):
set_cmd_text_color(foreground_green)
sys.stdout.write(mess + '\n')
resetcolor()
# red
def printred(mess):
set_cmd_text_color(foreground_red)
sys.stdout.write(mess + '\n')
resetcolor()
# yellow
def printyellow(mess):
set_cmd_text_color(foreground_yellow)
sys.stdout.write(mess + '\n')
resetcolor()
# white bkground and black text
def printyellowred(mess):
set_cmd_text_color(background_yellow | foreground_red)
sys.stdout.write(mess + '\n')
resetcolor()
boot_progress_keyword =r".*? (\d:\d:\d.\d).*?(boot_progress_\s+): (\d+)"
am_on_resume_called=r".*? (\d:\d:\d.\d).*?am_on_resume_called:.*?launcher,launch_activity]"
desc_dict=
consume_time_standard=
def read_log_file(logfile):
with open(logfile,"r") as f:
content =f.read()
f.close()
return content
def filter_keyword_time(keyword,logfile):
boot_progress_keyword_time_array = re.findall(keyword,logfile)
#print (boot_progress_keyword_time_array)
return boot_progress_keyword_time_array
def format_time(stacktime):
t =stacktime.split(":")
s=t[-1].split(".")
return int(s[1])/1000.0+int(s[0])+int(t[-2])*60+int(t[-3])*3600
def analysisdata(boot_progress_keyword_time_array,launcher_array):
timestart=boot_progress_keyword_time_array[0][2]
printyellow(desc_dict['boot_progress_start'])
if int(timestart)printgreen(u"{} boot_progress_start {}ms".format(u"核心之前時間",timestart))
else:
printred(u"{} boot_progress_start {}ms".format(u"核心之前時間", timestart))
boot_progress_ams_ready_current_time =0
boot_progress_ams_ready_current_stacktime=0
for stacktime,name,time in boot_progress_keyword_time_array[1:]:
if name=="boot_progress_ams_ready":
boot_progress_ams_ready_current_time =int(time)
boot_progress_ams_ready_current_stacktime = stacktime
if name in desc_dict.keys():
desc=desc_dict[name]
else:
desc=""
printyellow(u"{}".format(desc))
consume_time=int(time)-int(timestart)
if consume_timeprintgreen(u"{} consume time: {}ms".format(name, consume_time))
else:
printred(u"{} consume time: {}ms".format(name,consume_time))
timestart=time
# 本次開機時長可以用:
# 002a7f 12-28 16:08:33.652 650 650 i boot_progress_ams_ready: 43367
# 00476d 12-28 16:08:48.448 1436 1436 i am_on_resume_called: [0,com.android.launcher3.launcher,launch_activity]
# 計算: 43.367+(48.448-33.652)= 58.163s
boot_up_time =boot_progress_ams_ready_current_time/1000.0+(format_time(launcher_array[0])-format_time(boot_progress_ams_ready_current_stacktime))
printgreen(u"{} boot up consume time: {}s".format(u"本次開機時長",boot_up_time))
if __name__=="__main__":
logfile=r"events.log"
content = read_log_file(logfile)
boot_progress_keyword_time_array=filter_keyword_time(boot_progress_keyword,content)
launcher_array=filter_keyword_time(am_on_resume_called,content)
analysisdata(boot_progress_keyword_time_array,launcher_array)
os.system("pause")
Android下獲取開機時間
我的思路是 程式裡註冊個廣播接收器,接收開機啟動的廣播,當程式接到該廣播後,寫入檔案sharedpreferences,當我們程式需要用到開機時間時,再從sharedpreferences中讀取資訊。廢話不多說,下面上原始碼。androidmanifest.xml receiver檔案,記錄開機時間...
Android下獲取開機時間
我的思路是 程式裡註冊個廣播接收器,接收開機啟動的廣播,當程式接到該廣播後,寫入檔案sharedpreferences,當我們程式需要用到開機時間時,再從sharedpreferences中讀取資訊。廢話不多說,下面上原始碼。androidmanifest.xml receiver檔案,記錄開機時間...
開機時間太長
開機時間太長,用360檢測的系統核心專案占用的時間是100多秒。網上查到是由於系統多次掛起引起的。解決方法 1.管理工具 計算機管理 裝置管理器 ide ata atapi控制器 ata channel 0 解除安裝驅動 重啟後效果很明顯。防止以後再次發生這樣的事 1.單擊 開始 單擊 執行 鍵入 ...