android ash日志,iOS奔溃日志分析

iOS奔溃日志分析

前言(扯淡)

iOS奔溃日志能够比较有效的分析奔溃的原因,方便我们debug我们的项目。当然现在有很多线上的这种bug收集和集成的第三方例如:Bugly这种。这次我来说说,怎么样在拿到奔溃日志后发现我们代码中的bug。

需要的装备

Symbolicatecarash

这个是Xcode自带的一个Carsh分析的工具。我们如果想要分析奔溃日志必须要用到它。那么如何找到他呢???

1. 找到Symbolicatecarash文件`

find /Applications/Xcode.app -name symbolicatecrash -type f

你会找到:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/./symbolicatecrash

2.拷贝到指定目录

cp /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash /Users/angel/Desktop/crash

工程项目编程好的包文件

把项目编译好的Product里面的对于文件拉到刚刚的文件夹下。

dSYM文件

这个是符号化相关的文件 把对应工程包的dSYM文件也拉到刚刚的文件夹下。

Crash文件

真机上的Crash文件导出,可以通过itunes。只要在手机上奔溃过,利用itunes点击同步便可把奔溃日志同步到本地电脑上。在如下路径找到对应时间点的Crash文件,拉到刚刚的目录下。文件路劲~/Library/Logs/CrashReporter/MobileDevice/

自己写的Python批处理文件

对应代码如下

#!/usr/bin/python

#-*- coding: utf-8 -*-

#encoding=utf-8

__author__ = 'zengmingjian'

import os

import sys

import commands

def crashFileValid(excuteFile,dsymFile):

if len(excuteFile) < 4:

return

excuteCmd = "dwarfdump --uuid " + excuteFile + "/" + excuteFile[0:len(excuteFile) - 4]

print excuteCmd

dsymCmd = "dwarfdump --uuid " + dsymFile

lines1 = os.popen(excuteCmd).readlines()

lines2 = os.popen(dsymCmd).readlines()

for line in lines1:

uuidString1 = line.split(' ')[1]

for line in lines2:

uuidString2 = line.split(' ')[1]

if (uuidString1 == uuidString2):

print ("uuidString = " + uuidString1)

return True

else:

print ("uuidString1 = " + uuidString1)

print ("uuidString2 = " + uuidString2)

print("!!!!!dsym 文件 和 可执行app文件不匹配!!!!!")

return False

#解析设置环境

def setEnvironment():

os.environ["DEVELOPER_DIR"]="/Applications/Xcode.app/Contents/Developer/" #DISPLAY是环境变量名,:0.0是要设置的值

os.system('$DEVELOPER_DIR')

#检测是否存在symbolicatecrash工具,如果不存在,则在xcode拷贝到当前目录

def getSymbolicatecrashTool():

currentDir = os.getcwd()

symbolDir = "/Applications/Xcode.app/Contents/SharedFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash"

for root,dirs,files in os.walk(currentDir):

if os.path.exists(root + "/" + "symbolicatecrash"):

print("=================")

setEnvironment()

return

else:

os.system("cp " + symbolDir + " " + currentDir)

setEnvironment()

break

#遍历当前目录,解析文件

def parseCrashLog():

dirList = os.listdir(os.getcwd())

print dirList

crashList = []

dsymName = ""

appName = ""

for d in dirList:

if d.endswith(".crash") or d.endswith(".ips"):

crashList.append(d)

if d.endswith(".dSYM"):

dsymName = d

if d.endswith(".app"):

appName = d

#不存在dsym文件

if dsymName == "":

print "error:请将dsym文件考到当前目录!!!!!"

return

if appName == "":

print "error:请将app文件考到当前目录!!!!"

return

#检测dsym文件 和app文件是否匹配

if (crashFileValid(appName, dsymName) == False):

return

for crashFile in crashList:

if crashFile.endswith(".crash"):

print crashFile

print dsymName

os.system("./symbolicatecrash "+ crashFile + " " + dsymName + " >> " + crashFile.replace(".crash",".log"))

elif crashFile.endswith(".ips"):

os.system("./symbolicatecrash "+ crashFile + " " + dsymName +" >> " + crashFile.replace(".ips",".log"))

def startPaser():

getSymbolicatecrashTool()

parseCrashLog()

if __name__ == '__main__':

startPaser()

使用方法

把Crash文件对应的包对应的项目文件,dSYM文件和Crash文件放在同一个目录下。然后调用上面的python文件就可以得到一个.log的解析文件。根据解析文件 就可以知道是哪一行代码导致的奔溃。然后就可以修改奔溃。

参考和致谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值