脚本小工具: 游戏接入大量SDK后,快速查找引发报错问题的SDK(.a或.framework)

游戏或应用在接入大量SDK后,上线后对自身稳定性会存在隐藏的风险,通过一些诸如bugly工具可以监控出错问题,这时候我们需要去定位是哪一家SDK导致的,在此背景下,我们可以写一些脚本来检查,减少手动查找询问的时间!

脚本代码如下:

#coding=utf-8

import sys
import os
import  subprocess
import time
import shlex

# 第三方SDK文件夹目录的父级目录
third_SDK_Root_Path=''
# 第三方SDK名称标示,这里实例说明
third_SDK_Names=['Unity',
                 'Admob'
                 ]
# 第三方SDK文件.a或framework的路径目录,这里实例说明
third_SDK_Paths=['Unity/2.1.1/UnityAds.framework/UnityAds',
                 'Admob/7.25.0/GoogleMobileAds.framework/GoogleMobileAds'
                 ]

# 调用子进程,拿到输出结果
# @time_me
def startSubprocessPrograme(shell_cmd,check_classValue,platName):
    start = time.clock()
    #
    cmd=shlex.split(shell_cmd)
    p=subprocess.Popen(cmd,shell=False,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
    result = False
    while p.poll() is None:
        line = p.stdout.readline()
        line = line.strip()
        if check_classValue in line:
            result=True
    if p.returncode == 0:
        
        pass
    else:
        print('subprocess failed : [{}]'.format(shell_cmd))
    print(' 完成 :[{}] SDK查找!!!!'.format(platName))
    if result==True:
        print('成功找到SDK: [{}]'.format(platName))
    else:
        print('不是 [{}] SDK'.format(platName))

    end = time.clock()

    print str(end-start)
    return result

# @time_me
def searchFull(search_platName):
    result_platname=''
    for i in range(len(third_SDK_Names)):
        # 组装全路径
        platNamePath = third_SDK_Paths[i]
        # 可能存在多个路径
        arrTemp=platNamePath.split(',')
        for j in range(len(arrTemp)):
            platNamePath=arrTemp[j]
            print(' platNamePath: {}'.format(platNamePath))

            platFullPath = third_SDK_Root_Path + platNamePath

            targetPath = 'strings {}'.format(platFullPath)
            platName = third_SDK_Names[i]

            print(' cmd: {}'.format(targetPath))
            result = startSubprocessPrograme(
                targetPath,
                search_platName, platName)

            if result == True:

                break;

        if result == True:
            result_platname=third_SDK_Names[i]
            break;
    print('=======')
    print('完成SDK查找!!! 目标SDK是:{}'.format(result_platname))
    print('=======')
    pass

if __name__ == '__main__':
    paras_len= len(sys.argv)
    if paras_len>=2:
        third_SDK_Root_Path=sys.argv[1]
        search_platName = sys.argv[2]
        start = time.clock()
        searchFull(search_platName)
        end = time.clock()
        print str(end-start)
    pass
使用环境: Mac电脑

找到SDK文件夹,复制Game_ThirdSDK_Check.py脚本到SDK文件夹同级目录(注意: 路径不能为中文)下


使用方法:
python Game_ThirdSDK_Check.py路径 搜索的关键字(Bugly上报错的关键字) SDK文件夹路径

使用示例: 
python /Users/***/Desktop/Output/Game_ThirdSDK_Check.py TTMemoryCache /Users/***/Desktop/Output/SDK/ 

终端窗口预览示例:

 platNamePath: Admob/7.25.0/GoogleMobileAds.framework/GoogleMobileAds
 cmd: strings /Users/***/Desktop/Output/SDK/Admob/7.25.0/GoogleMobileAds.framework/GoogleMobileAds
 完成 :[Admob] SDK查找!!!!
不是 [Admob] SDK
3.199672
 platNamePath: Toutiao/1.8.0/WMAdSDK.framework/WMAdSDK
 cmd: strings /Users/***/Desktop/Output/SDK/Toutiao/1.8.0/WMAdSDK.framework/WMAdSDK
 完成 :[Toutiao] SDK查找!!!!
成功找到SDK: [Toutiao]
5.274037
=======
完成SDK查找!!! 目标SDK是:Toutiao
=======
126.05532

 

posted @ 2018-08-09 10:41  One Piece,我来了!  阅读(407)  评论(0)    收藏  举报