一文揭秘如何利用AndroidGodEye 打造Android應用性能測試監控


  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文件,具體路徑如下

 

 文件內容如下

<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

界面如下。

 

 

 

 這樣我們在實際的測試中,就可以發現我們的應用中的性能問題了,盡早發現盡早處理。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM