一文揭秘如何利用AndroidGodEye 打造Android应用性能测试监控

摘要:
Android开发人员一直缺乏性能检测工具。唯一的工具,如Android DeviceMonitor,使用起来也很麻烦,需要开发人员使用。AndroidGodEye是一个可以在PC浏览器中实时监控Android数据指标的工具。您可以通过wifi/usb连接手机和PC,并通过PC浏览器实时监控手机的性能。

  AndroidGodEye是什么?

    官网的介绍如下。  

Android开发者在性能检测方面的工具一直比较匮乏,仅有的一些工具,比如Android Device Monitor,使用起来也有些繁琐,使用起来对开发者有一定的要求。
而线上的App监控更无从谈起。
所以需要有一个系统能够提供Debug和Release阶段全方位的监控,更深入地了解对App运行时的状态。AndroidGodEye是一个可以在PC浏览器中实时监控Android数据指标
比如性能指标,但是不局限于性能)的工具,你可以通过wifi/usb连接手机和pc,通过pc浏览器实时监控手机性能。
AndroidGodEye 系统分为三部分:
Core 核心部分,提供所有模块Debug Monitor部分,提供Debug阶段开发者面板Toolbox 快速接入工具集,给开发者提供各种便捷接入的工具AndroidGodEye提供了多种监控模块,
比如cpu、内存、卡顿、内存泄漏等等,
并且提供了Debug阶段的Monitor看板实时展示这 些数据。而且提供了api供开发者在release阶段进行数据上报。

        那么如何使用呢,接下来,我来带领大家去实际的去操作下。

        首先呢,我们先去引入

dependencies {
    // 核心模块,必须依赖
      implementation 'cn.hikyson.godeye:godeye-core:3.4.2'
    implementation 'cn.hikyson.godeye:godeye-monitor:3.4.2'
    implementation 'cn.hikyson.godeye:godeye-okhttp:3.4.2'
    // 额外依赖,添加此依赖可以完成Crash监控,如果不依赖则无法监控Crash(安装了也不会生效)
    implementation 'cn.hikyson.godeye:godeye-xcrash:3.4.2'
}

  

备注,这里的gradle的版本需要6.1.1版本

支持页面生命周期耗时检测和方法耗时检测MethodCanary

在Root Project的build.gradle中添加

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
    //我的配置classpath "cn.hikyson.methodcanary:plugin:0.15.0"
        classpath "cn.hikyson.methodcanary:plugin:PLUGIN_VERSION_NAME"
    }
}

  

  PLUGIN_VERSION_NAME参考 MethodCanary github release

在Application Module Project('com.android.application')的build.gradle中添加

apply plugin: 'cn.hikyson.methodcanary.plugin'
AndroidGodEye {
    enableMethodTracer true // 方法耗时检测,注意,生产包中关闭它,举例,这里可以这么写:!gradle.startParameter.taskNames.contains("assembleRelease")
    enableLifecycleTracer true // 页面生命周期检测
    instrumentationRuleFilePath 'AndroidGodEye-MethodCanary.js'
  }

  

需要配置AndroidGodEye-MethodCanary.js

如下

/**
    classInfo
        {int access
         String name
         String superName
         String[] interfaces}

     methodInfo
         {int access
         String name
         String desc}
**/
function isInclude(classInfo,methodInfo){
    if(!classInfo.name.startsWith('cn/hikyson/methodcanary')){
        return false;
    }
    if(classInfo.name.startsWith('cn/hikyson/methodcanary/samplelib/R$')
            || classInfo.name === 'cn/hikyson/methodcanary/samplelib/BuildConfig'){
            return false
    }
    return true
}

  在debug配置

resValue("bool", "android_god_eye_manual_install", "false")
            resValue("bool", "android_god_eye_need_notification", "true")
            resValue("integer", "android_god_eye_monitor_port", "5390")
            resValue("string", "android_god_eye_install_assets_path", "android-godeye-config/install.config")
          

  在项目的目录下面创建assets目录,然后创建android-godeye-config,然后去创建install.config文件,具体路径如下

一文揭秘如何利用AndroidGodEye 打造Android应用性能测试监控第1张

 文件内容如下

