Coder Social home page Coder Social logo

ryanfu / adi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zkwlx/adi

0.0 0.0 0.0 4.99 MB

ADI(Android Debug Intensive) 是通过 JVMTI 实现的 Android 应用开发调试的增强工具集,目前主要提供性能相关的监控能力。

License: Apache License 2.0

Java 4.66% Kotlin 4.95% CMake 21.31% C 30.26% C++ 24.39% Python 14.43%

adi's Introduction

ADI 简介

对象分配与释放的样例

对象分配图表 点击体验

多线程竞争样例

线程竞争图表 点击体验

APP 集成样例截图

ADI 控制窗

ADI(Android Debug Intensive) 是通过 JVMTI 实现的 Android 应用开发调试的增强工具集,目前主要提供性能相关的监控能力。
ADI 对运行时的 App 进行性能数据收集,并提供工具用于生成分析图表。目前提供如下功能:

  • 监控 ART 运行过程中对象的分配与释放,包括对象大小、创建对象调用栈等信息
  • 监控 ART 运行过程中多线程之间的锁竞争,包括发生竞争时的调用栈、当前竞争线程的等待时长、当前持有锁的线程等信息

注意 ADI 只支持 Android 8.0(包括 8.0)之后的系统。

如何使用

集成到 APP

首先添加 jcenter 依赖(添加过请忽略):

buildscript {
    repositories {
        jcenter()
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

然后 APP 工程集成 adi 库:

debugImplementation 'zkw.adi:adi:0.9.3'
releaseImplementation 'zkw.adi:adi-nop:0.9.3'

生成 Log 文件

集成 adi 库之后便能够对 App 进行性能数据采集,采集方式有两种。

方法一,使用 start/stop 接口

具体代码如下

// 首先进行初始化
ADIManager.init(context)
...
// 在任何想开始采集的地方添加如下代码
val builder = ADIConfig.Builder()
builder.setEventType(ADIConfig.Type.THREAD_MONITOR_CONTEND)// 设置要监控的事件类型
ADIManager.start(activity, builder.build())
...
// 在任何停止采集的地方添加如下代码
ADIManager.stop()
方法二,可交互的悬浮控制窗

控制窗可以在不重新编译的情况下更改 ADI 配置,下面代码展示如何启动控制窗

// 在 Activity 中调用
ADIFloatManager.showADIFloat(activity)

控制窗的使用方法情参考图解

控制窗图解

解析 Log 文件并生成图表

采集的内容存放在 Context.getExternalCacheDir()/ADI 目录下,例如

/sdcard/Android/data/APP 包名/cache/ADI/adi_1570605092.log

取出 log 文件后,需要用adi-analyzer工具分析 log 并生成图表,通过 pip3 安装:

pip3 install adi-analyzer

之后运行 adi-analyzer 并将 log 文件传入:

adi-analyzer ~/adi_1570605092.log

adi-analyzer 会创建 .html 结尾的图表文件,之后会自动启动浏览器打开图表文件,图表效果请参考封面。

功能详解

对象分配监控

在监控对象分配时,ADI 会监控所有 Java 层对象的创建事件,有几点需要注意:

  • 频繁创建对象可能会导致 App 卡顿甚至卡死,可以通过 ADIConfig.sampleIntervalMs 或控制窗配置采样间隔(默认 0.8ms)
  • 调用栈的深度默认是 10,可以通过 ADIConfig.stackDepth 或控制窗修改
  • 如果生成的 Log 文件过大会严重影响图表生成时间,此时建议增加采样间隔或减少整体采样时长

ADI 会为对象事件的 Log 生成两个图表:对象分配数量图表和对象分配大小图表。下面用对象分配数量图表介绍下图表的使用方式。 图表图解

点击体验

多线程竞争监控

在监控多线程竞争时,ADI 会监控所有 Java 层 synchronized 关键字导致的多线程锁竞争事件,以下几点需要注意:

  • 调用栈的深度默认是 10,可以通过 ADIConfig.stackDepth 或控制窗修改
  • 如果生成的 Log 文件过大会严重影响图表生成时间,此时建议减少采样时长

多线程竞争图表的 Y 轴是发生竞争的线程名字,X 轴是时间,具体说明请看图解。 图表图解

点击体验

License

Copyright 2019 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

adi's People

Contributors

zkwlx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.