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

Commit

Permalink
*[Android] weex performance optimization (#1844)
Browse files Browse the repository at this point in the history
* try get debug flag from env params
* rm useless log rm
* try get debugflag from environment
* get cpu abi from Build.CPU_ABI;
  • Loading branch information
lucky-chen authored and YorkShen committed Nov 29, 2018
1 parent 8780ecd commit 4e1aacb
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public static Bitmap blur(@NonNull Bitmap originalImage, int radius) {
}

Bitmap result = stackBlur(sampledImage,radius);
WXLogUtils.d(TAG, "elapsed time on blurring image(radius:"+ radius + ",sampling: " + sampling + "): " + (System.currentTimeMillis() - start) + "ms");
return result;
}catch (Exception e) {
WXLogUtils.e(TAG, "thrown exception when blurred image(times = " + i + "),"+ e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.alibaba.weex.commons.adapter;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
import com.taobao.weex.common.WXJSExceptionInfo;
import com.taobao.weex.utils.WXLogUtils;
Expand All @@ -29,7 +30,7 @@ public class JSExceptionAdapter implements IWXJSExceptionAdapter {

@Override
public void onJSException(WXJSExceptionInfo exception) {
if (exception != null) {
if (exception != null && WXEnvironment.isApkDebugable()) {
WXLogUtils.d(exception.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.bridge.SimpleJSCallback;
import com.taobao.weex.utils.WXLogUtils;
Expand Down Expand Up @@ -128,7 +129,9 @@ private WXLocationListener findLocation(String watchId, String sucCallback, Stri

@Override
public void watchPosition(final String successCallback, final String errorCallback, final String params) {
WXLogUtils.d("into--[watchPosition] successCallback:" + successCallback + " errorCallback:" + errorCallback + "\nparams:" + params);
if (WXEnvironment.isApkDebugable()){
WXLogUtils.d("into--[watchPosition] successCallback:" + successCallback + " errorCallback:" + errorCallback + "\nparams:" + params);
}
if (!TextUtils.isEmpty(params)) {
try {
JSONObject jsObj = new JSONObject(params);
Expand Down
21 changes: 15 additions & 6 deletions android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class WXEnvironment {
/** from init to sdk-ready **/
public static long sSDKInitTime =0;

public static long sJSFMStartListenerTime=0;

/**
* component and modules ready
* */
Expand All @@ -110,6 +112,7 @@ public class WXEnvironment {
public static LogLevel sLogLevel = LogLevel.DEBUG;
private static boolean isApkDebug = true;
public static boolean isPerf = false;
private static boolean sDebugFlagInit = false;

private static boolean openDebugLog = false;

Expand Down Expand Up @@ -277,20 +280,26 @@ public static boolean isApkDebugable() {
return false;
}

if (!isApkDebug) {
return false;
if (sDebugFlagInit){
return isApkDebug;
}
try {
ApplicationInfo info = sApplication.getApplicationInfo();
isApkDebug = (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
return isApkDebug;
String debugModeConfig = getCustomOptions().get(WXConfig.debugMode);
if (TextUtils.isEmpty(debugModeConfig)){
ApplicationInfo info = sApplication.getApplicationInfo();
isApkDebug = (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}else {
isApkDebug = Boolean.valueOf(debugModeConfig);
}
} catch (Exception e) {
/**
* Don't call WXLogUtils.e here,will cause stackoverflow
*/
e.printStackTrace();
isApkDebug = false;
}
return true;
sDebugFlagInit = true;
return isApkDebug;
}

public static boolean isPerf() {
Expand Down
1 change: 1 addition & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;

import android.util.Log;
import com.taobao.weex.adapter.IDrawableLoader;
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
Expand Down
81 changes: 39 additions & 42 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ public void render(String pageName, Script template, Map<String, Object> options
mWXPerformance.beforeInstanceRender(mInstanceId);

if(WXEnvironment.isApkDebugable() && WXPerformance.DEFAULT.equals(pageName)){
WXLogUtils.e("WXSDKInstance", "Please set your pageName or your js bundle url !!!!!!!");

if (getUIContext() != null) {
new AlertDialog.Builder(getUIContext())
Expand Down Expand Up @@ -682,8 +681,6 @@ private void renderInternal(String pageName,
mBundleUrl = mWXPerformance.pageName;
}

WXLogUtils.d("WXSDKInstance", "Start render page: " + pageName);

if (WXTracing.isAvailable()) {
WXTracing.TraceEvent traceEvent = WXTracing.newEvent("executeBundleJS", mInstanceId, -1);
traceEvent.traceId = mExecJSTraceId;
Expand Down Expand Up @@ -950,9 +947,6 @@ public String getInstanceId() {
}

public Context getContext() {
if(mContext == null){
WXLogUtils.e("WXSdkInstance mContext == null");
}
return mContext;
}

Expand Down Expand Up @@ -1058,7 +1052,9 @@ public void onActivityCreate() {
if(mRootComp != null) {
mRootComp.onActivityCreate();
}else{
WXLogUtils.w("Warning :Component tree has not build completely,onActivityCreate can not be call!");
if (WXEnvironment.isApkDebugable()){
WXLogUtils.w("Warning :Component tree has not build completely,onActivityCreate can not be call!");
}
}

mGlobalEventReceiver=new WXGlobalEventReceiver(this);
Expand All @@ -1080,7 +1076,10 @@ public void onActivityStart() {
if(mRootComp != null) {
mRootComp.onActivityStart();
}else{
WXLogUtils.w("Warning :Component tree has not build completely,onActivityStart can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely,onActivityStart can not be call!");

}
}

}
Expand All @@ -1091,7 +1090,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
if(mRootComp != null) {
mRootComp.onCreateOptionsMenu(menu);
}else{
WXLogUtils.w("Warning :Component tree has not build completely,onActivityStart can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely,onActivityStart can not be call!");

}
}
return true;
}
Expand All @@ -1116,10 +1118,11 @@ public void onActivityPause() {
if(mRootComp != null) {
mRootComp.onActivityPause();
}else{
WXLogUtils.w("Warning :Component tree has not build completely,onActivityPause can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely,onActivityPause can not be call!");
}
}

WXLogUtils.i("Application onActivityPause()");
if (!mCurrentGround) {
WXLogUtils.i("Application to be in the backround");
Intent intent = new Intent(WXGlobalEventReceiver.EVENT_ACTION);
Expand Down Expand Up @@ -1147,7 +1150,9 @@ public void onActivityResume() {
if(mRootComp != null) {
mRootComp.onActivityResume();
}else{
WXLogUtils.w("Warning :Component tree has not build completely, onActivityResume can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely, onActivityResume can not be call!");
}
}

if (mCurrentGround) {
Expand Down Expand Up @@ -1176,10 +1181,11 @@ public void onActivityStop() {
if(mRootComp != null) {
mRootComp.onActivityStop();
}else{
WXLogUtils.w("Warning :Component tree has not build completely, onActivityStop can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely, onActivityStop can not be call!");
}
}


}

@Override
Expand All @@ -1189,7 +1195,9 @@ public void onActivityDestroy() {
if(mRootComp != null) {
mRootComp.onActivityDestroy();
}else{
WXLogUtils.w("Warning :Component tree has not build completely, onActivityDestroy can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely, onActivityDestroy can not be call!");
}
}

destroy();
Expand All @@ -1203,7 +1211,9 @@ public boolean onActivityBack() {
if(mRootComp != null) {
return mRootComp.onActivityBack();
}else{
WXLogUtils.w("Warning :Component tree has not build completely, onActivityBack can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely, onActivityBack can not be call!");
}
}

return false;
Expand Down Expand Up @@ -1236,7 +1246,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data){
if(mRootComp != null) {
mRootComp.onActivityResult(requestCode,resultCode,data);
}else{
WXLogUtils.w("Warning :Component tree has not build completely, onActivityResult can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w("Warning :Component tree has not build completely, onActivityResult can not be call!");
}
}
}

Expand All @@ -1248,7 +1260,10 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
if(mRootComp != null) {
mRootComp.onRequestPermissionsResult(requestCode,permissions,grantResults);
}else{
WXLogUtils.w("Warning :Component tree has not build completely, onRequestPermissionsResult can not be call!");
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.w(
"Warning :Component tree has not build completely, onRequestPermissionsResult can not be call!");
}
}
}

Expand Down Expand Up @@ -1303,7 +1318,9 @@ public void onCreateFinish() {
* call back when update finish
*/
public void onUpdateFinish() {
WXLogUtils.d("Instance onUpdateSuccess");
if (WXEnvironment.isApkDebugable()){
WXLogUtils.d("Instance onUpdateSuccess");
}
}


Expand All @@ -1319,11 +1336,6 @@ public void onRenderSuccess(final int width, final int height) {

long time = System.currentTimeMillis() - mRenderStartTime;
long[] renderFinishTime = WXBridgeManager.getInstance().getRenderFinishTime(getInstanceId());
WXLogUtils.renderPerformanceLog("onRenderSuccess", time);
WXLogUtils.renderPerformanceLog(" invokeCreateInstance",mWXPerformance.communicateTime);
WXLogUtils.renderPerformanceLog(" onRenderSuccessCallBridgeTime", renderFinishTime[0]);
WXLogUtils.renderPerformanceLog(" onRenderSuccessCssLayoutTime", renderFinishTime[1]);
WXLogUtils.renderPerformanceLog(" onRenderSuccessParseJsonTime", renderFinishTime[2]);

mWXPerformance.callBridgeTime = renderFinishTime[0];
mWXPerformance.cssLayoutTime = renderFinishTime[1];
Expand All @@ -1333,7 +1345,6 @@ public void onRenderSuccess(final int width, final int height) {
if(mWXPerformance.screenRenderTime<0.001){
mWXPerformance.screenRenderTime = time;
}
WXLogUtils.d(WXLogUtils.WEEX_PERF_TAG, "mComponentNum:" + mWXPerformance.componentCount);

if (mRenderListener != null && mContext != null) {
mRenderListener.onRenderSuccess(WXSDKInstance.this, width, height);
Expand All @@ -1343,16 +1354,16 @@ public void onRenderSuccess(final int width, final int height) {
performance.args=getBundleUrl();
mUserTrackAdapter.commit(mContext,null,IWXUserTrackAdapter.JS_BRIDGE,performance,getUserTrackParams());
}

WXLogUtils.d(WXLogUtils.WEEX_PERF_TAG, mWXPerformance.toString());
if (WXEnvironment.isApkDebugable()){
WXLogUtils.d(WXLogUtils.WEEX_PERF_TAG, mWXPerformance.toString());
}
}
if(WXEnvironment.isPerf()){
WXLogUtils.e("weex_perf",mWXPerformance.getPerfData());
}
}

public void onRefreshSuccess(final int width, final int height) {
WXLogUtils.renderPerformanceLog("onRefreshSuccess", (System.currentTimeMillis() - mRefreshStartTime));
if (mRenderListener != null && mContext != null) {
mRenderListener.onRefreshSuccess(WXSDKInstance.this, width, height);
}
Expand Down Expand Up @@ -1391,10 +1402,6 @@ public void onChangeElement(WXComponent component, boolean isOutOfScreen) {
}

if (!isOutOfScreen) {

// WXLogUtils.renderPerformanceLog(" interactionViewAddCount", getWXPerformance().interactionViewAddCount);
// WXLogUtils.renderPerformanceLog(" interactionViewAddLimitCount", getWXPerformance().interactionViewAddLimitCount);
// WXLogUtils.renderPerformanceLog(" interactionTime", getWXPerformance().interactionTime);
mApmForInstance.arriveInteraction(component);
}
}
Expand Down Expand Up @@ -1500,13 +1507,6 @@ public void run() {
mApmForInstance.arriveFSRenderTime();
mWXPerformance.fsRenderTime = System.currentTimeMillis();
mWXPerformance.screenRenderTime = System.currentTimeMillis() - mRenderStartTime;

long[] fitstScreenPerformance = WXBridgeManager.getInstance().getFirstScreenRenderTime(getInstanceId());
WXLogUtils.renderPerformanceLog("firstScreenRenderFinished", mWXPerformance.screenRenderTime);
WXLogUtils.renderPerformanceLog(" firstScreenJSFExecuteTime", mWXPerformance.firstScreenJSFExecuteTime);
WXLogUtils.renderPerformanceLog(" firstScreenCallBridgeTime", fitstScreenPerformance[0]);
WXLogUtils.renderPerformanceLog(" firstScreenCssLayoutTime", fitstScreenPerformance[1]);
WXLogUtils.renderPerformanceLog(" firstScreenParseJsonTime", fitstScreenPerformance[2]);
}

private void destroyView(View rootView) {
Expand Down Expand Up @@ -2011,11 +2011,9 @@ public void onHttpFinish(WXResponse response) {
mApmForInstance.updateRecordInfo(response.extendParams);
Object actualNetworkTime=response.extendParams.get("actualNetworkTime");
mWXPerformance.actualNetworkTime=actualNetworkTime instanceof Long?(long)actualNetworkTime:0;
WXLogUtils.renderPerformanceLog("actualNetworkTime", mWXPerformance.actualNetworkTime);

Object pureNetworkTime=response.extendParams.get("pureNetworkTime");
mWXPerformance.pureNetworkTime=pureNetworkTime instanceof Long?(long)pureNetworkTime:0;
WXLogUtils.renderPerformanceLog("pureNetworkTime", mWXPerformance.pureNetworkTime);

Object connectionType=response.extendParams.get("connectionType");
mWXPerformance.connectionType=connectionType instanceof String?(String)connectionType:"";
Expand Down Expand Up @@ -2065,7 +2063,6 @@ public void onHttpFinish(WXResponse response) {
}
}
}
WXLogUtils.renderPerformanceLog("networkTime", mWXPerformance.networkTime);
String wxErrorCode = WXInstanceApm.VALUE_ERROR_CODE_DEFAULT;
if (response!=null && response.originalData!=null && TextUtils.equals("200", response.statusCode)) {
mApmForInstance.onStage(WXInstanceApm.KEY_PAGE_STAGES_DOWN_BUNDLE_END);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface IWXUserTrackAdapter {
String STREAM_MODULE = "streamModule";
String INVOKE_MODULE = "invokeModule";
String INIT_FRAMEWORK = "initFramework";
String COUNTER = "counter";

/**
* monitor keys
Expand Down
Loading

0 comments on commit 4e1aacb

Please sign in to comment.