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

[WEEX-560][Android] fix null point of apm && report initJSFM fail info #1422

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class WXBridgeManager implements Callback, BactchExecutor {
public static final String METHOD_NOTIFY_TRIM_MEMORY = "notifyTrimMemory";
public static final String METHOD_NOTIFY_SERIALIZE_CODE_CACHE =
"notifySerializeCodeCache";
public static final String METHOD_CREATE_INSTANCE_CONTEXT = "createInstanceContext";

public static final String KEY_METHOD = "method";
public static final String KEY_ARGS = "args";
Expand Down Expand Up @@ -1628,8 +1629,12 @@ private void invokeInitFramework(Message msg) {
}
}

public static long sInitFrameWorkTimeOrigin;
public static StringBuilder sInitFrameWorkMsg = new StringBuilder();

private void initFramework(String framework) {
if (WXSDKEngine.isSoInitialized() && !isJSFrameworkInit()) {
sInitFrameWorkTimeOrigin = System.currentTimeMillis();
if (TextUtils.isEmpty(framework)) {
// if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d("weex JS framework from assets");
Expand All @@ -1639,9 +1644,11 @@ private void initFramework(String framework) {
} else {
framework = WXFileUtils.loadAsset("weex-main-jsfm.js", WXEnvironment.getApplication());
}
sInitFrameWorkMsg.append("| weex JS framework from assets, isSandBoxContext: ").append(isSandBoxContext);
}
if (TextUtils.isEmpty(framework)) {
setJSFrameworkInit(false);
sInitFrameWorkMsg.append("| framework isEmpty ");
WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_ERR_JS_FRAMEWORK,
"initFramework", "framework is empty!! ", null);
return;
Expand All @@ -1666,6 +1673,7 @@ private void initFramework(String framework) {
} catch (Exception e) {
e.printStackTrace();
}
sInitFrameWorkMsg.append(" | pieSupport:").append(pieSupport);
WXLogUtils.d("[WXBridgeManager] initFrameworkEnv crashFile:" + crashFile + " pieSupport:" + pieSupport);
// extends initFramework
if (mWXBridge.initFrameworkEnv(framework, assembleDefaultOptions(), crashFile, pieSupport) == INIT_FRAMEWORK_OK) {
Expand All @@ -1683,39 +1691,20 @@ private void initFramework(String framework) {
WXEnvironment.JsFrameworkInit = true;
registerDomModule();
trackComponentAndModulesTime();
String reinitInfo = "";
if (reInitCount > 1) {
reinitInfo = "reinit Framework:";
// WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_JS_FRAMEWORK_REINIT_SUCCESS,
// "initFramework", reinitInfo + "success", null);
} else {
// WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_JS_FRAMEWORK_INIT_SUCCESS,
// "initFramework", reinitInfo + "success", null);
}
} else {
sInitFrameWorkMsg.append(" | ExecuteJavaScript fail, reInitCount").append(reInitCount);
if (reInitCount > 1) {
WXLogUtils.e("[WXBridgeManager] invokeReInitFramework ExecuteJavaScript fail");
String err = "[WXBridgeManager] invokeReInitFramework ExecuteJavaScript fail reinit FrameWork";
// WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_ERR_JS_FRAMEWORK,
// "initFramework", "reInitCount = " + reInitCount + err, null);
} else {
WXLogUtils.e("[WXBridgeManager] invokeInitFramework ExecuteJavaScript fail");
String err = "[WXBridgeManager] invokeInitFramework ExecuteJavaScript fail";
// WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_ERR_JS_FRAMEWORK,
// "initFramework", err, null);
}
}
} catch (Throwable e) {
sInitFrameWorkMsg.append(" | invokeInitFramework exception ").append(e.toString());
if (reInitCount > 1) {
WXLogUtils.e("[WXBridgeManager] invokeInitFramework ", e);
String err = "[WXBridgeManager] invokeInitFramework reinit FrameWork exception!#" + e.toString();
// WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_ERR_JS_FRAMEWORK,
// "initFramework", "reInitCount ==" + reInitCount + err, null);
} else {
WXLogUtils.e("[WXBridgeManager] invokeInitFramework ", e);
String err = "[WXBridgeManager] invokeInitFramework exception!#" + e.toString();
// WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_ERR_JS_FRAMEWORK,
// "initFramework", err, null);
}
}

Expand Down Expand Up @@ -2015,12 +2004,17 @@ public void reportJSException(String instanceId, String function,
instance.setNeedLoad(true);
return;
} else {
String errorMsg = new StringBuilder()
.append(WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorMsg())
.append(", reportJSException >>>> instanceId:").append(instanceId)
.append(", exception function:").append(function)
.append(", exception:").append(exception)
.append(", extInitTime:").append(System.currentTimeMillis()-WXBridgeManager.sInitFrameWorkTimeOrigin).append("ms")
.append(", extInitErrorMsg:").append(WXBridgeManager.sInitFrameWorkMsg.toString())
.toString();
instance.onRenderError(//DegradPassivity to H5
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorCode(),
WXErrorCode.WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED.getErrorMsg() +
"reportJSException >>>> instanceId:" + instanceId
+ ", exception function:" + function + ", exception:"
+ exception
errorMsg
);
//doReportJSException(instanceId,function,exception);
WXExceptionUtils.commitCriticalExceptionRT(instanceId,WXErrorCode.WX_RENDER_ERR_JS_CREATE_INSTANCE,function,exception,null);
Expand Down Expand Up @@ -2083,6 +2077,12 @@ private void doReportJSException(String instanceId, String function, String exce

}
}
Map<String,String> extInfo = null;
if (METHOD_CREATE_INSTANCE.equals(function) || METHOD_CREATE_INSTANCE_CONTEXT.equals(function)){
extInfo = new HashMap<>();
extInfo.put("extInitTime",(System.currentTimeMillis() - WXBridgeManager.sInitFrameWorkTimeOrigin)+"ms");
extInfo.put("extInitErrorMsg",WXBridgeManager.sInitFrameWorkMsg.toString());
}

if (checkEmptyScreen(instance)){
if (WXEnvironment.isApkDebugable()){
Expand All @@ -2091,12 +2091,12 @@ private void doReportJSException(String instanceId, String function, String exce
WXExceptionUtils.commitCriticalExceptionRT(exceptionId, WXErrorCode.WX_RENDER_ERR_JS_RUNTIME,
function,
WXErrorCode.WX_RENDER_ERR_JS_RUNTIME.getErrorMsg() + exception,
null);
extInfo);
} else {
WXExceptionUtils.commitCriticalExceptionRT(exceptionId, WXErrorCode.WX_KEY_EXCEPTION_WXBRIDGE,
function,
WXErrorCode.WX_KEY_EXCEPTION_WXBRIDGE.getErrorMsg() + exception,
null);
extInfo);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public enum WXErrorCode {
/**
* WX Key Exception Commit RT JsBridge eg. js excute runtime error
*/
WX_KEY_EXCEPTION_WXBRIDGE("-9400", "[js excute runtime error] detail js stack \n",ErrorType.JS_ERROR,ErrorGroup.JS),
WX_KEY_EXCEPTION_WXBRIDGE("-9400", "[js excute runtime error] detail js stack -> ",ErrorType.JS_ERROR,ErrorGroup.JS),
WX_KEY_EXCEPTION_WXBRIDGE_EXCEPTION("-9401", "[js excute runtime error] detail js stack \n",ErrorType.JS_ERROR,ErrorGroup.JS),

/**
Expand Down Expand Up @@ -278,7 +278,7 @@ public enum WXErrorCode {

WX_DEGRAD_ERR_INSTANCE_CREATE_FAILED_JS("-1006", "degradeToH5|createInstance fail|wx_create_instance_error",ErrorType.DEGRAD_ERROR,ErrorGroup.JS),


WX_ERR_HASH_MAP_TMP("-10010", "WX_ERR_HASH_MAP_TMP",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

/**
* TEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
package com.taobao.weex.performance;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.common.WXErrorCode;
import com.taobao.weex.utils.WXExceptionUtils;

public class WXInstanceApm {

Expand Down Expand Up @@ -102,7 +104,7 @@ public WXInstanceApm(String instanceId) {
IApmGenerator generator = WXSDKManager.getInstance().getApmGenerater();
if (null != generator) {
apmInstance = generator.generateApmInstance(WEEX_PAGE_TOPIC);
recordStatsMap = new HashMap<>();
recordStatsMap = new ConcurrentHashMap<>();
}
}

Expand Down Expand Up @@ -228,7 +230,19 @@ public void updateDiffStats(String name, double diffValue) {
if (null == apmInstance) {
return;
}
double preVal = recordStatsMap.containsKey(name) ? recordStatsMap.get(name) : 0;
Double preVal = recordStatsMap.containsKey(name) ? recordStatsMap.get(name) : 0;
//fix by use ConcurrentHashMap,but not sure,so report if error still happen
if (null == preVal){
WXExceptionUtils.commitCriticalExceptionRT(
"",
WXErrorCode.WX_ERR_HASH_MAP_TMP,
"updateDiffStats",
"key : "+name,
null
);
return;
}

double currentValue = preVal + diffValue;
recordStatsMap.put(name, currentValue);
addStats(name, currentValue);
Expand All @@ -238,7 +252,18 @@ public void updateMaxStats(String name, double currentVal) {
if (null == apmInstance) {
return;
}
double maxValue = recordStatsMap.containsKey(name) ? recordStatsMap.get(name) : 0;
Double maxValue = recordStatsMap.containsKey(name) ? recordStatsMap.get(name) : 0;
//fix by use ConcurrentHashMap,but not sure,so report if error still happen
if (null == maxValue){
WXExceptionUtils.commitCriticalExceptionRT(
"",
WXErrorCode.WX_ERR_HASH_MAP_TMP,
"updateMaxStats",
"key : "+name,
null
);
return;
}
if (maxValue < currentVal) {
maxValue = currentVal;
recordStatsMap.put(name, currentVal);
Expand Down