[6.2.6][技术优化] 将卡顿日志转成在链路日志中存储
This commit is contained in:
@@ -5,11 +5,12 @@ import android.os.SystemClock;
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.mogo.core.lancetx.compiler.lib.generator.Type;
|
||||
import com.mogo.core.lancetx.compiler.lib.hook.IHookInvoker;
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant;
|
||||
import com.mogo.eagle.core.function.api.devatools.block.IMoGoBlockProvider;
|
||||
import com.mogo.eagle.core.function.api.devatools.perf.IMoGoCpuUsageProvider;
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
|
||||
import com.mogo.eagle.core.function.main.ARouterUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.VLogUtils;
|
||||
import com.zhjt.service.chain.ChainLog;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -170,8 +171,8 @@ public class HookInvokerImpl implements IHookInvoker {
|
||||
String s = builder.toString();
|
||||
|
||||
|
||||
VLogUtils.w("HookHandler", "Junk Detected:" + builder, 4096);
|
||||
// linkedLog(type, builder.toString());
|
||||
//VLogUtils.w("HookHandler", "Junk Detected:" + builder, 4096);
|
||||
linkedLog(type, builder.toString());
|
||||
if (flag) {
|
||||
extra.setLength(0);
|
||||
}
|
||||
@@ -248,7 +249,7 @@ public class HookInvokerImpl implements IHookInvoker {
|
||||
}
|
||||
if (holder != null) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("##holder::").append(holder);
|
||||
sb.append("##holder::").append(holder.getName());
|
||||
} else {
|
||||
sb.append("holder::").append(holder);
|
||||
}
|
||||
@@ -287,19 +288,19 @@ public class HookInvokerImpl implements IHookInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
// private void linkedLog(Type type, String msg) {
|
||||
// try {
|
||||
// linkedLogInternal(type,msg);
|
||||
// } catch (Throwable t) {
|
||||
// t.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @ChainLog(
|
||||
// linkChainLog = ChainConstant.CHAIN_TYPE_ANR_LEAK,
|
||||
// linkCode = ChainConstant.CHAIN_SOURCE_HMI,
|
||||
// nodeAliasCode = ChainConstant.CHAIN_CODE_MAIN_BLOCK,
|
||||
// paramIndexes = { 0, 1 }
|
||||
// )
|
||||
// private void linkedLogInternal(Type type, String msg) {}
|
||||
private void linkedLog(Type type, String msg) {
|
||||
try {
|
||||
linkedLogInternal(type,msg);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ChainLog(
|
||||
linkChainLog = ChainConstant.CHAIN_TYPE_ANR_LEAK,
|
||||
linkCode = ChainConstant.CHAIN_SOURCE_HMI,
|
||||
nodeAliasCode = ChainConstant.CHAIN_CODE_MAIN_BLOCK,
|
||||
paramIndexes = { 0, 1 }
|
||||
)
|
||||
private void linkedLogInternal(Type type, String msg) {}
|
||||
}
|
||||
|
||||
@@ -9,40 +9,21 @@ import com.knightboost.lancet.api.annotations.TargetClass
|
||||
import com.knightboost.lancet.api.annotations.TargetMethod
|
||||
import com.knightboost.lancet.api.annotations.Weaver
|
||||
import com.mogo.eagle.core.block.runtime.message.Message
|
||||
import com.mogo.eagle.core.block.runtime.utils.TimeUtils.Companion.now
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@Weaver
|
||||
@Group("main_block_check")
|
||||
class UiPostLancet {
|
||||
|
||||
|
||||
internal data class ActionWrapper(var action: Runnable): Runnable {
|
||||
|
||||
override fun run() {
|
||||
val start = now()
|
||||
try {
|
||||
action.run()
|
||||
} finally {
|
||||
CallerDevaToolsManager.block()?.takeIf {
|
||||
it.hasInit()
|
||||
}?.recorder()?.recycle(Message.acquire(handler = null, action = action, duration = now() - start))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val map by lazy { ConcurrentHashMap<Runnable, ActionWrapper>() }
|
||||
|
||||
@JvmStatic
|
||||
@TargetClass(value = "android.app.Activity", scope = Scope.ALL)
|
||||
@TargetMethod(methodName = "runOnUiThread")
|
||||
@ReplaceInvoke
|
||||
fun runOnUiThreadOfActivity(activity: Activity, action: Runnable) {
|
||||
try {
|
||||
activity.runOnUiThread(ActionWrapper(action).also { map[action] = it })
|
||||
activity.runOnUiThread(action)
|
||||
} finally {
|
||||
CallerDevaToolsManager.block()?.takeIf {
|
||||
it.hasInit()
|
||||
@@ -55,22 +36,8 @@ class UiPostLancet {
|
||||
@TargetMethod(methodName = "post")
|
||||
@ReplaceInvoke
|
||||
fun post(view: View, action: Runnable): Boolean {
|
||||
return try {
|
||||
view.post(ActionWrapper(action).also { map[action] = it })
|
||||
} finally {
|
||||
CallerDevaToolsManager.block()?.takeIf {
|
||||
it.hasInit()
|
||||
}?.recorder()?.insert(Message.acquire(handler = null, action = action, extra = mapOf(view.javaClass.name to "post")))
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@TargetClass(value = "android.view.View", scope = Scope.ALL)
|
||||
@TargetMethod(methodName = "postDelayed")
|
||||
@ReplaceInvoke
|
||||
fun postDelayed(view: View, action: Runnable, delayMillis: Long): Boolean {
|
||||
return try {
|
||||
view.postDelayed(ActionWrapper(action).also { map[action] = it }, delayMillis)
|
||||
view.post(action)
|
||||
} finally {
|
||||
CallerDevaToolsManager.block()?.takeIf {
|
||||
it.hasInit()
|
||||
@@ -78,20 +45,32 @@ class UiPostLancet {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@TargetClass(value = "android.view.View", scope = Scope.ALL)
|
||||
@TargetMethod(methodName = "postDelayed")
|
||||
@ReplaceInvoke
|
||||
fun postDelayed(view: View, action: Runnable, delayMillis: Long): Boolean {
|
||||
return try {
|
||||
view.postDelayed(action, delayMillis)
|
||||
} finally {
|
||||
CallerDevaToolsManager.block()?.takeIf {
|
||||
it.hasInit()
|
||||
}?.recorder()?.insert(Message.acquire(handler = null, action = action, delay = delayMillis, extra = mapOf(view.javaClass.name to "postDelayed")))
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@TargetClass(value = "android.view.View", scope = Scope.ALL)
|
||||
@TargetMethod(methodName = "removeCallbacks")
|
||||
@ReplaceInvoke
|
||||
fun removeCallbacks(view: View, action: Runnable): Boolean {
|
||||
return try {
|
||||
view.removeCallbacks(map.remove(action))
|
||||
view.removeCallbacks(action)
|
||||
} finally {
|
||||
CallerDevaToolsManager.block()?.takeIf {
|
||||
it.hasInit()
|
||||
}?.recorder()?.remove(Message.acquire(handler = null, action = action, extra = mapOf(view.javaClass.name to "removeCallbacks")))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user