feat:add global anchor hook to monitor all performance hook
This commit is contained in:
@@ -108,6 +108,10 @@ public class DoricContext {
|
||||
this.source = source;
|
||||
this.extra = extra;
|
||||
this.performanceProfile = new DoricPerformanceProfile(contextId);
|
||||
DoricPerformanceProfile.AnchorHook anchorHook = getDriver().getRegistry().getGlobalPerformanceAnchorHook();
|
||||
if (anchorHook != null) {
|
||||
this.performanceProfile.addAnchorHook(anchorHook);
|
||||
}
|
||||
}
|
||||
|
||||
public DoricPerformanceProfile getPerformanceProfile() {
|
||||
|
@@ -28,6 +28,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import pub.doric.engine.DoricJSEngine;
|
||||
import pub.doric.performance.DoricPerformanceProfile;
|
||||
import pub.doric.plugin.AnimatePlugin;
|
||||
import pub.doric.plugin.CoordinatorPlugin;
|
||||
import pub.doric.plugin.DoricJavaPlugin;
|
||||
@@ -246,4 +247,16 @@ public class DoricRegistry {
|
||||
public void setDefaultErrorDrawable(Drawable defaultErrorDrawable) {
|
||||
this.defaultErrorDrawable = defaultErrorDrawable;
|
||||
}
|
||||
|
||||
|
||||
private DoricPerformanceProfile.GlobalAnchorHook globalPerformanceAnchorHook;
|
||||
|
||||
public void setGlobalPerformanceAnchorHook(DoricPerformanceProfile.GlobalAnchorHook anchorHook) {
|
||||
globalPerformanceAnchorHook = anchorHook;
|
||||
}
|
||||
|
||||
public DoricPerformanceProfile.GlobalAnchorHook getGlobalPerformanceAnchorHook() {
|
||||
return globalPerformanceAnchorHook;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -67,6 +67,10 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
|
||||
public DoricJSEngine() {
|
||||
mDoricRegistry = new DoricRegistry(this);
|
||||
DoricPerformanceProfile.AnchorHook anchorHook = mDoricRegistry.getGlobalPerformanceAnchorHook();
|
||||
if (anchorHook != null) {
|
||||
globalProfile.addAnchorHook(anchorHook);
|
||||
}
|
||||
globalProfile.prepare(DoricPerformanceProfile.PART_INIT);
|
||||
handlerThread = new HandlerThread(this.getClass().getSimpleName());
|
||||
handlerThread.start();
|
||||
|
@@ -57,6 +57,10 @@ public class DoricPerformanceProfile {
|
||||
void onAnchor(String name, long prepare, long start, long end);
|
||||
}
|
||||
|
||||
public interface GlobalAnchorHook extends AnchorHook {
|
||||
void onAnchor(DoricPerformanceProfile profile, String name, long prepare, long start, long end);
|
||||
}
|
||||
|
||||
public DoricPerformanceProfile(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -113,10 +117,6 @@ public class DoricPerformanceProfile {
|
||||
print(anchorName);
|
||||
}
|
||||
|
||||
public Map<String, Long> getAnchorMap() {
|
||||
return this.anchorMap;
|
||||
}
|
||||
|
||||
private void print(final String anchorName) {
|
||||
if (!enable) {
|
||||
return;
|
||||
@@ -139,7 +139,11 @@ public class DoricPerformanceProfile {
|
||||
Log.d(TAG, String.format("%s: %s prepared %dms, cost %dms.",
|
||||
name, anchorName, start - prepare, end - start));
|
||||
for (AnchorHook hook : hooks) {
|
||||
hook.onAnchor(anchorName, prepare, start, end);
|
||||
if (hook instanceof GlobalAnchorHook) {
|
||||
((GlobalAnchorHook) hook).onAnchor(DoricPerformanceProfile.this, anchorName, prepare, start, end);
|
||||
} else {
|
||||
hook.onAnchor(anchorName, prepare, start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user