android 开机时间检测

基于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{2}:\d{2}:\d{2}.\d{3}).*?(boot_progress_\S+): (\d+)"
AM_ON_RESUME_CALLED=r".*? (\d{2}:\d{2}:\d{2}.\d{3}).*?am_on_resume_called:.*?Launcher,LAUNCH_ACTIVITY]"
DESC_DICT={
    "boot_progress_start":u"进入zygote",
    "boot_progress_preload_start":u"开始preload class&resource",
    "boot_progress_preload_end":u"preload结束",
    "boot_progress_system_run":u"systemserver起来了",
    "boot_progress_pms_start":u"pms服务起来",
    "boot_progress_pms_system_scan_start":u"开始扫描system分区",
    "boot_progress_pms_data_scan_start":u"开始扫描data分区",
    "boot_progress_pms_scan_end":u"pms扫描结束",
    "boot_progress_pms_ready":u"pms ready",
    "boot_progress_ams_ready":u"pms到ams间会起一堆服务,然后ams 服务ready",
    "boot_progress_enable_screen":u"进入屏幕",
    "FallbackHome":u"进入fallback界面,等待user_unlocked广播",
    "Launcher":u"进入桌面"
}
CONSUME_TIME_STANDARD={
    "boot_progress_start":10512,
    "boot_progress_preload_start":2294,
    "boot_progress_preload_end":2570,
    "boot_progress_system_run":453,
    "boot_progress_pms_start":1082,
    "boot_progress_pms_system_scan_start":535,
    "boot_progress_pms_data_scan_start":779,
    "boot_progress_pms_scan_end":335,
    "boot_progress_pms_ready":759,
    "boot_progress_ams_ready":2995,
    "boot_progress_enable_screen":4848,
    "boot_up":56091
}


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)

 

你可能感兴趣的:(android开发,python)