[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4066":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":33,"discoverSource":34},4066,"matrix","Tencent\u002Fmatrix","Tencent","Matrix is a plugin style, non-invasive APM system developed by WeChat.","",null,"Java",12019,1927,268,376,0,2,5,15,6,44.86,"Other",false,"master",true,[27,28,29],"android","apm-client","wechat","2026-06-12 02:00:58","![Matrix-icon](assets\u002Fimg\u002Freadme\u002Fheader.png)\n[![license](http:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-BSD3-brightgreen.svg?style=flat)](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fblob\u002Fmaster\u002FLICENSE)\n[![PRs Welcome](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPRs-welcome-brightgreen.svg)](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fpulls)\n[![WeChat Approved](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FWechat%20Approved-2.1.0-red.svg)](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki)\n[![CircleCI](https:\u002F\u002Fcircleci.com\u002Fgh\u002FTencent\u002Fmatrix.svg?style=shield)](https:\u002F\u002Fapp.circleci.com\u002Fpipelines\u002Fgithub\u002FTencent\u002Fmatrix)\n\n(中文版本请参看[这里](#matrix_cn))  \n\n[Matrix for iOS\u002FmacOS 中文版](#matrix_ios_cn)  \n[Matrix for android 中文版](#matrix_android_cn)   \n[Matrix for iOS\u002FmacOS](#matrix_ios_en)   \n[Matrix for android](#matrix_android_en)   \n\n**Matrix** is an APM (Application Performance Manage) used in Wechat to monitor, locate and analyse performance problems. It is a **plugin style**, **non-invasive** solution and is currently available on iOS, macOS and Android.\n\n# \u003Ca name='matrix_ios_en'> Matrix for iOS\u002FmacOS \u003C\u002Fa>\n\nThe monitoring scope of the current tool includes: crash, lag, and memory, which includes the following three plugins:\n\n* **WCCrashBlockMonitorPlugin：** Based on [KSCrash](https:\u002F\u002Fgithub.com\u002Fkstenerud\u002FKSCrash) framework, it features cutting-edge lag stack capture capabilities with crash capture.\n\n* **WCMemoryStatPlugin：** A memory monitoring tool that captures memory allocation and the callstack of an application's memory event.\n\n* **WCFPSMonitorPlugin：** A fps monitoring tool that captures main thread's callstack while user scrolling.\n\n## Features\n\n#### WCCrashBlockMonitorPlugin\n\n* Easy integration, no code intrusion.\n* Determine whether the app is stuck by checking the running status of the Runloop, and support both the iOS and macOS platform.\n* Add time-consuming stack fetching, attaching the most time-consuming main thread stack to the thread snapshot log.\n\n#### WCMemoryStatPlugin\n\n* Live recording every object's creating and the corresponding callstack of its creation, and report it when the application out-of-memory is detected.\n\n## Getting Started\n#### Install\n\n* **Install with static framework**\n  1. Get source code of Matrix;\n  2. Open terminal, execute `make` in the `matrix\u002Fmatrix-iOS` directory to compile and generate static library. After compiling, the iOS platform library is in the `matrix\u002Fmatrix-iOS\u002Fbuild_ios` directory, and the macOS platform library is in the `matrix\u002Fmatrix-iOS\u002Fbuild_macos` directory.\n  3. Link with static framework in the project:\n    * iOS : Use `Matrix.framework` under the `matrix\u002Fmatrix-iOS\u002Fbuild_ios` path, link `Matrix.framework` to the project as a static library;\n    * macOS : Use `Matrix.framework` under the `matrix\u002Fmatrix-iOS\u002Fbuild_macos` path, link `Matrix.framework` to the project as a static library.\n  4. Add `#import \u003CMatrix\u002FMatrix.h>`, then you can use the performance probe tool of WeChat.\n\n#### Start the plugins\n\nIn the following places:\n\n* Program `main` function;\n* `application:didFinishLaunchingWithOptions:` of  `AppDelegate`;\n* Or other places running as earlier as possible after application launching.\n\nAdd a code similar to the following to start the plugin:\n\n```objective-c\n#import \u003CMatrix\u002FMatrix.h>\n  \nMatrix *matrix = [Matrix sharedInstance];\nMatrixBuilder *curBuilder = [[MatrixBuilder alloc] init];\ncurBuilder.pluginListener = self; \u002F\u002F get the related event of plugin via the callback of the pluginListener\n    \nWCCrashBlockMonitorPlugin *crashBlockPlugin = [[WCCrashBlockMonitorPlugin alloc] init];    \n[curBuilder addPlugin:crashBlockPlugin]; \u002F\u002F add lag and crash monitor.\n    \nWCMemoryStatPlugin *memoryStatPlugin = [[WCMemoryStatPlugin alloc] init];\n[curBuilder addPlugin:memoryStatPlugin]; \u002F\u002F add memory monitor.\n\nWCFPSMonitorPlugin *fpsMonitorPlugin = [[WCFPSMonitorPlugin alloc] init];\n[curBuilder addPlugin:fpsMonitorPlugin]; \u002F\u002F add fps monitor.\n    \n[matrix addMatrixBuilder:curBuilder];\n    \n[crashBlockPlugin start]; \u002F\u002F start the lag and crash monitor.\n[memoryStatPlugin start]; \u002F\u002F start memory monitor\n[fpsMonitorPlugin start]; \u002F\u002F start fps monitor\n```\n\n#### Receive callbacks to obtain monitoring data\n\nSet `pluginListener` of the `MatrixBuilder` object, implement the `MatrixPluginListenerDelegate`\n\n```objective-c\n\u002F\u002F set delegate\n\nMatrixBuilder *curBuilder = [[MatrixBuilder alloc] init];\ncurBuilder.pluginListener = \u003Cobject conforms to MatrixPluginListenerDelegate>; \n\n\u002F\u002F MatrixPluginListenerDelegate\n\n- (void)onInit:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onStart:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onStop:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onDestroy:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onReportIssue:(MatrixIssue *)issue;\n```\n\nEach plugin added to `MatrixBuilder` will call back the corresponding event via `pluginListener`.\n\n**Important: Get the monitoring data of the Matrix via `onReportIssue:`, the data format info reference to [Matrix for iOS\u002FmacOS Data Format Description](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki\u002FMatrix-for-iOS-macOS-Data-Format-Description)**\n\n## Tutorials\n\nAt this point, Matrix has been integrated into the app and is beginning to collect crash, lag, and memory data. If you still have questions, check out the example: `samples\u002Fsample-iOS\u002FMatrixDemo`.\n\n\n\n# \u003Ca name='matrix_android_en'> Matrix for android \u003C\u002Fa>\n\n## Plugins\n\n- **APK Checker:**\n\n  Analyse the APK package, give suggestions of reducing the APK's size; Compare two APK and find out the most significant increment on size\n\n- **Resource Canary:**\n\n  Detect the activity leak and bitmap duplication basing on WeakReference and [Square Haha](https:\u002F\u002Fgithub.com\u002Fsquare\u002Fhaha) \n\n- **Trace Canary:**\n\n  FPS Monitor, Startup Performance, ANR, UI-Block \u002F Slow Method Detection\n\n- **SQLite Lint:**\n\n  Evaluate the quality of SQLite statement automatically by using SQLite official tools\n\n- **IO Canary:**\n\n  Detect the file IO issues, including performance of file IO and closeable leak \n\n- **Battery Canary:**\n\n  App thread activities monitor (Background watch & foreground loop watch), Sonsor usage monitor (WakeLock\u002FAlarm\u002FGps\u002FWifi\u002FBluetooth), Background network activities (Wifi\u002FMobile) monitor.\n  \n- **MemGuard**\n\n  Detect heap memory overlap, use-after-free and double free issues.\n\n\n## Features\n#### APK Checker\n\n- **Easy-to-use.** Matrix provides a JAR tool, which is more convenient to apply to your integration systems. \n- **More features.** In addition to APK Analyzer, Matrix find out the R redundancies, the dynamic libraries statically linked STL, unused resources, and supports custom checking rules.\n- **Visual Outputs.** supports HTML and JSON outputs.\n\n#### Resource Canary\n\n- **Separated detection and analysis.** Make possible to use in automated test and in release versions (monitor only).\n- **Pruned Hprof.** Remove the useless data in hprof and easier to upload.\n- **Detection of duplicate bitmap.** \n\n#### Trace Canary\n\n- **High performance.** Dynamically modify bytecode at compile time, record function cost and call stack with little performance loss.\n- **Accurate call stack of ui-block.** Provide informations such as call stack, function cost, execution times to solve the problem of ui-block quickly.\n- **Non-hack.** High compatibility to Android versions.\n- **More features.** Automatically covers multiple fluency indicators such as ui-block, startup time, activity switching, slow function detection.\n- **High-accuracy ANR detector.**  Detect ANRs accurately and give ANR trace file with high compatibility and high stability.\n\n#### SQLite Lint\n\n- **Easy-to-use.** Non-invasive.\n- **High applicability.** Regardless of the amount of data, you can discover SQLite performance problems during development and testing.\n- **High standards.** Detection algorithms based on best practices, make SQLite statements to the highest quality.\n- **May support multi-platform.** Implementing in C++ makes it possible to support multi-platform.\n\n#### IO Canary\n- **Easy-to-use.** Non-invasive.\n- **More feature.** Including performance of file IO and closeable leak.\n- **Compatible with Android P.**\n\n#### Battery Canary\n- **Easy-to-use.** Use out of box (unit tests as example).\n- **More feature.** Flexible extending with base and utils APIs.\n\n#### Memory Hook\n\n- A native memory leak detection tool for Android.\n- **Non-invasive.** It is based on PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook)), so we do NOT need to recompile the native libraries.\n- **High performance.** we use WeChat-Backtrace for fast unwinding which supports both aarch64 and armeabi-v7a architectures.\n\n#### Pthread Hook\n\n- A Java and native thread leak detection and native thread stack space trimming tool for Android.\n- **Non-invasive.** It is based on PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook)), so we do NOT need to recompile the native libraries.\n- It saves virtual memory overhead by trimming default stack size of native thread in half, which can reduce crashes caused by virtual memory insufficient under 32bit environment.\n\n#### WVPreAllocHook\n\n+ A tool for saving virtual memory overhead caused by WebView preloading when WebView is not actually used. It's useful for reducing crashes caused by virtual memory insufficient under 32bit environment.\n+ **Non-invasive.** It is based on PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook)), so we do NOT need to recompile the native libraries.\n+ WebView still works after using this tool.\n\n#### MemGuard\n\n+ A tool base on GWP-Asan to detect heap memory issues.\n+ **Non-invasive.** It is based on PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook)), so we do NOT need to recompile the native libraries.\n+ It's able to apply on specific libraries that needs to be detected by RegEx.\n\n+ It detects heap memory accessing overlap, use-after-free and double free issues.\n\n\n#### Backtrace Component\n\n- A fast native backtrace component designed by Matrix based on quicken unwind tables that are generated and simplified from DWARF and ARM exception handling informations. It is about 15x ~ 30x faster than libunwindstack.\n\n\n## Getting Started\n***The JCenter repository will stop service on February 1, 2022. So we uploaded Matrix(since 0.8.0) to the MavenCentral repository.***\n\n1. Configure `MATRIX_VERSION` in gradle.properties.\n``` gradle\n  MATRIX_VERSION=2.1.0\n```\n\n2. Add `matrix-gradle-plugin` in your build.gradle:\n``` gradle \n  dependencies {\n      classpath (\"com.tencent.matrix:matrix-gradle-plugin:${MATRIX_VERSION}\") { changing = true }\n  }\n \n```\n3. Add dependencies to your app\u002Fbuild.gradle.\n\n``` gradle\n  dependencies {\n    implementation group: \"com.tencent.matrix\", name: \"matrix-android-lib\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-android-commons\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-trace-canary\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-resource-canary-android\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-resource-canary-common\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-io-canary\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-sqlite-lint-android-sdk\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-battery-canary\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-hooks\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-backtrace\", version: MATRIX_VERSION, changing: true\n  }\n  \n  apply plugin: 'com.tencent.matrix-plugin'\n  matrix {\n    trace {\n        enable = true\t\u002F\u002Fif you don't want to use trace canary, set false\n        baseMethodMapFile = \"${project.buildDir}\u002Fmatrix_output\u002FDebug.methodmap\"\n        blackListFile = \"${project.projectDir}\u002FmatrixTrace\u002FblackMethodList.txt\"\n    }\n  }\n```\n\n4. Implement `PluginListener` to receive data processed by Matrix.\n\n``` java\n  public class TestPluginListener extends DefaultPluginListener {\n    public static final String TAG = \"Matrix.TestPluginListener\";\n    public TestPluginListener(Context context) {\n        super(context);\n        \n    }\n\n    @Override\n    public void onReportIssue(Issue issue) {\n        super.onReportIssue(issue);\n        MatrixLog.e(TAG, issue.toString());\n        \n        \u002F\u002Fadd your code to process data\n    }\n}\n```\n\nMatrix gradle plugin could work with Android Gradle Plugin 3.5.0\u002F4.0.0\u002F4.1.0 currently.\n\n5. Implement `DynamicConfig` to change parameters of Matrix.\n``` java\n  public class DynamicConfigImplDemo implements IDynamicConfig {\n    public DynamicConfigImplDemo() {}\n\n    public boolean isFPSEnable() { return true;}\n    public boolean isTraceEnable() { return true; }\n    public boolean isMatrixEnable() { return true; }\n    public boolean isDumpHprof() {  return false;}\n\n    @Override\n    public String get(String key, String defStr) {\n        \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public int get(String key, int defInt) {\n      \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public long get(String key, long defLong) {\n        \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public boolean get(String key, boolean defBool) {\n        \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public float get(String key, float defFloat) {\n        \u002F\u002Fhook to change default values\n    }\n}\n```\n\n6. Init Matrix in the ```onCreate``` of your application. \n\n``` java \n  Matrix.Builder builder = new Matrix.Builder(application); \u002F\u002F build matrix\n  builder.patchListener(new TestPluginListener(this)); \u002F\u002F add general pluginListener\n  DynamicConfigImplDemo dynamicConfig = new DynamicConfigImplDemo(); \u002F\u002F dynamic config\n  \n  \u002F\u002F init plugin \n  IOCanaryPlugin ioCanaryPlugin = new IOCanaryPlugin(new IOConfig.Builder()\n                    .dynamicConfig(dynamicConfig)\n                    .build());\n  \u002F\u002Fadd to matrix               \n  builder.plugin(ioCanaryPlugin);\n  \n  \u002F\u002Finit matrix\n  Matrix.init(builder.build());\n\n  \u002F\u002F start plugin \n  ioCanaryPlugin.start();\n```\nFor more Matrix configurations, look at the [sample](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Ftree\u002Fdev\u002Fsamples\u002Fsample-android).\n\nNote:\n1. Since Matrix for Android has migrated to AndroidX since v0.9.0. You may need to add 'android.useAndroidX=true' flag to gradle.properties\n2. You can get more about Matrix output at the wiki [The output of Matrix](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki\u002FMatrix-Android--data-format); \n\n\n#### Battery Canary Usage\n\nInit BatteryCanary as the following codes:\n```java\nBatteryMonitorConfig config = new BatteryMonitorConfig.Builder()\n        .enable(JiffiesMonitorFeature.class)\n        .enableStatPidProc(true)\n        .greyJiffiesTime(30 * 1000L)\n        .setCallback(new BatteryMonitorCallback.BatteryPrinter())\n        .build();\n\nBatteryMonitorPlugin plugin = new BatteryMonitorPlugin(config);\n```\n\nFor detail usage, please reference showcase tests at `com.tencent.matrix.batterycanary.ApisTest` or `sample.tencent.matrix.battery.BatteryCanaryInitHelper`.\n\n#### Backtrace Component Usage\n\nHow to init backtrace component：\n```java\nWeChatBacktrace.instance().configure(getApplicationContext()).commit();\n```\n\nThen other components in Matrix could use Quikcen Backtrace to unwind stacktrace. See more configuration comments in 'WeChatBacktrace.Configuration'.\n\n#### APK Checker Usage\n\nAPK Checker can run independently in Jar ([matrix-apk-canary-2.1.0.jar](https:\u002F\u002Frepo.maven.apache.org\u002Fmaven2\u002Fcom\u002Ftencent\u002Fmatrix\u002Fmatrix-apk-canary\u002F2.1.0\u002Fmatrix-apk-canary-2.1.0.jar)）  mode, usage:\n\n\n```shell\njava -jar matrix-apk-canary-2.1.0.jar\nUsages: \n    --config CONFIG-FILE-PATH\nor\n    [--input INPUT-DIR-PATH] [--apk APK-FILE-PATH] [--unzip APK-UNZIP-PATH] [--mappingTxt MAPPING-FILE-PATH] [--resMappingTxt RESGUARD-MAPPING-FILE-PATH] [--output OUTPUT-PATH] [--format OUTPUT-FORMAT] [--formatJar OUTPUT-FORMAT-JAR] [--formatConfig OUTPUT-FORMAT-CONFIG (json-array format)] [Options]\n    \nOptions:\n-manifest\n     Read package info from the AndroidManifest.xml.\n-fileSize [--min DOWN-LIMIT-SIZE (KB)] [--order ORDER-BY ('asc'|'desc')] [--suffix FILTER-SUFFIX-LIST (split by ',')]\n     Show files whose size exceed limit size in order.\n-countMethod [--group GROUP-BY ('class'|'package')]\n     Count methods in dex file, output results group by class name or package name.\n-checkResProguard\n     Check if the resguard was applied.\n-findNonAlphaPng [--min DOWN-LIMIT-SIZE (KB)]\n     Find out the non-alpha png-format files whose size exceed limit size in desc order.\n-checkMultiLibrary\n     Check if there are more than one library dir in the 'lib'.\n-uncompressedFile [--suffix FILTER-SUFFIX-LIST (split by ',')]\n     Show uncompressed file types.\n-countR\n     Count the R class.\n-duplicatedFile\n     Find out the duplicated resource files in desc order.\n-checkMultiSTL  --toolnm TOOL-NM-PATH\n     Check if there are more than one shared library statically linked the STL.\n-unusedResources --rTxt R-TXT-FILE-PATH [--ignoreResources IGNORE-RESOURCES-LIST (split by ',')]\n     Find out the unused resources.\n-unusedAssets [--ignoreAssets IGNORE-ASSETS-LIST (split by ',')]\n     Find out the unused assets file.\n-unstrippedSo  --toolnm TOOL-NM-PATH\n     Find out the unstripped shared library file.\n```\n\nLearn more about [Matrix-APKChecker](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki\u002FMatrix-Android-ApkChecker) \n\n\n# Support\n\nAny problem?\n\n1. Learn more from [Sample](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Ftree\u002Fmaster\u002Fsamples\u002F)\n2. [Source Code](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Ftree\u002Fmaster\u002Fmatrix)\n3. [Wiki](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki) & [FAQ](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Fwiki\u002FMatrix-%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)\n4. Contact us for help\n\n# Contributing\n\nIf you are interested in contributing, check out the [CONTRIBUTING.md](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Fblob\u002Fmaster\u002FCONTRIBUTING.md), also join our [Tencent OpenSource Plan](https:\u002F\u002Fopensource.tencent.com\u002Fcontribution).\n\n# License\n\nMatrix is under the BSD license. See the [LICENSE](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Fblob\u002Fmaster\u002FLICENSE) file for details\n\n------\n\n# \u003Ca name=\"matrix_cn\">Matrix\u003C\u002Fa>\n![Matrix-icon](assets\u002Fimg\u002Freadme\u002Fheader.png)\n[![license](http:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-BSD3-brightgreen.svg?style=flat)](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fblob\u002Fmaster\u002FLICENSE)[![PRs Welcome](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPRs-welcome-brightgreen.svg)](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fpulls)  [![WeChat Approved](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FWechat%20Approved-2.1.0-red.svg)](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki)\n\n**Matrix** 是一款微信研发并日常使用的应用性能接入框架，支持iOS, macOS和Android。\nMatrix 通过接入各种性能监控方案，对性能监控项的异常数据进行采集和分析，输出相应的问题分析、定位与优化建议，从而帮助开发者开发出更高质量的应用。\n\n# \u003Ca name='matrix_ios_cn'>Matrix for iOS\u002FmacOS \u003C\u002Fa>\n\nMatrix-iOS 当前工具监控范围包括：崩溃、卡顿和内存，包含以下三款插件：\n\n* **WCCrashBlockMonitorPlugin：** 基于 [KSCrash](https:\u002F\u002Fgithub.com\u002Fkstenerud\u002FKSCrash) 框架开发，具有业界领先的卡顿堆栈捕获能力，同时兼备崩溃捕获能力\n\n* **WCMemoryStatPlugin：** 一款性能极致的内存监控工具，能够全面捕获应用 OOM 时的内存分配以及调用堆栈情况\n\n* **WCFPSMonitorPlugin：** 一款 FPS 监控工具，当用户滑动界面时，记录主线程调用栈\n\n## 特性\n\n#### WCCrashBlockMonitorPlugin\n\n* 接入简单，代码无侵入\n* 通过检查 Runloop 运行状态判断应用是否卡顿，同时支持 iOS\u002FmacOS 平台\n* 增加耗时堆栈提取，卡顿线程快照日志中附加最近时间最耗时的主线程堆栈\n\n#### WCMemoryStatPlugin\n\n* 在应用运行期间获取对象存活以及相应的堆栈信息，在检测到应用 OOM 时进行上报\n\n## 使用方法\n\n#### 安装\n\n* **通过静态库安装**\n  1. 获取 Matrix 源码；\n  2. 打开命令行，在 `matrix\u002Fmatrix-iOS` 代码目录下执行 `make` 进行编译生成静态库；编译完成后，iOS 平台的库在 `matrix\u002Fmatrix-iOS\u002Fbuild_ios` 目录下，macOS 平台的库在 `matrix\u002Fmatrix-iOS\u002Fbuild_macos` 目录下；\n  3. 工程引入静态库：\n    * iOS 平台：使用 `matrix\u002Fmatrix-iOS\u002Fbuild_ios` 路径下的 `Matrix.framework`，将 `Matrix.framework` 以静态库的方式引入工程；\n    * macOS 平台：使用 `matrix\u002Fmatrix-iOS\u002Fbuild_macos` 路径下的 `Matrix.framework`，将 `Matrix.framework` 以静态库的方式引入工程。\n  4. 添加头文件 `#import \u003CMatrix\u002FMatrix.h>`，就可以接入微信的性能探针工具了！\n\n\n#### 启动监控\n\n在以下地方：\n\n* 程序 `main` 函数入口；\n* `AppDelegate` 中的 `application:didFinishLaunchingWithOptions:`；\n* 或者其他应用启动比较早的时间点。\n\n添加类似如下代码，启动插件：\n\n```\n#import \u003CMatrix\u002FMatrix.h>\n  \nMatrix *matrix = [Matrix sharedInstance];\nMatrixBuilder *curBuilder = [[MatrixBuilder alloc] init];\ncurBuilder.pluginListener = self; \u002F\u002F pluginListener 回调 plugin 的相关事件\n    \nWCCrashBlockMonitorPlugin *crashBlockPlugin = [[WCCrashBlockMonitorPlugin alloc] init];    \n[curBuilder addPlugin:crashBlockPlugin]; \u002F\u002F 添加卡顿和崩溃监控\n    \nWCMemoryStatPlugin *memoryStatPlugin = [[WCMemoryStatPlugin alloc] init];\n[curBuilder addPlugin:memoryStatPlugin]; \u002F\u002F 添加内存监控功能\n\nWCFPSMonitorPlugin *fpsMonitorPlugin = [[WCFPSMonitorPlugin alloc] init];\n[curBuilder addPlugin:fpsMonitorPlugin]; \u002F\u002F 添加 fps 监控功能\n    \n[matrix addMatrixBuilder:curBuilder];\n    \n[crashBlockPlugin start]; \u002F\u002F 开启卡顿和崩溃监控\n[memoryStatPlugin start]; \u002F\u002F 开启内存监控\n[fpsMonitorPlugin start]; \u002F\u002F 开启 fps 监控\n```\n\n#### 接收回调获得监控数据\n\n设置 MatrixBuilder 对象中的 pluginListener，实现 MatrixPluginListenerDelegate。\n\n```\n\u002F\u002F 设置 delegate\n\nMatrixBuilder *curBuilder = [[MatrixBuilder alloc] init];\ncurBuilder.pluginListener = \u003C一个遵循 MatrixPluginListenerDelegate 的对象>; \n\n\u002F\u002F MatrixPluginListenerDelegate\n\n- (void)onInit:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onStart:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onStop:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onDestroy:(id\u003CMatrixPluginProtocol>)plugin;\n- (void)onReportIssue:(MatrixIssue *)issue;\n```\n\n各个添加到 MatrixBuilder 的 plugin 会将对应的事件通过 pluginListener 回调。\n\n**重要：通过 `onReportIssue:` 获得 Matrix 处理后的数据，监控数据格式详见：[Matrix for iOS\u002FmacOS 数据格式说明](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki\u002FMatrix-for-iOS-macOS-%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E)**\n\n## Demo\n\n至此，Matrix 已经集成到应用中并且开始收集崩溃、卡顿和爆内存数据，如仍有疑问，请查看示例：`samples\u002Fsample-iOS\u002FMatrixDemo`\n\n\n# \u003Ca name='matrix_android_cn'>Matrix for Android \u003C\u002Fa>\n\nMatrix-android 当前监控范围包括：应用安装包大小，帧率变化，启动耗时，卡顿，慢方法，SQLite 操作优化，文件读写，内存泄漏等等。\n- APK Checker:\n  针对 APK 安装包的分析检测工具，根据一系列设定好的规则，检测 APK 是否存在特定的问题，并输出较为详细的检测结果报告，用于分析排查问题以及版本追踪\n  \n- Resource Canary:\n  基于 WeakReference 的特性和 [Square Haha](https:\u002F\u002Fgithub.com\u002Fsquare\u002Fhaha) 库开发的 Activity 泄漏和 Bitmap 重复创建检测工具\n  \n- Trace Canary:\n  监控ANR、界面流畅性、启动耗时、页面切换耗时、慢函数及卡顿等问题\n  \n- SQLite Lint:\n  按官方最佳实践自动化检测 SQLite 语句的使用质量\n  \n- IO Canary:\n  检测文件 IO 问题，包括：文件 IO 监控和 Closeable Leak 监控\n  \n- Battery Canary:\n  监控 App 活跃线程（待机状态 & 前台 Loop 监控）、ASM 调用 (WakeLock\u002FAlarm\u002FGps\u002FWifi\u002FBluetooth 等传感器)、 后台流量 (Wifi\u002F移动网络)等 Battery Historian 统计 App 耗电的数据\n  \n- MemGuard\n\n  检测堆内存访问越界、使用释放后的内存、重复释放等问题\n\n## 特性\n\n与常规的 APM 工具相比，Matrix 拥有以下特点：\n\n#### APK Checker\n\n- 具有更好的可用性：JAR 包方式提供，更方便应用到持续集成系统中，从而追踪和对比每个 APK 版本之间的变化\n- 更多的检查分析功能：除具备 APKAnalyzer 的功能外，还支持统计 APK 中包含的 R 类、检查是否有多个动态库静态链接了 STL 、搜索 APK 中包含的无用资源，以及支持自定义检查规则等\n- 输出的检查结果更加详实：支持可视化的 HTML 格式，便于分析处理的 JSON ，自定义输出等等\n\n#### Resource Canary\n\n- 分离了检测和分析部分，便于在不打断自动化测试的前提下持续输出分析后的检测结果\n- 对检测部分生成的 Hprof 文件进行了裁剪，移除了大部分无用数据，降低了传输 Hprof 文件的开销\n- 增加了重复 Bitmap 对象检测，方便通过减少冗余 Bitmap 数量，降低内存消耗\n\n#### Trace Canary\n\n- 编译期动态修改字节码, 高性能记录执行耗时与调用堆栈\n- 准确的定位到发生卡顿的函数，提供执行堆栈、执行耗时、执行次数等信息，帮助快速解决卡顿问题\n- 自动涵盖卡顿、启动耗时、页面切换、慢函数检测等多个流畅性指标\n- 准确监控ANR，并且能够高兼容性和稳定性地保存系统产生的ANR Trace文件\n\n#### SQLite Lint\n\n- 接入简单，代码无侵入\n- 数据量无关，开发、测试阶段即可发现SQLite性能隐患\n- 检测算法基于最佳实践，高标准把控SQLite质量*\n- 底层是 C++ 实现，支持多平台扩展\n\n#### IO Canary\n\n- 接入简单，代码无侵入\n- 性能、泄漏全面监控，对 IO 质量心中有数\n- 兼容到 Android P\n\n#### Battery Canary\n\n- 接入简单，开箱即用\n- 预留 Base 类和 Utility 工具以便扩展监控特性\n\n#### Memory Hook\n\n- 一个检测 Android native 内存泄漏的工具\n- 无侵入，基于 PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook))，无需重编 native 库\n- 高性能，基于 Wechat-Backtrace 进行快速 unwind 堆栈，支持 aarch64 和 armeabi-v7a 架构\n\n#### Pthread Hook\n\n- 一个检测 Android Java 和 native 线程泄漏及缩减 native 线程栈空间的工具\n- 无侵入，基于 PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook))，无需重编 native 库\n- 通过对 native 线程的默认栈大小进行减半降低线程带来的虚拟内存开销，在 32 位环境下可缓解虚拟内存不足导致的崩溃问题\n\n#### WVPreAllocHook\n\n+ 一个用于安全释放 WebView 预分配内存以在不加载 WebView 时节省虚拟内存的工具，在 32 位环境下可缓解虚拟内存不足导致的崩溃问题\n+ 无侵入，基于 PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook))，无需重编 native 库\n+ 使用该工具后 WebView 仍可正常工作\n\n#### MemGuard\n\n+ 一个基于 GWP-Asan 修改的堆内存问题检测工具\n+ 无侵入，基于 PLT-hook([iqiyi\u002FxHook](https:\u002F\u002Fgithub.com\u002Fiqiyi\u002FxHook))，无需重编 native 库\n+ 可根据正则表达式指定被检测的目标库\n+ 可检测堆内存访问越界、使用释放后的内存和双重释放等问题\n\n#### Backtrace Component\n- 基于 DWARF 以及 ARM 异常处理数据进行简化并生成全新的 quicken unwind tables 数据，用于实现可快速回溯 native 调用栈的 backtrace 组件。回溯速度约是 libunwindstack 的 15x ~ 30x 左右。\n\n## 使用方法\n\n***由于 JCenter 服务将于 2022 年 2 月 1 日下线，我们已将 Matrix 新版本（>= 0.8.0) maven repo 发布至 MavenCentral。***\n\n1. 在你项目根目录下的 gradle.properties 中配置要依赖的 Matrix 版本号，如：\n``` gradle\n  MATRIX_VERSION=2.1.0\n```\n\n2. 在你项目根目录下的 build.gradle 文件添加 Matrix 依赖，如：\n``` gradle \n  dependencies {\n      classpath (\"com.tencent.matrix:matrix-gradle-plugin:${MATRIX_VERSION}\") { changing = true }\n  }\n```\n\n3. 接着，在 app\u002Fbuild.gradle 文件中添加 Matrix 各模块的依赖，如：\n``` gradle\n  dependencies {\n    implementation group: \"com.tencent.matrix\", name: \"matrix-android-lib\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-android-commons\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-trace-canary\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-resource-canary-android\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-resource-canary-common\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-io-canary\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-sqlite-lint-android-sdk\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-battery-canary\", version: MATRIX_VERSION, changing: true\n    implementation group: \"com.tencent.matrix\", name: \"matrix-hooks\", version: MATRIX_VERSION, changing: true\n  }\n\n  apply plugin: 'com.tencent.matrix-plugin'\n  matrix {\n    trace {\n        enable = true\t\u002F\u002Fif you don't want to use trace canary, set false\n        baseMethodMapFile = \"${project.buildDir}\u002Fmatrix_output\u002FDebug.methodmap\"\n        blackListFile = \"${project.projectDir}\u002FmatrixTrace\u002FblackMethodList.txt\"\n    }\n  }\n```\n\n目前 Matrix gradle plugin 支持 Android Gradle Plugin 3.5.0\u002F4.0.0\u002F4.1.0。\n\n4. 实现 PluginListener，接收 Matrix 处理后的数据, 如：\n``` java\n  public class TestPluginListener extends DefaultPluginListener {\n    public static final String TAG = \"Matrix.TestPluginListener\";\n    public TestPluginListener(Context context) {\n        super(context);\n        \n    }\n\n    @Override\n    public void onReportIssue(Issue issue) {\n        super.onReportIssue(issue);\n        MatrixLog.e(TAG, issue.toString());\n        \n        \u002F\u002Fadd your code to process data\n    }\n}\n```\n\n5. 实现动态配置接口， 可修改 Matrix 内部参数. 在 sample-android 中 我们有个简单的动态接口实例[DynamicConfigImplDemo.java](samples\u002Fsample-android\u002Fapp\u002Fsrc\u002Fmain\u002Fjava\u002Fsample\u002Ftencent\u002Fmatrix\u002Fconfig\u002FDynamicConfigImplDemo.java), 其中参数对应的 key 位于文件 [MatrixEnum](samples\u002Fsample-android\u002Fapp\u002Fsrc\u002Fmain\u002Fjava\u002Fsample\u002Ftencent\u002Fmatrix\u002Fconfig\u002FMatrixEnum.java)中， 摘抄部分示例如下：\n``` java\n  public class DynamicConfigImplDemo implements IDynamicConfig {\n    public DynamicConfigImplDemo() {}\n\n    public boolean isFPSEnable() { return true;}\n    public boolean isTraceEnable() { return true; }\n    public boolean isMatrixEnable() { return true; }\n    public boolean isDumpHprof() {  return false;}\n\n    @Override\n    public String get(String key, String defStr) {\n        \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public int get(String key, int defInt) {\n         \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public long get(String key, long defLong) {\n        \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public boolean get(String key, boolean defBool) {\n        \u002F\u002Fhook to change default values\n    }\n\n    @Override\n    public float get(String key, float defFloat) {\n        \u002F\u002Fhook to change default values\n    }\n}\n\n```\n6. 选择程序启动的位置对 Matrix 进行初始化，如在 Application 的继承类中， Init 核心逻辑如下：\n``` java \n  Matrix.Builder builder = new Matrix.Builder(application); \u002F\u002F build matrix\n  builder.pluginListener(new TestPluginListener(this)); \u002F\u002F add general pluginListener\n  DynamicConfigImplDemo dynamicConfig = new DynamicConfigImplDemo(); \u002F\u002F dynamic config\n  \n  \u002F\u002F init plugin \n  IOCanaryPlugin ioCanaryPlugin = new IOCanaryPlugin(new IOConfig.Builder()\n                    .dynamicConfig(dynamicConfig)\n                    .build());\n  \u002F\u002Fadd to matrix               \n  builder.plugin(ioCanaryPlugin);\n  \n  \u002F\u002Finit matrix\n  Matrix.init(builder.build());\n\n  \u002F\u002F start plugin \n  ioCanaryPlugin.start();\n```\n\n至此，Matrix就已成功集成到你的项目中，并且开始收集和分析性能相关异常数据，如仍有疑问，请查看 [示例](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Ftree\u002Fdev\u002Fsamples\u002Fsample-android\u002F).\n\nPS：\n1. 从 v0.9.0 开始，Matrix for Android 迁移到了 AndroidX. 你可能需要添加 'android.useAndroidX=true' 标志到 gradle.properties 文件里。\n2. Matrix 分析后的输出字段的含义请查看 [Matrix 输出内容的含义解析](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki\u002FMatrix-Android--data-format)\n\n\n#### Battery Canary Usage\n\n相关初始化代码如下：\n```java\nBatteryMonitorConfig config = new BatteryMonitorConfig.Builder()\n        .enable(JiffiesMonitorFeature.class)\n        .enableStatPidProc(true)\n        .greyJiffiesTime(30 * 1000L)\n        .setCallback(new BatteryMonitorCallback.BatteryPrinter())\n        .build();\n\nBatteryMonitorPlugin plugin = new BatteryMonitorPlugin(config);\n```\n\n具体使用方式，请参考单元测试里相关用例的代码： `com.tencent.matrix.batterycanary.ApisTest` 或 `sample.tencent.matrix.battery.BatteryCanaryInitHelper`.\n\n#### Backtrace Component Usage\n\n如何初始化 backtrace 组件：\n```java\nWeChatBacktrace.instance().configure(getApplicationContext()).commit();\n```\n\n初始化后其他 Matrix 组件就可以使用 Quicken Backtrace 进行回溯。更多参数的配置请查看 WeChatBacktrace.Configuration 的接口注释。\n\n#### APK Checker\n\nAPK Check 以独立的 jar 包提供 ([matrix-apk-canary-2.1.0.jar](https:\u002F\u002Frepo.maven.apache.org\u002Fmaven2\u002Fcom\u002Ftencent\u002Fmatrix\u002Fmatrix-apk-canary\u002F2.1.0\u002Fmatrix-apk-canary-2.1.0.jar)），你可以运行：\n\n```cmd\njava -jar matrix-apk-canary-2.1.0.jar\n```\n\n查看 Usages 来使用它。\n\n```\nUsages: \n    --config CONFIG-FILE-PATH\nor\n    [--input INPUT-DIR-PATH] [--apk APK-FILE-PATH] [--unzip APK-UNZIP-PATH] [--mappingTxt MAPPING-FILE-PATH] [--resMappingTxt RESGUARD-MAPPING-FILE-PATH] [--output OUTPUT-PATH] [--format OUTPUT-FORMAT] [--formatJar OUTPUT-FORMAT-JAR] [--formatConfig OUTPUT-FORMAT-CONFIG (json-array format)] [Options]\n    \nOptions:\n-manifest\n     Read package info from the AndroidManifest.xml.\n-fileSize [--min DOWN-LIMIT-SIZE (KB)] [--order ORDER-BY ('asc'|'desc')] [--suffix FILTER-SUFFIX-LIST (split by ',')]\n     Show files whose size exceed limit size in order.\n-countMethod [--group GROUP-BY ('class'|'package')]\n     Count methods in dex file, output results group by class name or package name.\n-checkResProguard\n     Check if the resguard was applied.\n-findNonAlphaPng [--min DOWN-LIMIT-SIZE (KB)]\n     Find out the non-alpha png-format files whose size exceed limit size in desc order.\n-checkMultiLibrary\n     Check if there are more than one library dir in the 'lib'.\n-uncompressedFile [--suffix FILTER-SUFFIX-LIST (split by ',')]\n     Show uncompressed file types.\n-countR\n     Count the R class.\n-duplicatedFile\n     Find out the duplicated resource files in desc order.\n-checkMultiSTL  --toolnm TOOL-NM-PATH\n     Check if there are more than one shared library statically linked the STL.\n-unusedResources --rTxt R-TXT-FILE-PATH [--ignoreResources IGNORE-RESOURCES-LIST (split by ',')]\n     Find out the unused resources.\n-unusedAssets [--ignoreAssets IGNORE-ASSETS-LIST (split by ',')]\n     Find out the unused assets file.\n-unstrippedSo  --toolnm TOOL-NM-PATH\n     Find out the unstripped shared library file.\n```\n\n由于篇幅影响，此次不再赘述，我们在 [Matrix-APKChecker](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki\u002FMatrix-Android-ApkChecker) 中进行了详细说明。\n\n\n# Support\n\n还有其他问题？\n\n1. 查看[示例](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Ftree\u002Fmaster\u002Fsamples)；\n2. 阅读[源码](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Ftree\u002Fmaster\u002Fmatrix)；\n3. 阅读 [Wiki](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix\u002Fwiki) 或 [FAQ](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Fwiki\u002FMatrix-%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)；\n4. 联系我们。\n\n# 参与贡献\n\n关于 Matrix 分支管理、issue 以及 pr 规范，请阅读 [Matrix Contributing Guide](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Fblob\u002Fmaster\u002FCONTRIBUTING.md)。\n\n[腾讯开源激励计划](https:\u002F\u002Fopensource.tencent.com\u002Fcontribution) 鼓励开发者的参与和贡献，期待你的加入。\n\n# License\n\nMatrix is under the BSD license. See the [LICENSE](https:\u002F\u002Fgithub.com\u002FTencent\u002FMatrix\u002Fblob\u002Fmaster\u002FLICENSE) file for details\n\n# 信息公示\n\n- SDK名称：Matrix\n- 版本号：2.1.0\n- 开发者：深圳市腾讯计算机系统有限公司\n- 主要功能：Matrix是微信研发并日常使用的应用性能监控工具，支持iOS、macOS和Android。Matrix通过接入闪退、卡顿、耗电、内存等方面的监控方案，对性能监控项的异常数据进行采集和分析，输出相应的问题分析、定位与优化建议，从而帮助开发者开发出更高质量的应用。\n- [Matrix SDK使用说明](https:\u002F\u002Fgithub.com\u002FTencent\u002Fmatrix)\n- [Matrix SDK个人信息保护规则](https:\u002F\u002Fsupport.weixin.qq.com\u002Fcgi-bin\u002Fmmsupportacctnodeweb-bin\u002Fpages\u002FyTezupX6yF028Mpf)\n","Matrix 是由微信开发的一款插件式、非侵入的应用性能管理系统，用于监控、定位和分析应用程序的性能问题。其核心功能包括崩溃监测、卡顿检测及内存使用情况跟踪等，通过WCCrashBlockMonitorPlugin、WCMemoryStatPlugin以及WCFPSMonitorPlugin这三个主要插件实现。这些工具能够帮助开发者轻松集成，无需修改现有代码即可获得详细的性能数据报告。适用于iOS、macOS和Android平台上的应用开发项目，特别是在需要高度关注用户体验流畅度与稳定性的场景下非常有用。","2026-06-11 02:58:14","top_language"]