使用adb命令获取Android SurfaceView 的 帧率(fps)jank,手机的基本信息

获取fps

        adb shell dumpsys SurfaceFlinger | grep + 包名启动页 (不然他获取的数据是只有一行数据),这个命令只需要执行一次

        使用的是adb shell dumpsys SurfaceFlinger --latency "SurfaceView +包名/启动页"获取的,目前只支持安卓6.0以上。

        使用adb 命令时,可以根据他的版本来进行拼接命令行

        安卓7.0:adb shell dumpsys SurfaceFlinger --latency "SurfaceView +包名/启动页"

        安卓8.0--安卓10: adb shell dumpsys SurfaceFlinger --latency "SurfaceView +包名/启动页#0"

        安卓11:暂时没测

        安卓12:adb shell dumpsys SurfaceFlinger --latency "SurfaceView +包名/启动页(BLAST)#0"

        执行之后,返回结果可能各不相同,有128行的,129行的,257行的,第一行166666666.。。。之类的是屏幕的刷新率/刷新的时间间隔。有的第二行是执行的命令。剩下的就是帧数据了,

分为三列:

  • 第一列:表示应用绘制图像的时间点
  • 第二列:SF将帧提交给H/W(硬件)绘制之前的垂直同步时间。
  • 第三列:在SF将帧提交给H/W的时间点,算是H/W接受完SF发来数据的时间点,绘制完成的时间点

计算方式:本文使用的是第二列数据。因为好多手机得到的数据,第一列和第三列数据是一样的

16666666
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0
0       0       0

0       75152891320027  0
0       75152907976642  0
0       75152941365340  0
0       75152974872319  0
0       75153008281538  0
0       75153041768361  0
0       75153075258621  0
0       75153108519975  0
0       75153158574402  0
0       75153175158413  0
0       75153208754767  0
0       75153242157892  0
0       75153275713152  0
0       75153308947996  0
0       75153342481433  0
0       75153375754819  0
0       75153542967840  0
0       75153559645027  0
0       75153576540548  0
0       75153593006173  0
0       75153609714454  0
0       75153626491954  0
0       75153643087579  0
0       75153659892110  0
0       75153676623100  0
0       75153710119975  0
0       75153743700860  0
0       75153777001069  0
0       75153843714662  0
0       75153860340131  0
0       75153877015131  0
0       75153910435964  0
0       75153943864454  0
0       75153977357371  0
0       75154010686850  0
0       75154044245339  0
0       75154077459714  0
0       75154111062579  0
0       75154144366902  0
0       75154177938725  0
0       75154244873829  0
0       75154261383881  0
0       75154278122631  0
0       75154311477475  0
0       75154345154454  0
0       75154378347371  0
0       75154411960912  0
0       75154461855548  0
0       75154478616902  0
0       75154511997423  0
0       75154612268048  0
0       75154629020339  0
0       75154645684141  0
0       75154662381902  0
0       75154679121173  0
0       75154695957995  0
0       75154745931016  0
0       75154762560912  0
0       75154796106745  0
0       75154829484506  0
0       75154863126745  0
0       75154896328985  0
0       75154929769610  0
0       75154963208829  0
0       75154996592474  0
0       75155030027110  0
0       75155063514610  0
0       75155096818099  0
0       75155130309818  0
0       75155163711641  0
0       75155196983881  0
0       75155230591797  0
0       75155263867370  0
0       75155297110391  0
0       75155330722110  0
0       75155380769870  0
0       75155431071172  0
0       75155447685651  0
0       75155481061901  0
0       75155497811485  0
0       75155565012110  0
0       75155581256172  0
0       75155614818360  0
0       75155631568985  0
0       75155664830860  0
0       75155698306537  0
0       75155731727005  0
0       75155765030183  0
0       75155798560755  0
0       75155832071224  0
0       75155882198047  0
0       75155898720547  0
0       75155932292787  0
0       75155965658412  0
0       75155999120287  0
0       75156032369922  0
0       75156065899037  0
0       75156099374609  0
0       75156132631641  0
0       75156166211849  0
0       75156199663620  0
0       75156233020182  0
0       75156266231589  0
0       75156299606380  0
0       75156333153099  0
0       75156450209245  0
0       75156466872839  0
0       75156483620495  0
0       75156500582839  0
0       75156516923307  0
0       75156533518672  0
0       75156633869818  0
0       75156650588463  0
0       75156667235234  0
0       75156684052734  0
0       75156700766172  0
0       75156751034609  0
0       75156784305182  0
0       75156801062057  0
0       75156834540338  0
0       75156867999140  0
0       75156901351380  0
0       75156934761640  0
0       75156968168984  0
0       75157001610651  0
0       75157018328307  0
0       9223372036854775807     0

   类似 这样的,只取后边的有效数据,fps = 有效数据的长度/两帧之间的差的总和,注意两帧之间 的差要除以一的九次方。就得到fps了。

