• Android性能测试-分析工具


    简介

    这里我们说的性能测试主要是应用的CPU和内存占有率,如果CPU和内存占用率过高,就会导致内存泄漏,导致应用发生崩溃,影响用户的体验

    测试方法

    首先,我们说下性能测试的方法,

    1.通过手动点击,不断跳转到一个界面 

    2.使用Monkey来进行稳定性测试

    工具使用

    1.通过手动点击,不断跳转到一个界面。

      监控工具:android studio 的 Profile

    限制: 必须要有源码

    操作步骤如下:

    1.点击profile,安装应用到测试机上

    2. 点击record开始记录

     

     3.查看图形,如果在某一个界面出现异常升高,此时停止record.(profile可以分析MEMORY, CPU, NETWORK)

     4. 通过目录查找到你的应用的类

     5. 通过分析Allocatinos,如果某一个类的数值过大,就是因为该内存没有及时得到释放,就在该类上找原因(一般是Activity)

     

    2.使用Monkey来进行稳定性测试

    分析工具:自己写python代码,通过循环查看CPU 和内存来进行分析。

    内存:

    def get_total_pss():
    
        if os.path.exists('total.txt'):
            with open('total.txt','r+') as f2:
                res = f2.readlines()
                print(res)
                f2.seek(0)
                f2.truncate()
        with open('total.txt', 'at') as f1:
            f1.write('TOTAL:
    ')
        package = "com.wangpos.by.cashier3"
        cmd = "adb shell dumpsys meminfo {}".format(package)
        total = "TOTAL"
        while is_execute:
            lines = os.popen(cmd).readlines()
            for line in lines:
                if total in line:
                    # print(type(line))
                    total_result = [i for i in re.split(' ',line) if i !='']
                    print(total_result)
                    with open('total.txt','at') as f:
                        f.write(total_result[1]+'
    ')
                        sleep(5)
                    return total_result[1]

    输出,写入文件:

    CPU:

    def get_cpu():
        package = "com.wangpos.by.cashier3"
        cmd = "adb shell top -m 10 -n 1 -s cpu"
    
        while True:
            lines = os.popen(cmd).readlines()
            print(lines)
            for line in lines:
                if package in line:
                    result = [i for i in re.split(' ',line) if i !='']
                    with open('cpu.txt', 'at') as f:
                        f.write(result[2])
                        print(float(result[2].strip('%')))
                        sleep(5)
                    return float(result[2].strip('%'))

    输出,写入文件:

  • 相关阅读:
    Android Studio AVD和SDK Manager灰色不能点击的问题。
    回溯:最佳调度问题
    回溯:八皇后问题(蒟蒻)
    usaco1.4.3等差数列
    单调队列练习题(oj p1157 p1158 p1159)
    OJP1147括号匹配加强版(栈)与P1153乱头发节(单调栈)
    NOIP2017游记......
    火柴棒等式c++
    潜伏者(noip09年t1)解题报告 C++
    2016noipday1t1玩具迷题结题报告
  • 原文地址:https://www.cnblogs.com/jiablogs/p/11140033.html
Copyright © 2020-2023  润新知