Skip to content

Commit

Permalink
Merge pull request #824 from Tencent/feature/dev
Browse files Browse the repository at this point in the history
Matrix 2.1.0 for Android
  • Loading branch information
gryamy authored Mar 21, 2023
2 parents ae45599 + 2e93817 commit 1ef5730
Show file tree
Hide file tree
Showing 197 changed files with 10,948 additions and 2,898 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Matrix-icon](assets/img/readme/header.png)
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/matrix/blob/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/matrix/pulls)
[![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.0.8-red.svg)](https://github.com/Tencent/matrix/wiki)
[![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.1.0-red.svg)](https://github.com/Tencent/matrix/wiki)
[![CircleCI](https://circleci.com/gh/Tencent/matrix.svg?style=shield)](https://app.circleci.com/pipelines/github/Tencent/matrix)

(中文版本请参看[这里](#matrix_cn))
Expand Down Expand Up @@ -215,7 +215,7 @@ At this point, Matrix has been integrated into the app and is beginning to colle

1. Configure `MATRIX_VERSION` in gradle.properties.
``` gradle
MATRIX_VERSION=2.0.8
MATRIX_VERSION=2.1.0
```

2. Add `matrix-gradle-plugin` in your build.gradle:
Expand Down Expand Up @@ -364,11 +364,11 @@ Then other components in Matrix could use Quikcen Backtrace to unwind stacktrace

#### APK Checker Usage

APK Checker can run independently in Jar ([matrix-apk-canary-2.0.8.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.0.8/matrix-apk-canary-2.0.8.jar)) mode, usage:
APK Checker can run independently in Jar ([matrix-apk-canary-2.1.0.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.1.0/matrix-apk-canary-2.1.0.jar)) mode, usage:


```shell
java -jar matrix-apk-canary-2.0.8.jar
java -jar matrix-apk-canary-2.1.0.jar
Usages:
--config CONFIG-FILE-PATH
or
Expand Down Expand Up @@ -427,7 +427,7 @@ Matrix is under the BSD license. See the [LICENSE](https://github.com/Tencent/Ma
# <a name="matrix_cn">Matrix</a>
![Matrix-icon](assets/img/readme/header.png)
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/matrix/blob/master/LICENSE)[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/matrix/pulls) [![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.0.8-red.svg)](https://github.com/Tencent/matrix/wiki)
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/matrix/blob/master/LICENSE)[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/matrix/pulls) [![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.1.0-red.svg)](https://github.com/Tencent/matrix/wiki)
**Matrix** 是一款微信研发并日常使用的应用性能接入框架,支持iOS, macOS和Android。
Matrix 通过接入各种性能监控方案,对性能监控项的异常数据进行采集和分析,输出相应的问题分析、定位与优化建议,从而帮助开发者开发出更高质量的应用。
Expand Down Expand Up @@ -628,7 +628,7 @@ Matrix-android 当前监控范围包括:应用安装包大小,帧率变化

1. 在你项目根目录下的 gradle.properties 中配置要依赖的 Matrix 版本号,如:
``` gradle
MATRIX_VERSION=2.0.8
MATRIX_VERSION=2.1.0
```

2. 在你项目根目录下的 build.gradle 文件添加 Matrix 依赖,如:
Expand Down Expand Up @@ -774,10 +774,10 @@ WeChatBacktrace.instance().configure(getApplicationContext()).commit();
#### APK Checker
APK Check 以独立的 jar 包提供 ([matrix-apk-canary-2.0.8.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.0.8/matrix-apk-canary-2.0.8.jar)),你可以运行:
APK Check 以独立的 jar 包提供 ([matrix-apk-canary-2.1.0.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.1.0/matrix-apk-canary-2.1.0.jar)),你可以运行:
```cmd
java -jar matrix-apk-canary-2.0.8.jar
java -jar matrix-apk-canary-2.1.0.jar
```
查看 Usages 来使用它。
Expand Down
2 changes: 1 addition & 1 deletion matrix/matrix-android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
# org.gradle.parallel=true
#Tue Jun 20 10:24:33 CST 2017

VERSION_NAME_PREFIX=2.0.8
VERSION_NAME_PREFIX=2.1.0
VERSION_NAME_SUFFIX=
## two options: Internal (for wechat), External (for public repo)
PUBLISH_CHANNEL=Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@
#include <dlfcn.h>
#include <set>
#include "EnhanceDlsym.h"
#include "../../../../../matrix-jectl/src/main/cpp/jectl/JeLog.h"

#define TAG "Matrix.EnhanceDl"

#include <android/log.h>

#define LOGD(TAG, FMT, args...) //__android_log_print(ANDROID_LOG_DEBUG, TAG, FMT, ##args)
#define LOGI(TAG, FMT, args...) //__android_log_print(ANDROID_LOG_INFO, TAG, FMT, ##args)
#define LOGE(TAG, FMT, args...) //__android_log_print(ANDROID_LOG_ERROR, TAG, FMT, ##args)

namespace enhance {

static std::set<DlInfo *> m_opened_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
package com.tencent.matrix.lifecycle.supervisor;

// Declare any non-default types here with import statements
import com.tencent.matrix.util.MemInfo;

interface ISubordinateProxy {
void dispatchState(in String scene, in String stateName, in boolean state);
void dispatchKill(in String scene, in String targetProcess, in int targetPid);
void dispatchDeath(in String scene, in String targetProcess, in int targetPid, in boolean isLruKill);

int getPss();
MemInfo getMemInfo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// MemInfo.aidl
package com.tencent.matrix.util;

// Declare any non-default types here with import statements

parcelable MemInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.tencent.matrix.lifecycle

import android.app.Application
import com.tencent.matrix.lifecycle.owners.*
import com.tencent.matrix.lifecycle.supervisor.*
import com.tencent.matrix.util.MatrixLog
import com.tencent.matrix.util.MatrixUtil

// @formatter:off
object MatrixLifecycleLogger {

private var application: Application? = null
private val TAG by lazy { "Matrix.lifecycle.Logger_${String.format("%-10.10s", suffix())}" }

private fun suffix(): String {
return if (MatrixUtil.isInMainProcess(application!!)) {
"Main"
} else {
val split = MatrixUtil.getProcessName(application!!).split(":").toTypedArray()
if (split.size > 1) {
split[1].takeLast(10)
} else {
"unknown"
}
}
}

fun init(app: Application, enable: Boolean) {
application = app
if (!enable) {
MatrixLog.i(TAG, "logger disabled")
return
}

ProcessUIResumedStateOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_UI_RESUMED")
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_UI_PAUSED")
})

ProcessUIStartedStateOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_UI_STARTED scene: ${ProcessUILifecycleOwner.recentScene}")
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_UI_STOPPED scene: ${ProcessUILifecycleOwner.recentScene}")
})

ProcessExplicitBackgroundOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_ENTER_EXPLICIT_BACKGROUND")
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_EXIT_EXPLICIT_BACKGROUND")
})

ProcessStagedBackgroundOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_ENTER_STAGED_BACKGROUND")
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_EXIT_STAGED_BACKGROUND")
})

ProcessDeepBackgroundOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_ENTER_DEEP_BACKGROUND")
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_EXIT_DEEP_BACKGROUND")
})

AppUIForegroundOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ON_APP_UI_ENTER_FOREGROUND scene: ${ProcessSupervisor.getRecentScene()}")
override fun off() = MatrixLog.i(TAG, "ON_APP_UI_EXIT_FOREGROUND scene: ${ProcessSupervisor.getRecentScene()}")
})

AppExplicitBackgroundOwner.observeForever(object : ISerialObserver {
override fun off() = MatrixLog.i(TAG, "ON_APP_EXIT_EXPLICIT_BACKGROUND")
override fun on() = MatrixLog.i(TAG, "ON_APP_ENTER_EXPLICIT_BACKGROUND")
})

AppStagedBackgroundOwner.observeForever(object : ISerialObserver {
override fun off() = MatrixLog.i(TAG, "ON_APP_EXIT_STAGED_BACKGROUND")
override fun on() = MatrixLog.i(TAG, "ON_APP_ENTER_STAGED_BACKGROUND")
})

AppDeepBackgroundOwner.observeForever(object : ISerialObserver {
override fun off() = MatrixLog.i(TAG, "ON_APP_EXIT_DEEP_BACKGROUND")
override fun on() = MatrixLog.i(TAG, "ON_APP_ENTER_DEEP_BACKGROUND")
})

ProcessSupervisor.addDyingListener { scene, processName, pid ->
MatrixLog.i(TAG, "Dying Listener: process $pid-$processName is dying on scene $scene")
false // NOT rescue
}

ProcessSupervisor.addDeathListener { scene, processName, pid, isLruKill ->
MatrixLog.i(
TAG,
"Death Listener: process $pid-$processName died on scene $scene, is LRU Kill? $isLruKill"
)
}

ForegroundServiceLifecycleOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "ForegroundServiceLifecycleOwner: ON")
override fun off() = MatrixLog.i(TAG, "ForegroundServiceLifecycleOwner: OFF")
})

OverlayWindowLifecycleOwner.observeForever(object : ISerialObserver {
override fun on() = MatrixLog.i(TAG, "OverlayWindowLifecycleOwner: ON, hasOverlay = ${OverlayWindowLifecycleOwner.hasOverlayWindow()}, hasVisible = ${OverlayWindowLifecycleOwner.hasVisibleWindow()}")
override fun off() = MatrixLog.i(TAG, "OverlayWindowLifecycleOwner: OFF, hasOverlay = ${OverlayWindowLifecycleOwner.hasOverlayWindow()}, hasVisible = ${OverlayWindowLifecycleOwner.hasVisibleWindow()}")
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ data class MatrixLifecycleConfig(
*/
val enableOverlayWindowMonitor: Boolean = false,

val lifecycleThreadConfig: LifecycleThreadConfig = LifecycleThreadConfig()
val lifecycleThreadConfig: LifecycleThreadConfig = LifecycleThreadConfig(),

val enableLifecycleLogger: Boolean = false
)

/**
Expand Down Expand Up @@ -61,6 +63,7 @@ class MatrixLifecycleOwnerInitializer {
ProcessUILifecycleOwner.init(app)
ForegroundServiceLifecycleOwner.init(app, config.enableFgServiceMonitor)
OverlayWindowLifecycleOwner.init(config.enableOverlayWindowMonitor)
MatrixLifecycleLogger.init(app, config.enableLifecycleLogger)
}

@SuppressLint("PrivateApi", "DiscouragedPrivateApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.util.concurrent.*
private const val TAG = "Matrix.Lifecycle.Thread"

data class LifecycleThreadConfig(
val externalExecutor: Executor? = null,
val maxPoolSize: Int = 5,
val keepAliveSeconds: Long = 30L,
val onHeavyTaskDetected: (task: String, cost: Long) -> Unit = { task, cost ->
Expand Down Expand Up @@ -45,6 +46,11 @@ internal object MatrixLifecycleThread {
}

val executor by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {

if (config.externalExecutor != null) {
return@lazy config.externalExecutor!!
}

val idleSynchronousQueue = IdleSynchronousQueue()

object : ThreadPoolExecutor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Handler
import android.os.Message
import android.os.Process
import android.util.ArrayMap
import com.tencent.matrix.lifecycle.MatrixLifecycleThread
import com.tencent.matrix.lifecycle.StatefulOwner
import com.tencent.matrix.util.MatrixLog
import com.tencent.matrix.util.safeApply
Expand All @@ -19,8 +20,6 @@ import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.lang.reflect.Proxy

private const val SDK_GUARD = 32

/**
* Created by Yves on 2021/11/30
*/
Expand Down Expand Up @@ -49,10 +48,6 @@ object ForegroundServiceLifecycleOwner : StatefulOwner() {
MatrixLog.i(TAG, "disabled")
return
}
if (Build.VERSION.SDK_INT > SDK_GUARD) { // for safety
MatrixLog.e(TAG, "NOT support for api-level ${Build.VERSION.SDK_INT} yet!!!")
return
}
inject()
}

Expand Down Expand Up @@ -127,8 +122,10 @@ object ForegroundServiceLifecycleOwner : StatefulOwner() {
}
STOP_SERVICE -> {
ActivityThreadmH?.post {
safeApply(TAG) {
hasForegroundService()
MatrixLifecycleThread.handler.post {
safeApply(TAG) {
hasForegroundService()
}
}
}
}
Expand Down Expand Up @@ -159,15 +156,17 @@ object ForegroundServiceLifecycleOwner : StatefulOwner() {
}

private fun checkIfAlreadyForegrounded(componentName: ComponentName) {
safeApply(TAG) {
activityManager?.getRunningServices(Int.MAX_VALUE)?.filter {
it.pid == Process.myPid()
&& it.uid == Process.myUid()
&& it.service == componentName
&& it.foreground
}?.forEach {
MatrixLog.i(TAG, "service turned fg when create: ${it.service}")
fgServiceHandler?.onStartForeground(it.service)
MatrixLifecycleThread.handler.post {
safeApply(TAG) {
activityManager?.getRunningServices(Int.MAX_VALUE)?.filter {
it.pid == Process.myPid()
&& it.uid == Process.myUid()
&& it.service == componentName
&& it.foreground
}?.forEach {
MatrixLog.i(TAG, "service turned fg when create: ${it.service}")
fgServiceHandler?.onStartForeground(it.service)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import android.view.WindowManager
import com.tencent.matrix.lifecycle.StatefulOwner
import com.tencent.matrix.util.*

private const val SDK_GUARD = 32

/**
* Created by Yves on 2021/12/30
*/
Expand Down Expand Up @@ -39,10 +37,6 @@ object OverlayWindowLifecycleOwner : StatefulOwner() {
MatrixLog.i(TAG, "disabled")
return
}
if (Build.VERSION.SDK_INT > SDK_GUARD) { // for safety
MatrixLog.e(TAG, "NOT support for api-level ${Build.VERSION.SDK_INT} yet!!!")
return
}
inject()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object ProcessExplicitBackgroundOwner : StatefulOwner(), IBackgroundStatefulOwne
override fun action(): Boolean {
val uiForeground by lazy { ProcessUIStartedStateOwner.active() }
val fgService by lazy { ForegroundServiceLifecycleOwner.hasForegroundService() }
val visibleWindow by lazy { OverlayWindowLifecycleOwner.hasVisibleWindow() }
val visibleWindow by lazy { OverlayWindowLifecycleOwner.hasOverlayWindow() }

if (uiForeground) {
MatrixLog.i(TAG, "turn OFF for UI foreground")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ internal object ProcessSubordinate {
}
}

fun getPss(): Int {
return 0
fun getMemInfo(): Array<MemInfo> {
val memInfoList = ArrayList<MemInfo>()
subordinateProxies.forEachSafe {
it.value.memInfo?.let { m->
memInfoList.add(m)
}
}
return memInfoList.toTypedArray()
}
}

Expand Down Expand Up @@ -243,9 +249,10 @@ internal object ProcessSubordinate {
}
}

override fun getPss(): Int {
TODO("Not yet implemented")
}
override fun getMemInfo(): MemInfo = safeLet(
TAG,
defVal = MemInfo(amsPssInfo = PssInfo(), debugPssInfo = PssInfo())
) { MemInfo.getCurrentProcessFullMemInfo() }

}

Expand Down
Loading

0 comments on commit 1ef5730

Please sign in to comment.