[6.2.0][技术优化] 打开监测开关
This commit is contained in:
@@ -1,39 +1,72 @@
|
||||
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.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() {
|
||||
|
||||
|
||||
private volatile boolean recorded = false;
|
||||
|
||||
private final ThreadLocal<Long> start = new ThreadLocal<>();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onExecutorBefore(@NonNull ThreadConfig.TaskType taskType, @Nullable Object task, @Nullable String desc) {
|
||||
|
||||
if (!recorded && aRouterInit.get()) {
|
||||
IMoGoCpuUsageProvider usage = CallerDevaToolsManager.INSTANCE.usage();
|
||||
if (usage != null) {
|
||||
recorded = true;
|
||||
HandlerCompat.createAsync(Looper.getMainLooper()).post(() -> usage.startMainThreadTime(Debug.threadCpuTimeNanos()));
|
||||
usage.onProcessLaunched(SystemClock.elapsedRealtimeNanos());
|
||||
}
|
||||
}
|
||||
if (recorded) {
|
||||
start.set(Debug.threadCpuTimeNanos());
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecutorStateChanged(@NonNull ThreadPoolExecutor threadPoolExecutor, int core, int max, int active, long completed) {
|
||||
|
||||
}
|
||||
public void onExecutorStateChanged(@NonNull ThreadPoolExecutor threadPoolExecutor, int core, int max, int active, long completed) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user