Monkey Crash解析脚本

脚本语言:python v2.7

解析原理:monkey出现crash时,日志都会以"// CRASH: + package name + pid"行开始记录;monkey执行随机事件,该行内容以":Sending"或":Switch"开头

脚本代码:

source_file_path = $(your monkey log file)

crash_file_path = $(file to restore crash)



def crash_analysis():

    analysis_flag = False

    crash_content = []

    read_lines = open(source_file_path)

    for line in read_lines:

        if ((line != None) & (line.startWith("// CRASH:")):

            analysis_flag = True

        elif ((line != None) & line.startswith(":Sending") & analysisFlag):

            analysis_flag = False
    
        elif ((line != None) & line.startswith(":Switch") & analysisFlag):

            analysis_flag = False

        if (analysis_flag):

            crash_content.append(line)

    file_out = open(crash_file_path, 'w')

    file_out.writelines(crash_content)

    file_out.close()



crash_analysis()

你可能感兴趣的:(Monkey Crash解析脚本)