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

+ [android] performance tracing #586

Merged
merged 16 commits into from
Aug 15, 2017
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
Binary file modified android/sdk/libs/armeabi/libweexjsc.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class WXEnvironment {
*/
public static boolean sDebugMode = false;
public static String sDebugWsUrl = "";
public static boolean sDebugServerConnectable = true;
public static boolean sDebugServerConnectable = false;
public static boolean sRemoteDebugMode = false;
public static String sRemoteDebugProxyUrl = "";
public static long sJSLibInitTime = 0;
Expand Down
37 changes: 36 additions & 1 deletion android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.taobao.weex.dom.WXDomTask;
import com.taobao.weex.dom.WXEvent;
import com.taobao.weex.http.WXHttpUtil;
import com.taobao.weex.tracing.WXTracing;
import com.taobao.weex.ui.component.NestedContainer;
import com.taobao.weex.ui.component.WXBasicComponentType;
import com.taobao.weex.ui.component.WXComponent;
Expand Down Expand Up @@ -116,6 +117,9 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View.
private static volatile int mViewPortWidth = 750;
private int mInstanceViewPortWidth = 750;

public long mRenderStartNanos;
public int mExecJSTraceId = WXTracing.nextId();

/**
* Render strategy.
*/
Expand Down Expand Up @@ -419,6 +423,16 @@ private void renderInternal(String pageName,
return;
}

if (WXTracing.isAvailable()) {
WXTracing.TraceEvent traceEvent = WXTracing.newEvent("executeBundleJS", mInstanceId, -1);
traceEvent.traceId = mExecJSTraceId;
traceEvent.iid = mInstanceId;
traceEvent.tname = "JSThread";
traceEvent.ph = "B";
traceEvent.submit();
mRenderStartNanos = System.nanoTime();
}

ensureRenderArchor();

Map<String, Object> renderOptions = options;
Expand All @@ -433,7 +447,7 @@ private void renderInternal(String pageName,
}

mWXPerformance.pageName = pageName;
mWXPerformance.JSTemplateSize = template.length() / 1024;
mWXPerformance.JSTemplateSize = template.length() / 1024f;

mRenderStartTime = System.currentTimeMillis();
mRenderStrategy = flag;
Expand Down Expand Up @@ -1487,13 +1501,24 @@ class WXHttpListener implements IWXHttpAdapter.OnHttpListener {
private WXRenderStrategy flag;
private WXSDKInstance instance;
private long startRequestTime;
private int traceId;

private WXHttpListener(String pageName, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag, long startRequestTime) {
this.pageName = pageName;
this.options = options;
this.jsonInitData = jsonInitData;
this.flag = flag;
this.startRequestTime = startRequestTime;
this.traceId = WXTracing.nextId();

if (WXTracing.isAvailable()) {
WXTracing.TraceEvent event = WXTracing.newEvent("downloadBundleJS", mInstanceId, -1);
event.iid = mInstanceId;
event.tname = "Network";
event.ph = "B";
event.traceId = traceId;
event.submit();
}
}

public void setSDKInstance(WXSDKInstance instance) {
Expand Down Expand Up @@ -1533,6 +1558,16 @@ public void onHttpFinish(WXResponse response) {
this.instance.getWXStatisticsListener().onHttpFinish();
}

if (WXTracing.isAvailable()) {
WXTracing.TraceEvent event = WXTracing.newEvent("downloadBundleJS", mInstanceId, -1);
event.traceId = traceId;
event.tname = "Network";
event.ph = "E";
event.extParams = new HashMap<>();
event.extParams.put("BundleSize", response.originalData.length);
event.submit();
}

mWXPerformance.networkTime = System.currentTimeMillis() - startRequestTime;
if(response.extendParams!=null){
Object actualNetworkTime=response.extendParams.get("actualNetworkTime");
Expand Down
30 changes: 29 additions & 1 deletion android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.taobao.weex.adapter.DefaultWXHttpAdapter;
import com.taobao.weex.adapter.ICrashInfoReporter;
import com.taobao.weex.adapter.IDrawableLoader;
import com.taobao.weex.adapter.ITracingAdapter;
import com.taobao.weex.adapter.IWXDebugAdapter;
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
Expand All @@ -52,6 +53,7 @@
import com.taobao.weex.utils.WXUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -85,10 +87,13 @@ public class WXSDKManager {
private IWXStatisticsListener mStatisticsListener;
private URIAdapter mURIAdapter;
private IWebSocketAdapterFactory mIWebSocketAdapterFactory;
private ITracingAdapter mTracingAdapter;
private WXValidateProcessor mWXValidateProcessor;
// Tell weexv8 to initialize v8, default is true.
private boolean mNeedInitV8 = true;

private List<InstanceLifeCycleCallbacks> mLifeCycleCallbacks;

private static final int DEFAULT_VIEWPORT_WIDTH = 750;

private WXSDKManager() {
Expand Down Expand Up @@ -286,6 +291,11 @@ void destroyInstance(String instanceId) {
if (!WXUtils.isUiThread()) {
throw new WXRuntimeException("[WXSDKManager] destroyInstance error");
}
if (mLifeCycleCallbacks != null) {
for (InstanceLifeCycleCallbacks callbacks : mLifeCycleCallbacks) {
callbacks.onInstanceDestroyed(instanceId);
}
}
mWXRenderManager.removeRenderStatement(instanceId);
mWXDomManager.removeDomStatement(instanceId);
mBridgeManager.destroyInstance(instanceId);
Expand All @@ -312,7 +322,7 @@ public IWXJSExceptionAdapter getIWXJSExceptionAdapter() {
return mIWXJSExceptionAdapter;
}

void setIWXJSExceptionAdapter(IWXJSExceptionAdapter IWXJSExceptionAdapter) {
public void setIWXJSExceptionAdapter(IWXJSExceptionAdapter IWXJSExceptionAdapter) {
mIWXJSExceptionAdapter = IWXJSExceptionAdapter;
}

Expand Down Expand Up @@ -420,4 +430,22 @@ public void setCrashInfo(String key, String value) {
}
}

public void setTracingAdapter(ITracingAdapter adapter) {
this.mTracingAdapter = adapter;
}

public ITracingAdapter getTracingAdapter() {
return mTracingAdapter;
}

public void registerInstanceLifeCycleCallbacks(InstanceLifeCycleCallbacks callbacks) {
if (mLifeCycleCallbacks == null) {
mLifeCycleCallbacks = new ArrayList<>();
}
mLifeCycleCallbacks.add(callbacks);
}

public interface InstanceLifeCycleCallbacks {
void onInstanceDestroyed(String instanceId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.taobao.weex.adapter;

import com.taobao.weex.tracing.WXTracing;

/**
* Created by moxun on 2017/7/6.
*/

public interface ITracingAdapter {
void enable();
void disable();
void submitTracingEvent(WXTracing.TraceEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import com.taobao.weex.dom.WXDomModule;
import com.taobao.weex.dom.action.Action;
import com.taobao.weex.dom.action.Actions;
import com.taobao.weex.dom.action.TraceableAction;
import com.taobao.weex.tracing.WXTracing;
import com.taobao.weex.utils.WXFileUtils;
import com.taobao.weex.utils.WXJsonUtils;
import com.taobao.weex.utils.WXLogUtils;
Expand Down Expand Up @@ -158,6 +160,8 @@ private boolean isJSFrameworkInit(){

private Interceptor mInterceptor;

private WXParams mInitParams;

private WXBridgeManager() {
initWXBridge(WXEnvironment.sRemoteDebugMode);
mJSThread = new WXThread("WeexJSBridgeThread", this);
Expand Down Expand Up @@ -425,7 +429,9 @@ public int callNative(String instanceId, String tasks, String callback) {


long start = System.currentTimeMillis();
long parseNanos = System.nanoTime();
JSONArray array = JSON.parseArray(tasks);
parseNanos = System.nanoTime() - parseNanos;

if(WXSDKManager.getInstance().getSDKInstance(instanceId)!=null) {
WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start);
Expand All @@ -442,7 +448,7 @@ public int callNative(String instanceId, String tasks, String callback) {
if(target != null){
if(WXDomModule.WXDOM.equals(target)){
WXDomModule dom = getDomModule(instanceId);
dom.callDomMethod(task);
dom.callDomMethod(task,parseNanos);
}else {
JSONObject optionObj = task.getJSONObject(OPTIONS);
callModuleMethod(instanceId, (String) target,
Expand Down Expand Up @@ -495,10 +501,20 @@ public int callCreateBody(String instanceId, String tasks, String callback) {

try {
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
long start = System.currentTimeMillis();
long nanosTemp = System.nanoTime();
JSONObject domObject = JSON.parseObject(tasks);
nanosTemp = System.nanoTime() - nanosTemp;

WXDomModule domModule = getDomModule(instanceId);
Action action = Actions.getCreateBody(domObject);
domModule.postAction((DOMAction)action, true);

if (WXTracing.isAvailable() && action instanceof TraceableAction) {
((TraceableAction) action).mParseJsonNanos = nanosTemp;
((TraceableAction) action).mStartMillis = start;
((TraceableAction) action).onStartDomExecute(instanceId, "createBody", "_root", domObject.getString("type"), tasks);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callCreateBody exception: ", e);
Expand Down Expand Up @@ -637,9 +653,19 @@ public int callUpdateAttrs(String instanceId, String ref, String task, String ca
try {
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
WXDomModule domModule = getDomModule(instanceId);
long start = System.currentTimeMillis();
long parseNanos = System.nanoTime();
JSONObject domObject = JSON.parseObject(task);
parseNanos = System.nanoTime() - parseNanos;

Action action = Actions.getUpdateAttrs(ref, domObject);
domModule.postAction((DOMAction)action, false);

if (WXTracing.isAvailable() && action instanceof TraceableAction) {
((TraceableAction) action).mStartMillis = start;
((TraceableAction) action).mParseJsonNanos = parseNanos;
((TraceableAction) action).onStartDomExecute(instanceId, "updateAttrs", domObject.getString("ref"), domObject.getString("type"), task);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callUpdateAttrs exception: ", e);
Expand Down Expand Up @@ -680,9 +706,19 @@ public int callUpdateStyle(String instanceId, String ref, String task, String ca
try {
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
WXDomModule domModule = getDomModule(instanceId);
long start = System.currentTimeMillis();
long nanosTemp = System.nanoTime();
JSONObject domObject = JSON.parseObject(task);
nanosTemp = System.nanoTime() - nanosTemp;

Action action = Actions.getUpdateStyle(ref, domObject, false);
domModule.postAction((DOMAction)action, false);

if (WXTracing.isAvailable() && action instanceof TraceableAction) {
((TraceableAction) action).mParseJsonNanos = nanosTemp;
((TraceableAction) action).mStartMillis = start;
((TraceableAction) action).onStartDomExecute(instanceId, "updateStyle", ref, domObject.getString("type"), domObject.toJSONString());
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callUpdateStyle exception: ", e);
Expand Down Expand Up @@ -716,6 +752,10 @@ public int callRemoveElement(String instanceId, String ref, String callback) {
WXDomModule domModule = getDomModule(instanceId);
Action action = Actions.getRemoveElement(ref);
domModule.postAction((DOMAction)action, false);

if (WXTracing.isAvailable() && action instanceof TraceableAction) {
((TraceableAction) action).onStartDomExecute(instanceId, "removeElement", ref, null, ref);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callRemoveElement exception: ", e);
Expand Down Expand Up @@ -784,6 +824,10 @@ public int callAddEvent(String instanceId, String ref, String event, String call
WXDomModule domModule = getDomModule(instanceId);
Action action = Actions.getAddEvent(ref, event);
domModule.postAction((DOMAction)action, false);

if (WXTracing.isAvailable() && action instanceof TraceableAction) {
((TraceableAction) action).onStartDomExecute(instanceId, "addEvent", ref, null, event);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callAddEvent exception: ", e);
Expand Down Expand Up @@ -817,6 +861,10 @@ public int callRemoveEvent(String instanceId, String ref, String event, String c
WXDomModule domModule = getDomModule(instanceId);
Action action = Actions.getRemoveEvent(ref, event);
domModule.postAction((DOMAction)action, false);

if (WXTracing.isAvailable() && action instanceof TraceableAction) {
((TraceableAction) action).onStartDomExecute(instanceId, "removeEvent", ref, null, event);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callRemoveEvent exception: ", e);
Expand Down Expand Up @@ -847,13 +895,22 @@ public int callAddElement(String instanceId, String ref,String dom,String index,

if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
long start = System.currentTimeMillis();
long nanosTemp = System.nanoTime();
JSONObject domObject = JSON.parseObject(dom);
nanosTemp = System.nanoTime() - nanosTemp;

if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start);
}
WXDomModule domModule = getDomModule(instanceId);
domModule.postAction(Actions.getAddElement(domObject, ref,Integer.parseInt(index)),false);
DOMAction addElementAction = Actions.getAddElement(domObject, ref,Integer.parseInt(index));
domModule.postAction(addElementAction, false);

if (WXTracing.isAvailable() && addElementAction instanceof TraceableAction) {
((TraceableAction) addElementAction).mParseJsonNanos = nanosTemp;
((TraceableAction) addElementAction).mStartMillis = start;
((TraceableAction) addElementAction).onStartDomExecute(instanceId, "addElement", domObject.getString("ref"), domObject.getString("type"), dom);
}
}

if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) {
Expand Down Expand Up @@ -1400,9 +1457,14 @@ private WXParams assembleDefaultOptions() {
wxParams.setDeviceHeight(TextUtils.isEmpty(config.get("deviceHeight")) ? String.valueOf(WXViewUtils.getScreenHeight(WXEnvironment.sApplication)) : config.get("deviceHeight"));
wxParams.setOptions(WXEnvironment.getCustomOptions());
wxParams.setNeedInitV8(WXSDKManager.getInstance().needInitV8());
mInitParams = wxParams;
return wxParams;
}

public WXParams getInitParams() {
return mInitParams;
}

private void execRegisterFailTask() {

if (mRegisterModuleFailList.size() > 0) {
Expand Down
Loading