Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] add jsthread watch log && more log (#2722)
Browse files Browse the repository at this point in the history
[Android] fix cycle init

[Android] record reInitCount when ws && instance data
  • Loading branch information
lucky-chen authored and Darin726 committed Jul 18, 2019
1 parent 1245432 commit 1ee8c74
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
2 changes: 2 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.taobao.weex.common.WXInstanceWrap;
import com.taobao.weex.common.WXModule;
import com.taobao.weex.http.WXStreamModule;
import com.taobao.weex.performance.WXStateRecord;
import com.taobao.weex.ui.ExternalLoaderComponentHolder;
import com.taobao.weex.ui.IExternalComponentGetter;
import com.taobao.weex.ui.IExternalModuleGetter;
Expand Down Expand Up @@ -243,6 +244,7 @@ public void run() {
WXLogUtils.renderPerformanceLog("SDKInitExecuteTime", WXEnvironment.sSDKInitExecuteTime);
}
});
WXStateRecord.getInstance().startJSThreadWatchDog();
register();
}

Expand Down
2 changes: 2 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ public void onChangeElement(WXComponent component, boolean isOutOfScreen) {
}

public void onRenderError(final String errCode, final String msg) {
WXStateRecord.getInstance().recordException(getInstanceId(),"onRenderError,"+errCode+","+msg);
if (mRenderListener != null && mContext != null) {
WXLogUtils.e("onRenderError "+errCode +","+msg);
runOnUiThread(new Runnable() {
Expand All @@ -1673,6 +1674,7 @@ public void run() {
}

public void onJSException(final String errCode, final String function, final String exception) {
WXStateRecord.getInstance().recordException(getInstanceId(),"onJSException,"+errCode+","+function+"|"+exception);
hasException = true;
if (mRenderListener != null && mContext != null) {
WXLogUtils.e("onJSException "+errCode +","+exception);
Expand Down
13 changes: 13 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public class WXBridge implements IWXBridge {

@Override
public void updateInitFrameworkParams(String key, String value, String desc){
WXStateRecord.getInstance().recordAction("","updateInitFrameworkParams:");
nativeUpdateInitFrameworkParams(key, value, desc);
}

Expand All @@ -150,24 +151,29 @@ public int initFramework(String framework, WXParams params) {
@Override
public int initFrameworkEnv(String framework, WXParams params, String cacheDir, boolean pieSupport) {
if (MULTIPROCESS) {
WXStateRecord.getInstance().recordAction("","nativeInitFrameworkEnv:");
return nativeInitFrameworkEnv(framework, params, cacheDir, pieSupport);
} else {
WXStateRecord.getInstance().recordAction("","nativeInitFramework:");
return nativeInitFramework(framework, params);
}
}

@Override
public void refreshInstance(String instanceId, String namespace, String function, WXJSObject[] args) {
WXStateRecord.getInstance().recordAction(instanceId,"refreshInstance:"+namespace+","+function);
nativeRefreshInstance(instanceId, namespace, function, args);
}

@Override
public int execJS(String instanceId, String namespace, String function, WXJSObject[] args) {
WXStateRecord.getInstance().recordAction(instanceId,"execJS:"+namespace+","+function);
return nativeExecJS(instanceId, namespace, function, args);
}

@Override
public void execJSWithCallback(String instanceId, String namespace, String function, WXJSObject[] args, ResultCallback callback) {
WXStateRecord.getInstance().recordAction(instanceId,"execJSWithCallback:"+namespace+","+function);
if (callback == null) {
execJS(instanceId, namespace, function, args);
}
Expand All @@ -178,6 +184,7 @@ public void execJSWithCallback(String instanceId, String namespace, String funct
// Result from js engine
@CalledByNative
public void onReceivedResult(long callbackId, byte[] result) {
WXStateRecord.getInstance().recordAction("onReceivedResult","callbackId"+callbackId);
ResultCallback callback = ResultCallbackManager.removeCallbackById(callbackId);
if (callback != null) {
callback.onReceiveResult(result);
Expand All @@ -186,6 +193,7 @@ public void onReceivedResult(long callbackId, byte[] result) {

@Override
public int execJSService(String javascript) {
WXStateRecord.getInstance().recordAction("execJSService","execJSService:");
return nativeExecJSService(javascript);
}

Expand All @@ -197,16 +205,19 @@ public void takeHeapSnapshot(String filename) {

@Override
public int createInstanceContext(String instanceId, String name, String function, WXJSObject[] args) {
WXStateRecord.getInstance().recordAction(instanceId,"createInstanceContext:");
return nativeCreateInstanceContext(instanceId, name, function, args);
}

@Override
public int destoryInstance(String instanceId, String name, String function, WXJSObject[] args) {
WXStateRecord.getInstance().recordAction(instanceId,"destoryInstance:");
return nativeDestoryInstance(instanceId, name, function, args);
}

@Override
public String execJSOnInstance(String instanceId, String script, int type) {
WXStateRecord.getInstance().recordAction(instanceId,"execJSOnInstance:"+type);
return nativeExecJSOnInstance(instanceId, script, type);
}

Expand Down Expand Up @@ -285,6 +296,7 @@ public void reportJSException(String instanceId, String func, String exception)
@CalledByNative
public Object callNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options) {
try {
WXStateRecord.getInstance().recordAction(instanceId,"callNativeModule:"+module+"."+method);
long start = WXUtils.getFixUnixTime();
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
JSONArray argArray = null;
Expand Down Expand Up @@ -367,6 +379,7 @@ public Object callNativeModule(String instanceId, String module, String method,
@Override
@CalledByNative
public void callNativeComponent(String instanceId, String ref, String method, byte[] arguments, byte[] optionsData) {
WXStateRecord.getInstance().recordAction(instanceId,"callNativeComponent:"+method);
try{
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
JSONArray argArray = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public class WXBridgeManager implements Callback, BactchExecutor {
private static final int CRASHREINIT = 50;
static volatile WXBridgeManager mBridgeManager;
private static long LOW_MEM_VALUE = 120;
private volatile static int reInitCount = 1;
public volatile static int reInitCount = 1;
private static String crashUrl = null;
private static long lastCrashTime = 0;

Expand Down Expand Up @@ -357,6 +357,7 @@ private boolean isJSFrameworkInit() {

private void setJSFrameworkInit(boolean init) {
mInit = init;
WXStateRecord.getInstance().recoreJsfmInitHistory("setJsfmInitFlag:"+init);
if (init == true) {
onJsFrameWorkInitSuccees();
}
Expand Down Expand Up @@ -615,8 +616,6 @@ public Object callNativeModule(String instanceId, String module, String method,
return IWXBridge.INSTANCE_RENDERING_ERROR;
}

WXStateRecord.getInstance().recordAction(instanceId,"callNativeModule:"+module+"."+method);

if (WXEnvironment.isApkDebugable() && BRIDGE_LOG_SWITCH) {
mLodBuilder.append("[WXBridgeManager] callNativeModule >>>> instanceId:").append(instanceId)
.append(", module:").append(module).append(", method:").append(method).append(", arguments:").append(arguments);
Expand Down Expand Up @@ -728,11 +727,13 @@ public int callNative(String instanceId, JSONArray tasks, String callback) {
dom.callDomMethod(task, parseNanos);
} else {
JSONObject optionObj = task.getJSONObject(OPTIONS);
WXStateRecord.getInstance().recordAction(instanceId,"callModuleMethod:"+instanceId+","+module+","+task.get(METHOD));
callModuleMethod(instanceId, (String) module,
(String) task.get(METHOD), (JSONArray) task.get(ARGS), optionObj);
}
} else if (task.get(COMPONENT) != null) {
WXDomModule dom = WXModuleManager.getDomModule(instanceId);
WXStateRecord.getInstance().recordAction(instanceId,"callDomMethod:"+instanceId+","+task.get(METHOD));
dom.invokeMethod((String) task.get(REF), (String) task.get(METHOD), (JSONArray) task.get(ARGS));
} else {
throw new IllegalArgumentException("unknown callNative");
Expand Down Expand Up @@ -1477,6 +1478,8 @@ public void createInstance(final String instanceId, final Script template,
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorMsg() +
" instanceId==" + instanceId + " template ==" + template + " mJSHandler== " + mJSHandler.toString()
);

instance.getApmForInstance().onStage("createInstance failed return; "+TextUtils.isEmpty(instanceId)+ ","+template.isEmpty()+","+(mJSHandler ==null));
return;
}

Expand All @@ -1485,6 +1488,7 @@ public void createInstance(final String instanceId, final Script template,
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorCode(),
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorMsg() +
" isJSFrameworkInit==" + isJSFrameworkInit() + " reInitCount == 1" );
instance.getApmForInstance().onStage("createInstance failed jsfm isn't init return;");
post(new Runnable() {
@Override
public void run() {
Expand All @@ -1499,6 +1503,7 @@ public void run() {
post(new Runnable() {
@Override
public void run() {
instance.getApmForInstance().onStage("wxLoadBundleStartOnJsThread");
long start = System.currentTimeMillis();
mWXBridge.setPageArgument(instanceId, "renderTimeOrigin", String.valueOf(instance.getWXPerformance().renderTimeOrigin));
mWXBridge.setInstanceRenderType(instance.getInstanceId(), instance.getRenderType());
Expand Down Expand Up @@ -1527,6 +1532,7 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorMsg()
);
WXLogUtils.e(err);
instance.getApmForInstance().onStage("framework.js uninitialized and return");
return;
}

Expand Down Expand Up @@ -1646,13 +1652,15 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
// if { "framework": "Vue" } or { "framework": "Rax" } will use invokeCreateInstanceContext
// others will use invokeExecJS
if (!isSandBoxContext) {
instance.getApmForInstance().onStage("!isSandBoxContext,and excute");
invokeExecJS(instance.getInstanceId(), null, METHOD_CREATE_INSTANCE, args, false);
return;
}
if (type == BundType.Vue || type == BundType.Rax
|| instance.getRenderStrategy() == WXRenderStrategy.DATA_RENDER
|| instance.getRenderStrategy() == WXRenderStrategy.DATA_RENDER_BINARY
|| instance.getRenderStrategy() == WXRenderStrategy.JSON_RENDER) {
instance.getApmForInstance().onStage("wxBeforeInvokeCreateInstanceContext");
int ret = invokeCreateInstanceContext(instance.getInstanceId(), null, "createInstanceContext", args, false);
instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_LOAD_BUNDLE_END);
if(ret == 0) {
Expand All @@ -1672,14 +1680,15 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
// WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE.getErrorMsg(),
// null
//);

instance.getApmForInstance().onStage("StartInvokeExecJSBadBundleType");
invokeExecJS(instance.getInstanceId(), null, METHOD_CREATE_INSTANCE, args, false);
instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_LOAD_BUNDLE_END);
return;
}
} catch (Throwable e) {
String err = "[WXBridgeManager] invokeCreateInstance " + e.getCause()
+ instance.getTemplateInfo();
instance.getApmForInstance().onStage("createInstance error :"+e.toString());

instance.onRenderError(
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorCode(),
Expand Down Expand Up @@ -3120,6 +3129,7 @@ public int callCreateFinish(String instanceId) {
long start = System.currentTimeMillis();
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
instance.getApmForInstance().onStage("callCreateFinish");
instance.firstScreenCreateInstanceTime(start);
GraphicActionCreateFinish action = new GraphicActionCreateFinish(instance);
WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(instanceId, action);
Expand Down Expand Up @@ -3157,6 +3167,7 @@ public int callRenderSuccess(String instanceId) {
try {
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
instance.getApmForInstance().onStage("callRenderSuccess");
GraphicActionRenderSuccess action = new GraphicActionRenderSuccess(instance);
WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(instanceId, action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public void doInit() {
addProperty(KEY_PAGE_PROPERTIES_JSLIB_VERSION, WXEnvironment.JS_LIB_SDK_VERSION);
addProperty(KEY_PAGE_PROPERTIES_WEEX_VERSION, WXEnvironment.WXSDK_VERSION);
addProperty(KEY_PAGE_PROPERTIES_WEEX_VERSION, WXEnvironment.WXSDK_VERSION);
addStats("wxReInitCount",WXBridgeManager.reInitCount);
if (null != instance){
addProperty(KEY_PAGE_PROPERTIES_UIKIT_TYPE, instance.getRenderType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.HashMap;
import java.util.Map;

import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.ui.IFComponentHolder;
import com.taobao.weex.utils.WXUtils;

/**
Expand All @@ -36,6 +38,7 @@ public class WXStateRecord {
private RecordList<Info> mJsfmInitHistory;
private RecordList<Info> mJscCrashHistory;
private RecordList<Info> mJscReloadHistory;
private RecordList<Info> mJsThradWatchHistory;

private static class SingleTonHolder {
private static final WXStateRecord S_INSTANCE = new WXStateRecord();
Expand All @@ -46,11 +49,12 @@ public static WXStateRecord getInstance() {
}

private WXStateRecord() {
mExceptionHistory = new RecordList<>(5);
mExceptionHistory = new RecordList<>(10);
mActionHistory = new RecordList<>(20);
mJsfmInitHistory = new RecordList<>(3);
mJscCrashHistory = new RecordList<>(3);
mJscReloadHistory = new RecordList<>(5);
mJsfmInitHistory = new RecordList<>(10);
mJscCrashHistory = new RecordList<>(10);
mJscReloadHistory = new RecordList<>(10);
mJsThradWatchHistory = new RecordList<>(20);
}

/**
Expand All @@ -72,7 +76,15 @@ public void recordAction(String instanceId, String action) {
* check onJSFMInit time,and we know when jsfm is init sucess in reloadJsEngine case
*/
public void onJSFMInit() {
mJsfmInitHistory.add(new Info(WXUtils.getFixUnixTime(), "JSFM", "onJsfmInit"));
recoreJsfmInitHistory("setJsfmVersion");
}

public void recoreJsfmInitHistory(String msg){
mJsfmInitHistory.add(new Info(WXUtils.getFixUnixTime(), "JSFM", msg));
}

public void recordJsThreadWatch(String msg){
mJsThradWatchHistory.add(new Info(WXUtils.getFixUnixTime(), "jsWatch", msg));
}

/**
Expand All @@ -96,6 +108,8 @@ public Map<String, String> getStateInfo() {
stateInfo.put("jsfmInitHistory", mJsfmInitHistory.toString());
stateInfo.put("jscCrashHistory", mJscCrashHistory.toString());
stateInfo.put("jscReloadHistory", mJscReloadHistory.toString());
stateInfo.put("jsThreadWatch", mJsThradWatchHistory.toString());
stateInfo.put("reInitCount", String.valueOf(WXBridgeManager.reInitCount));
return stateInfo;
}

Expand Down Expand Up @@ -144,4 +158,23 @@ public String toString() {
.toString();
}
}

public void startJSThreadWatchDog(){
WXBridgeManager.getInstance().post(jsThreadWatchTask);
}

private long jsThreadTime =-1;

private Runnable jsThreadWatchTask = new Runnable() {
@Override
public void run() {
if (jsThreadTime == -1){
jsThreadTime = WXUtils.getFixUnixTime();
}
long diff = WXUtils.getFixUnixTime() - jsThreadTime;
recordJsThreadWatch("diff:"+diff);
jsThreadTime = WXUtils.getFixUnixTime();
WXBridgeManager.getInstance().postDelay(jsThreadWatchTask,500);
}
};
}

0 comments on commit 1ee8c74

Please sign in to comment.