Android performance testing + result visualization

Technology used: mobileperf+pyecharts or mobileperf+grafana

Performance Testing

GitHub - alibaba/mobileperf: Android performance testAndroid performance test. Contribute to alibaba/mobileperf development by creating an account on GitHub.https://github.com/alibaba/mobileperf

 Instructions:

  • Install python3, add it to the environment variable, execute python --version, make sure it is python3
  • Install adb, make sure adb devices can find the device
  • Modify the configuration file, for example, refer to config.conf in the root directory
  • Run, mac, linux execute sh run.sh in the root directory of the mobileperf tool, windows double-click run.bat, end the test, wait for the set test time to expire or press Ctrl+C

The config file mainly changes the package name and device udid

 Test results, including cpu, fps, memory mem, traffic and other csv files

 Results visualization

grafana

The installation and use of grafana can be learned by yourself. Here we mainly talk about pyecharts

 pyecharts

Installation: pip install pyecharts

The actual cpu test results are as follows

 Now use pyecharts to process, the comment indicates the meaning of each step, you can look at it

import pandas as pd
import pyecharts.options as opts
from pyecharts.charts import Line
import os


class csv_to_chart(object):
    def __init__(self):
        self.cpu_file_name = './cpuinfo.csv'
        self.fps_file_name = './fps.csv'
        self.mem_file_name = './meminfo.csv'
        self.traffic_file_name = './traffic.csv'

    def func(self, val):
        tmp = float(val) / 100
        tmp = "{:.2f}".format(tmp)
        return str(tmp)

    def cpu_csv_to_line(self):
        # 读取CSV文件
        db = pd.read_csv(self.cpu_file_name)
        # 获取列名,转为列表
        tmp = db.columns.tolist()
        tmp_list = []
        # 列名system,特殊符号%,\n不能入库
        for a in tmp:
            if '\n' in a:
                tmp_list.append(a[:-2])
            elif 'system' in a:
                tmp_list.append('sys')
            elif '%' in a:
                tmp_list.append(a[:-1])
            else:
                tmp_list.append(a)
        db.columns = tmp_list

        # 将pid_cpu这一列除以100,因为是百分比
        db.pid_cpu = db.apply(lambda x: self.func(x.pid_cpu), axis=1)

        yk = (
            Line()
                .add_xaxis(db.datetime.tolist())

                .add_yaxis(series_name="cpu百分比",
                           y_axis=db.pid_cpu.tolist(),
                           # 跳过值是0的点
                           is_connect_nones=True,
                           # 曲线光滑
                           is_smooth=True,
                           markpoint_opts=opts.MarkPointOpts(
                               data=[
                                   opts.MarkPointItem(type_="max", name="最大值"),
                                   opts.MarkPointItem(type_="min", name="最小值"),
                               ]
                           ),
                           markline_opts=opts.MarkLineOpts(
                               data=[opts.MarkLineItem(type_="average", name="平均值")]
                           ), )

                .set_global_opts(title_opts=opts.TitleOpts(title="cpu占用详情"),
                                 tooltip_opts=opts.TooltipOpts(trigger="axis"))

                .render("html/cpu.html")
        )



if __name__ == '__main__':
    tmp = os.path.join(os.path.dirname(__file__), "html")
    if not os.path.exists(tmp):
        os.mkdir(tmp)
    csv_to_chart().cpu_csv_to_line()

current problem

  • Real device, no fps data
  • Simulator, no traffic data

Effect

  • line chart
  • maximum value
  • minimum value
  • average
  • vertical bar prompt
  • skip empty values

The script is placed in the statistical result path, and the corresponding html will be generated in the html folder when running

Real machine results

simulator results

Guess you like

Origin blog.csdn.net/qq_38312411/article/details/129306991