<config>
    <cpu intervalMillis="2000" />
    <battery />
    <fps intervalMillis="2000" />
    <leakCanary />
    <heap intervalMillis="2000" />
    <pss intervalMillis="2000" />
    <ram intervalMillis="2000" />
    <network />
    <sm dumpIntervalMillis="1000" longBlockThresholdMillis="500" shortBlockThresholdMillis="500" />
    <startup />
    <traffic intervalMillis="2000" sampleMillis="1000" />
    <crash immediate="false" />
    <thread intervalMillis="3000"
        threadFilter="cn.hikyson.godeye.core.internal.modules.thread.ExcludeSystemThreadFilter"
        threadTagger="cn.hikyson.godeye.core.internal.modules.thread.DefaultThreadTagger" />
    <pageload
        pageInfoProvider="cn.hikyson.godeye.core.internal.modules.pageload.DefaultPageInfoProvider" />
    <methodCanary lowCostMethodThresholdMillis="10" maxMethodCountSingleThreadByCost="300" />
    <appSize delayMillis="0" />
    <viewCanary maxDepth="10" />
    <imageCanary
        imageCanaryConfigProvider="cn.hikyson.godeye.core.internal.modules.imagecanary.DefaultImageCanaryConfigProvider" />
</config>

  这要是一些监控的配置。配置完毕,我们需要在项目的主入口增加

GodEyeHelper.setMonitorAppInfoConext(new AppInfoConext() {
            @Override
            public List<cn.hikyson.godeye.core.monitor.AppInfoLabel> getAppInfo() {
                List<AppInfoLabel> appInfoLabels = new ArrayList<>();
                appInfoLabels.add(new AppInfoLabel("ApplicationID", "com", null));
                appInfoLabels.add(new AppInfoLabel("VersionName", "1.1.0", ""));
                appInfoLabels.add(new AppInfoLabel("AndroidGodEye", "https://github.com/Kyson/AndroidGodEye", "https://github.com/Kyson/AndroidGodEye"));
                return appInfoLabels;
            }
        });

  

然后就可以运行app,我们就可以在设备上运行。

为了方便查看,

adb forward tcp:5390 tcp:5390

然后在本地浏览器就可以打开访问了。访问地址

http://localhost:5390/index.html

界面如下。

一文揭秘如何利用AndroidGodEye 打造Android应用性能测试监控第2张

 一文揭秘如何利用AndroidGodEye 打造Android应用性能测试监控第3张

 这样我们在实际的测试中,就可以发现我们的应用中的性能问题了,尽早发现尽早处理。

一文揭秘如何利用AndroidGodEye 打造Android应用性能测试监控第4张

免责声明:文章转载自《一文揭秘如何利用AndroidGodEye 打造Android应用性能测试监控》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇vue 弹窗时 监听手机返回键关闭弹窗(页面不跳转)MCI:移动持续集成在大众点评的实践下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android之——AIDL深入

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47071927 在上一篇博文《Android之——AIDL小结》中,我们简介了一下Android AIDL的使用方法,而在这篇博文中。我们将深入解说Android AIDL的使用方法。相同。在这里我们也通过一个小样例来学习Android...

android精品开源项目整理

转载地址:http://www.eoeandroid.com/thread-311366-1-1.html 前言:无论你是android的初学者,还有是Android开发了好多年的高手,可能都会有很多想法和经验希望与人分享交流,渴望能够接触到更多的项目实战,正所谓所谓与高手论道才能互补所长,与英雄共鼎方能百尺竿头,一味的织履贩席闭门造车只能固步自封成为...

.NET 基础知识

.net程序基本编写、执行流程(c#)       1>编写c#代码,保存为.cs文件。       2>通过csc.exe程序来将.cs文件编译为.net程序集(.exe或.dll)。此时的exe或dll并不是机器码(cpu不可理解)。【>csc /out:c:a.exe c:program.cs】   C:WindowsMicroso...

Delphi XE4 TStringHelper用法详解

原文地址:DelphiXE4TStringHelper用法详解作者:天下为公 Delphi XE4的TStringHelper,对操作字符串进一步带来更多的方法,估计XE5还能继续用到。System.SysUtils.TStringHelper大小写转换:-------------------------------------------------...

c# 利用百度图像处理【人像分割】一键抠图

百度AI开放平台-人像分割: http://ai.baidu.com/tech/body/seg 注意本文后面的话,百度这个技术效果太差劲了,国外这 https://www.remove.bg/ 个比百度强大很多。 using System; using System.Collections.Generic; using System.Linq; usin...

WordPress插件制作教程(三): 添加菜单的方法

上一篇编写了一个简单的插件,让大家对插件的简单制作有个了解,这一篇我们在更深一步,当我们激活插件后后台会显示菜单出来,然后通过单击菜单显示自己定义好的信息。激活之后会在WordPress后台显示一个菜单,下面会有多个子菜单,如下图: 1. 在WordPress后台添加一个同级主菜单,在主菜单下添加子菜单 // add_menu_page( $page_t...