Matrix工具抓取ANR

接着上一篇文章ANR的处理分析,这里来整理一下Matrix工具的使用。有不对的地方,请大家指出来

1.Matrix 简介:

Matrix 是一款微信研发并日常使用的应用性能接入框架,支持iOS, macOS和Android。 Matrix 通过接入各种性能监控方案,对性能监控项的异常数据进行采集和分析,输出相应的问题分析、定位与优化建议,从而帮助开发者开发出更高质量的应用。

2.使用说明:

​ Matrix-android 当前监控范围包括:应用安装包大小,帧率变化,启动耗时,卡顿,慢方法,SQLite 操作优化,文件读写,内存泄漏等等。

2.1配置Matrix版本:

在gradle.properties目录下配置Matrix版本

MATRIX_VERSION=2.1.0

2.2 AGP8.0.2导入依赖:

由于我是最新稳定版的Studio,AGP版本为8.0以上,所以这里有两种配置方式,后面讲解AGP8.0新的依赖配置方式和改变,这里就直接上代码.

dependencies {implementation 'androidx.appcompat:appcompat:1.6.1'implementation 'com.google.android.material:material:1.9.0'implementation 'androidx.constraintlayout:constraintlayout:2.1.4'testImplementation 'junit:junit:4.13.2'androidTestImplementation 'androidx.test.ext:junit:1.1.5'androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'implementation group: "com.tencent.matrix", name: "matrix-android-lib", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-android-commons", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-trace-canary", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-io-canary", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-memory-canary", version: MATRIX_VERSION, changing: trueimplementation 'com.blankj:utilcodex:1.31.1'
}

 2.3 AGP8.0以下导入依赖:

apply plugin: 'com.android.application'
apply plugin: 'com.tencent.matrix-plugin'matrix {trace {enable = true    //if you don't want to use trace canary, set falsebaseMethodMapFile = "${project.buildDir}/matrix_output/Debug.methodmap"blackListFile = "${project.projectDir}/matrixTrace/blackMethodList.txt"}}dependencies {implementation 'androidx.appcompat:appcompat:1.6.1'implementation 'com.google.android.material:material:1.9.0'implementation 'androidx.constraintlayout:constraintlayout:2.1.4'testImplementation 'junit:junit:4.13.2'androidTestImplementation 'androidx.test.ext:junit:1.1.5'androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'implementation group: "com.tencent.matrix", name: "matrix-android-lib", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-android-commons", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-trace-canary", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-io-canary", version: MATRIX_VERSION, changing: trueimplementation group: "com.tencent.matrix", name: "matrix-memory-canary", version: MATRIX_VERSION, changing: trueimplementation 'com.blankj:utilcodex:1.31.1'
}

2.4 项目的build.gradle配置: 

buildscript {repositories {google()mavenCentral()maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }maven { url 'https://repo1.maven.org/maven2/' }}dependencies {classpath 'com.android.tools.build:gradle:8.0.2'classpath ("com.tencent.matrix:matrix-gradle-plugin:${MATRIX_VERSION}") { changing = true }}
}
plugins {id 'com.android.application' version '8.0.2' apply falseid 'com.android.library' version '8.0.2' apply false
}

3.MatrixUtils工具类:

