[6.2.0][技术优化] 更改Handler消息记录方式,对编译生成的类方法集合进行过滤

This commit is contained in:
renwj
2023-11-20 15:35:36 +08:00
parent c8efde952b
commit 59ac4d030b
20 changed files with 824 additions and 1067 deletions

View File

@@ -0,0 +1,12 @@
package com.mogo.eagle.core.function.main
import java.util.concurrent.atomic.AtomicBoolean
class ARouterUtils {
companion object {
@JvmField
var isInit = AtomicBoolean(false)
}
}

View File

@@ -1,26 +1,23 @@
package com.mogo.eagle.core.function.main.threadopt;
import android.os.Debug;
import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.os.HandlerCompat;
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.thread.opt.core.ThreadManager;
import com.mogo.thread.opt.core.annotation.Keep;
import com.mogo.thread.opt.core.config.ThreadConfig;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@Keep
public class ThreadOptInitializer {
public static final AtomicBoolean aRouterInit = new AtomicBoolean(false);
private static final ThreadConfig.TaskExecuteListener listener = new ThreadConfig.TaskExecuteListener() {
@@ -38,29 +35,29 @@ public class ThreadOptInitializer {
@Override
public void onExecutorBefore(@NonNull ThreadConfig.TaskType taskType, @Nullable Object task, @Nullable String desc) {
if (!recorded && aRouterInit.get()) {
if (!recorded && ARouterUtils.isInit.get()) {
IMoGoCpuUsageProvider usage = CallerDevaToolsManager.INSTANCE.usage();
if (usage != null) {
recorded = true;
HandlerCompat.createAsync(Looper.getMainLooper()).post(() -> usage.startMainThreadTime(Debug.threadCpuTimeNanos()));
usage.onProcessLaunched(SystemClock.elapsedRealtimeNanos());
HandlerCompat.createAsync(Looper.getMainLooper()).post(usage::onMainThreadLaunched);
usage.onProcessLaunched();
}
}
if (recorded) {
start.set(Debug.threadCpuTimeNanos());
IMoGoCpuUsageProvider usage = CallerDevaToolsManager.INSTANCE.usage();
if (usage != null) {
usage.updateOtherThreadTime();
}
}
}
@Override
public void onExecutorAfter(@NonNull ThreadConfig.TaskType taskType, @Nullable Object task, @Nullable String desc) {
if (recorded) {
Long start = this.start.get();
if (start != null && start > 0) {
long delta = Debug.threadCpuTimeNanos() - start;
IMoGoCpuUsageProvider usage = CallerDevaToolsManager.INSTANCE.usage();
if (usage != null && desc != null) {
usage.incrementOtherThreadUsage(desc, Thread.currentThread(), delta);
}
IMoGoCpuUsageProvider usage = CallerDevaToolsManager.INSTANCE.usage();
if (usage != null) {
usage.updateOtherThreadTime();
}
}
}