jank 得获取

FrameTime  两帧画面间隔耗时

同时满足两条件,则认为是一次卡顿Jank.
    ①Display FrameTime>前三帧平均耗时2倍。 
    ②Display FrameTime>两帧电影帧耗时 (1000ms/24*2=84ms)
 
  同时满足两条件,则认为是一次严重卡顿BigJank.
    ①Display FrameTime >前三帧平均耗时2倍。
    ②Display FrameTime >三帧电影帧耗时(1000ms/24*3=125ms)。

手机的基本信息:

deviceName = os.popen('adb shell getprop ro.product.model').read()
    print("手机型号:" + deviceName)
    platformVersion_ver = os.popen(
        'adb shell getprop ro.build.version.release').read()
    print("安卓版本:" + platformVersion_ver)
    level = os.popen('adb shell dumpsys battery |findstr level').read()
    print("手机电量:" + level)
    # 获取的包名 + 启动页
    platformVersion = os.popen(
        'adb shell dumpsys window | findstr mCurrentFocus').read()
    path = platformVersion[34:len(platformVersion) - 2]
    # 获取的包名
    pack_name = path.split("/")[0]
    print("包名 :" + pack_name)
    # 获取app的进程id
    dev_adb = "adb shell ps | findstr " + '"' + pack_name + '"'
    results = os.popen(dev_adb).read()
    print('CPU数量:' + str(os.cpu_count()))
    # 多个空格替换为一个空格
    str_result = re.sub(' +', ' ', results)
    pid = str_result.split(' ')[1]
    print("手机进程id:" + pid)

CPU  内存 占用

# 获取手机的GPU 信息
def get_gpu(platformVersion_ver, path):
    # path.split("/")
    pack_name = path.split("/")[0]
    results = os.popen('adb shell dumpsys cpuinfo | findstr ' +
                       pack_name).read()
    # print("\n")
    str_result = re.sub(' +', ' ', results)
    print(str_result)
    if len(results) > 0:
        cpuLine = str_result.split(' ')[6]
        print('CPU占用率: ' + cpuLine)
    else:
        print('没有获取到CPU数据' + str_result)
    # print(cpuLine)
# 获取手机的内存占用的情况
def get_memory(platformVersion_ver, pid):
    print('进程id ' + pid)
    results = os.popen('adb shell top -n 1 -d 0.5 | findstr ' + pid).read()
    # print("\n")
    # print(results)
    if len(results) > 0:
        str_result = re.sub(' +', ' ', results)
        print(str_result)
        if platformVersion_ver > 7:
            cpuLine = str_result.split(' ')[6]
        else:
            cpuLine = str_result.split(' ')[9]
        print('内存占用: ' + cpuLine)
    else:
        print('没有获取到内存数据')

猜你喜欢

转载自blog.csdn.net/weixin_50330149/article/details/127449021