package com.example.matrixdemo.utils;import android.app.Application;import com.blankj.utilcode.util.LogUtils;
import com.example.matrixdemo.impl.MatrixDynamicConfigImpl;
import com.example.matrixdemo.plugin.MatrixPluginListener;
import com.tencent.matrix.Matrix;
import com.tencent.matrix.iocanary.IOCanaryPlugin;
import com.tencent.matrix.iocanary.config.IOConfig;
import com.tencent.matrix.memory.canary.MemoryCanaryPlugin;
import com.tencent.matrix.trace.TracePlugin;
import com.tencent.matrix.trace.config.TraceConfig;public class MatrixUtils {private static volatile MatrixUtils INSTANCE;private static final String TAG = "MatrixLog";private MatrixUtils() {}public static MatrixUtils getInstance() {if (INSTANCE == null) {synchronized (MatrixUtils.class) {if (INSTANCE == null) {INSTANCE = new MatrixUtils();}}}return INSTANCE;}public void initPlugin(Application application, String splashActivity) {Matrix.Builder builder = new Matrix.Builder(application); // build matrixbuilder.pluginListener(new MatrixPluginListener(application)); // add general pluginListenerMatrixDynamicConfigImpl matrixDynamicConfig = new MatrixDynamicConfigImpl(); // dynamic configboolean fpsEnable = matrixDynamicConfig.isFPSEnable();boolean traceEnable = matrixDynamicConfig.isTraceEnable();//Trace pluginTraceConfig traceConfig = new TraceConfig.Builder().dynamicConfig(matrixDynamicConfig).enableFPS(fpsEnable)//帧率.enableEvilMethodTrace(traceEnable)//慢方法.enableAnrTrace(traceEnable)//anr.enableStartup(traceEnable)//启动速度.splashActivities(splashActivity)//首页//debug模式.isDebug(true)//dev环境.isDevEnv(false).build();TracePlugin tracePlugin = new TracePlugin(traceConfig);builder.plugin(tracePlugin);MemoryCanaryPlugin memoryCanaryPlugin = new MemoryCanaryPlugin();builder.plugin(memoryCanaryPlugin);// io pluginIOCanaryPlugin ioCanaryPlugin = new IOCanaryPlugin(new IOConfig.Builder().dynamicConfig(matrixDynamicConfig).build());builder.plugin(ioCanaryPlugin);//init matrixMatrix.init(builder.build());tracePlugin.start();}
}

4.自定义Matrix动态配置接口

package com.example.matrixdemo.impl;import com.tencent.mrs.plugin.IDynamicConfig;public class MatrixDynamicConfigImpl implements IDynamicConfig {public MatrixDynamicConfigImpl() {}public boolean isFPSEnable() { return true;}public boolean isTraceEnable() { return true; }public boolean isMatrixEnable() { return true; }public boolean isDumpHprof() {  return false;}@Overridepublic String get(String key, String defStr) {return defStr;}@Overridepublic int get(String key, int defInt) {return defInt;}@Overridepublic long get(String key, long defLong) {return defLong;}@Overridepublic boolean get(String key, boolean defBool) {return defBool;}@Overridepublic float get(String key, float defFloat) {return defFloat;}
}

5.自定义插件事件监听:

package com.example.matrixdemo.plugin;import android.content.Context;import com.blankj.utilcode.util.LogUtils;
import com.tencent.matrix.plugin.DefaultPluginListener;
import com.tencent.matrix.report.Issue;
import com.tencent.matrix.util.MatrixLog;public class MatrixPluginListener extends DefaultPluginListener {public static final String TAG = "MatrixPluginListener";public MatrixPluginListener(Context context) {super(context);}@Overridepublic void onReportIssue(Issue issue) {super.onReportIssue(issue);//todo 处理性能监控数据MatrixLog.e(TAG, issue.toString());LogUtils.e(TAG, issue.toString());}
}

6.Matrix初始化:

package com.example.matrixdemo.app;import android.app.Application;import com.example.matrixdemo.utils.MatrixUtils;public class App extends Application {@Overridepublic void onCreate() {super.onCreate();initMatrix();}private void initMatrix() {MatrixUtils.getInstance().initPlugin(this,"com.example.matrixdemo.MainActivity;");}
}

7.简单使用: 

private void testThreadAnr() {try {int number = 0;while (number++ < 5) {LogUtils.e(TAG, "主线程睡眠导致的ANR:次数" + number + "/5");try {Thread.sleep(5000L);} catch (InterruptedException e) {e.printStackTrace();LogUtils.e(TAG, "异常信息为:" + e.getMessage());}}} catch (Throwable e) {e.printStackTrace();LogUtils.e(TAG, "异常信息为:" + e.getMessage());}
}

8.源码地址:

Matrixdemo: 微信性能监控框架Matrix的简单使用

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/635224.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Qt文件和目录相关操作

1.相关说明 QCoreApplication类、QFile类、QDir、QTemporaryDir类、QTemporaryFile类、QFileSystemWatcher类的相关函数 2.相关界面 3.相关代码 #include "dialog.h" #include "ui_dialog.h" #include <QFileDialog> #include <QTemporaryDir>…

Ardupilot开源飞控之VTOL之旅:打印件清单

Ardupilot开源飞控之VTOL之旅&#xff1a;打印件清单 1. 源由2. 清单2.1 模拟VTX打印件2.2 摄像头打印件2.3 GPS & RC天线打印件2.4 飞控 & 电调打印件 3. 总结4. 参考资料 1. 源由 VTOL一直仍在角落吃灰&#xff0c;主要还是手头缺点经费&#xff0c;搞台3D打印机基本…

理解“面向对象编程”概念

面向对象编程&#xff08;Object-Oriented Programming&#xff0c;OOP&#xff09;是一种软件开发范式&#xff0c;它以“对象”为核心&#xff0c;将程序视为一系列相互协作的对象集合。 具体来说&#xff0c;面向对象编程是一种程序设计和开发的范式&#xff0c;其核心理念是…

Kotlin 移动端多平台

支持多平台编程是 Kotlin 的主要优势之一。它减少了为不同平台编写和维护相同代码所花费的时间&#xff0c;同时保留了本机编程的灵活性和优势。 1. 基本概念 KMM&#xff1a;Kotlin Multiplatform for mobile&#xff08;移动设备的 Kotlin 多平台&#xff09; KMM 多平台的主…

16k+ start 一个开源的的监控系统部署教程

安装条件 Linux或macOS系统 4GB内存 开放 33014、33174、3183端口 1.安装 1、下载源码 首先使用 git 克隆源码到本地 git clone -b main https://github.com/SigNoz/signoz.git && cd signoz/deploy/ 方式1&#xff1a;运行 install.sh 脚本一键安装 ./install.s…

Webpack5入门到原理13:开发服务器自动化

每次写完代码都需要手动输入指令才能编译代码&#xff0c;太麻烦了&#xff0c;我们希望一切自动化 1. 下载包 npm i webpack-dev-server -D 2. 配置 webpack.config.js const path require("path"); const ESLintWebpackPlugin require("eslint-webpack…

luffy商城项目(一)

企业项目类型 # 1 面向互联网用户&#xff1a;商城类项目 -微信小程序商城 # 2 面向互联网用户&#xff1a;二手交易类的 -咸鱼 -转转 # 3 公司内部项目&#xff1a;python写的重点 -oa系统 -打卡系统工资核算系统 -第三方公司做的&#xff1a…

深度剖析 Spring 框架在 Java 应用开发中的优势与应用

Spring 是用于企业 Java 应用程序开发的最流行的应用程序开发框架。全球数百万开发人员使用 Spring Framework 创建高性能、易于测试和可重用的代码。Spring Framework 是一个开源的 Java 平台。它最初由 Rod Johnson 编写&#xff0c;并于 2003 年 6 月在 Apache 2.0 许可下首…

监督学习 - 梯度提升机(Gradient Boosting Machines,GBM)

什么是机器学习 梯度提升机&#xff08;Gradient Boosting Machines&#xff0c;GBM&#xff09;是一种集成学习方法&#xff0c;通过将多个弱学习器&#xff08;通常是决策树&#xff09;组合成一个强学习器来提高模型的性能。GBM的训练过程是通过迭代&#xff0c;每一步都根…

leetCode-42.接雨水

&#x1f4d1;前言 本文主要是【算法】——算法模拟的文章&#xff0c;如果有什么需要改进的地方还请大佬指出⛺️ &#x1f3ac;作者简介&#xff1a;大家好&#xff0c;我是听风与他&#x1f947; ☁️博客首页&#xff1a;CSDN主页听风与他 &#x1f304;每日一句&#xff…

git提权

实验环境——vulnhub-dc2靶场 git提权 前提&#xff1a;用户可以使用sudo中git权限 查看sudo权限 sudo -l可以发现git命令存在sudo提权 基于此进行权限提升 方式&#xff1a; sudo git help config #在末行命令模式输入 !/bin/bash 或 !sh #完成提权 sudo git -p help…

直接发文!1D-2D-MTF-CNN-GRU-AT多通道图像时序融合的分类/故障识别程序!Excel导入,直接运行

​适用平台&#xff1a;Matlab2023版本及以上 本程序同时结合两篇国内顶级EI的方法&#xff1a;提出1D-2D-MTF-CNN-GRU-AT多通道图像时序融合的分类/故障识别程序&#xff01; ①中文EI期刊《电力自动化设备》12月29号网络首发文献&#xff1a;《基于格拉姆角场与并行CNN的并…

【PyTorch】PyTorch之Reduction Ops

文章目录 前言一、ARGMAX二、ARGMIN三、AMAX和AMIN四、ALL和ANY五、MAX和MIN六、MEAN七、MEDIAN八、NORM九、PROD十、STD十一、SUM十二、UNIQUE十三、VAR 前言 介绍pytorch的Reduction Ops。 一、ARGMAX torch.argmax(input, dim, keepdimFalse) → LongTensor Parameters&a…

HTTP与HTTPS:网络通信的安全卫士

目录 引言 1. HTTP&#xff08;Hypertext Transfer Protocol&#xff09; 1.1HTTP的基本概念 1.2 HTTP的工作原理 1.3 HTTP请求与响应 1.4HTTP特点 1.4.1 无状态性 1.4.2 明文传输 1.4.3 简单快速 1.5 HTTP的安全性 2. HTTPS&#xff08;Hypertext Transfer Protoco…

UML相关问题及答案(2024)

1、什么是 UML&#xff0c;并且它通常用于什么目的&#xff1f; UML&#xff08;统一建模语言&#xff0c;Unified Modeling Language&#xff09;是一种标准的建模语言&#xff0c;它被广泛地用于软件和系统工程、业务建模以及其他非软件系统的可视化文档。UML 不是一种编程语…

突破Android开发瓶颈:6年Android开发者的实用建议

作为一名在Android领域摸爬滚打6年的老手&#xff0c;我想给那些在这个行业工作了3~5年的朋友们提供一些职业和技术上的建议。 许多开发者在职业生涯中都会遇到一个瓶颈期&#xff0c;尤其是当你在一个公司待了很长时间&#xff0c;感觉自己的技术和业务能力都无法得到提升时。…

多输入多输出 | Matlab实现基于LightGBM多输入多输出预测

多输入多输出 | Matlab实现基于LightGBM多输入多输出预测 目录 多输入多输出 | Matlab实现基于LightGBM多输入多输出预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 Matlab实现基于LightGBM多输入多输出预测&#xff08;完整源码和数据&#xff09; 1.data为数据集&a…

近期学习文章

DNSlog在渗透测试中的实战技巧 - 网安隐藏源IP&#xff0c;提高溯源难度的几种方案 - 网安FreeBuf网络安全行业门户 【漏洞公告】某平台一个有意思的CSRF // SecTrain安全博客 浅谈Web源码泄漏-安全客 - 安全资讯平台 红队-C2 Server基础构建 - 先知社区FreeBuf网络安全行业…

【电力电子在电力系统中的应用】2 CCM和DCM模式下Cuk电路的升降压工作状态

【仅供参考】 【2023.03西南交大电力电子在电力系统中的应用】 目录 0 仿真要求 1 仿真电路搭建及波形记录 1.1 CCM工作模式 1.1.1 升压模式 1.1.2 降压模式 1.2 DCM工作模式 1.2.1 升压模式 1.2.2 降压模式 1.3 改变开关频率和电容参数 1.3.1 改变开关频率 1.3.2 …

高清网络视频监控系统技术方案

目 录 一、概述 二、建设目标及需求 &#xff08;一&#xff09;建设总目标 &#xff08;二&#xff09;需求分析 三、设计依据与设计原则 &#xff08;一&#xff09;设计依据 &#xff08;二&#xff09;设计原则 四、建设方案设计 &#xff08;一&…