[6.2.0][技术优化] 打开监测开关
This commit is contained in:
@@ -23,6 +23,7 @@ import com.mogo.eagle.core.function.api.devatools.strict.*
|
||||
import com.mogo.eagle.core.function.api.devatools.download.*
|
||||
import com.mogo.eagle.core.function.api.devatools.logcat.*
|
||||
import com.mogo.eagle.core.function.api.devatools.mofang.*
|
||||
import com.mogo.eagle.core.function.api.devatools.perf.IMoGoCpuUsageProvider
|
||||
import com.mogo.eagle.core.function.api.lookaround.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.w
|
||||
@@ -53,6 +54,7 @@ import com.zhjt.mogo_core_function_devatools.mofang.*
|
||||
import com.zhjt.mogo_core_function_devatools.monitor.MonitorManager
|
||||
import com.zhjt.mogo_core_function_devatools.monitor.db.MonitorDb
|
||||
import com.zhjt.mogo_core_function_devatools.monitor.db.MonitorDb.Companion.getDb
|
||||
import com.zhjt.mogo_core_function_devatools.perf.MoGoCpuUsageProviderImpl
|
||||
import com.zhjt.mogo_core_function_devatools.report.IPCReportManager.Companion.iPCReportManager
|
||||
import com.zhjt.mogo_core_function_devatools.scene.SceneManager.Companion.sceneManager
|
||||
import com.zhjt.mogo_core_function_devatools.status.StatusManager
|
||||
@@ -86,6 +88,8 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
|
||||
private val block by lazy { MoGoBlockProviderImpl() }
|
||||
|
||||
private val usage by lazy { MoGoCpuUsageProviderImpl() }
|
||||
|
||||
@Volatile
|
||||
private var mDockerVersion: String? = null
|
||||
|
||||
@@ -394,4 +398,6 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
override fun logRecord(): IMoGoLogRecordProvider = logRecordProvider
|
||||
|
||||
override fun block(): IMoGoBlockProvider? = block
|
||||
|
||||
override fun usage(): IMoGoCpuUsageProvider? = usage
|
||||
}
|
||||
@@ -13,6 +13,10 @@ internal class MainBlockLinkedLog {
|
||||
}
|
||||
}
|
||||
|
||||
fun recordCpuUsage(extra: Map<String, String>) {
|
||||
recordCpuInternal(extra)
|
||||
}
|
||||
|
||||
@ChainLog(
|
||||
linkChainLog = ChainConstant.CHAIN_TYPE_ANR_LEAK,
|
||||
linkCode = ChainConstant.CHAIN_SOURCE_HMI,
|
||||
@@ -20,4 +24,13 @@ internal class MainBlockLinkedLog {
|
||||
paramIndexes = [0]
|
||||
)
|
||||
private fun recordInternal(extra: Map<String, List<String>>) {}
|
||||
|
||||
|
||||
@ChainLog(
|
||||
linkChainLog = ChainConstant.CHAIN_TYPE_ANR_LEAK,
|
||||
linkCode = ChainConstant.CHAIN_SOURCE_HMI,
|
||||
nodeAliasCode = ChainConstant.CHAIN_CODE_MAIN_BLOCK,
|
||||
paramIndexes = [0]
|
||||
)
|
||||
private fun recordCpuInternal(extra: Map<String, String>) {}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.mogo.eagle.core.block.runtime.config.recorder.IMessageRecorder.OnDump
|
||||
import com.mogo.eagle.core.block.runtime.listener.*
|
||||
import com.mogo.eagle.core.block.runtime.report.*
|
||||
import com.mogo.eagle.core.function.api.devatools.block.*
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
|
||||
import java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
internal class MoGoBlockProviderImpl: IMoGoBlockProvider, IBlockListener {
|
||||
@@ -26,7 +27,7 @@ internal class MoGoBlockProviderImpl: IMoGoBlockProvider, IBlockListener {
|
||||
.multiplier(2.0f)
|
||||
.isDebug(false)
|
||||
.period(5, SECONDS)
|
||||
.junkRateThreshold(0.8f)
|
||||
.junkRateThreshold(0.6f)
|
||||
.recorder(null, 500, 500)
|
||||
.build())
|
||||
hasInit = true
|
||||
@@ -49,6 +50,19 @@ internal class MoGoBlockProviderImpl: IMoGoBlockProvider, IBlockListener {
|
||||
override fun OnDumped(data: Map<Int, List<String>>) {
|
||||
map["history"] = data[0] ?: emptyList()
|
||||
map["pending"] = data[1] ?: emptyList()
|
||||
val cpu = CallerDevaToolsManager.usage()?.dump()
|
||||
if (!cpu.isNullOrEmpty()) {
|
||||
val mainThreadCpuUsage = cpu.remove("MainThreadCpuUsage")
|
||||
val processLaunchedTime = cpu.remove("ProcessLaunchedTime")
|
||||
if (mainThreadCpuUsage != null && processLaunchedTime != null) {
|
||||
linkedLog.recordCpuUsage(LinkedHashMap<String, String>().also {
|
||||
it["MainThread"] = "${ mainThreadCpuUsage * 1.0f * 100 / processLaunchedTime }%"
|
||||
cpu.entries.sortedByDescending { it.value }.forEach { sorted ->
|
||||
it[sorted.key] = "${ sorted.value * 1.0f * 100 / processLaunchedTime }%"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
linkedLog.record(map)
|
||||
}
|
||||
})
|
||||
@@ -81,7 +95,6 @@ internal class MoGoBlockProviderImpl: IMoGoBlockProvider, IBlockListener {
|
||||
}
|
||||
|
||||
override fun recorder(): IMessageRecorder {
|
||||
|
||||
return BlockDetector.recorder()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.zhjt.mogo_core_function_devatools.perf
|
||||
|
||||
import android.os.SystemClock
|
||||
import com.mogo.eagle.core.function.api.devatools.perf.IMoGoCpuUsageProvider
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
internal class MoGoCpuUsageProviderImpl: IMoGoCpuUsageProvider {
|
||||
|
||||
private var processLaunchTime: Long = 0L
|
||||
|
||||
private var mainThreadStartTime : Long = 0L
|
||||
|
||||
private var mainThreadLastTime: Long = 0L
|
||||
|
||||
private var mainThreadCpuUsage: Long = 0L
|
||||
|
||||
private val maxSize = 500
|
||||
|
||||
private val map by lazy { LinkedHashMap<String, Long>(0, 0.75f, true) }
|
||||
|
||||
private val lock by lazy { ReentrantLock() }
|
||||
|
||||
private val builder by lazy { ThreadLocal<StringBuilder>() }
|
||||
|
||||
override fun onProcessLaunched(time: Long) {
|
||||
processLaunchTime = time
|
||||
}
|
||||
|
||||
override fun startMainThreadTime(time: Long) {
|
||||
mainThreadStartTime = time
|
||||
}
|
||||
|
||||
override fun updateMainThreadTime(time: Long) {
|
||||
if (mainThreadLastTime == 0L) {
|
||||
mainThreadLastTime = mainThreadStartTime
|
||||
}
|
||||
val delta = time - mainThreadLastTime
|
||||
if (delta > 0) {
|
||||
mainThreadCpuUsage += delta
|
||||
}
|
||||
mainThreadLastTime = time
|
||||
}
|
||||
|
||||
override fun incrementOtherThreadUsage(group: String, t: Thread, usage: Long) {
|
||||
var builder = builder.get()
|
||||
if (builder == null) {
|
||||
builder = StringBuilder(128)
|
||||
this.builder.set(builder)
|
||||
}
|
||||
if (builder.isNotEmpty()) {
|
||||
builder.setLength(0)
|
||||
}
|
||||
builder.append(group).append("@@").append(t.name)
|
||||
lock.withLock {
|
||||
while (map.size > maxSize) {
|
||||
val toEvict = map.entries.iterator().next()
|
||||
map.remove(toEvict.key)
|
||||
}
|
||||
map[builder.toString()] = map.getOrPut(builder.toString()) { 0 } + usage
|
||||
}
|
||||
}
|
||||
|
||||
override fun dump(): LinkedHashMap<String, Long> {
|
||||
return lock.withLock {
|
||||
if (map.isNotEmpty()) {
|
||||
val iterator = map.entries.iterator()
|
||||
val rst = LinkedHashMap<String, Long>()
|
||||
rst["MainThreadCpuUsage"] = mainThreadCpuUsage
|
||||
rst["ProcessLaunchedTime"] = SystemClock.elapsedRealtimeNanos() - processLaunchTime
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
rst[next.key] = next.value
|
||||
}
|
||||
rst
|
||||
} else {
|
||||
LinkedHashMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user