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

Commit

Permalink
[WEEX-614][Android] apm monitor logic fix (#1527)
Browse files Browse the repository at this point in the history
* [Android] ignore the count down 10 view for interaction time calculate
* [Android] modify imageSize logic
* [Android] fix origin fsRender time ,and newFsRenderTime
  • Loading branch information
lucky-chen authored and YorkShen committed Sep 15, 2018
1 parent aab4ea5 commit 6b0bc9f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 31 deletions.
26 changes: 8 additions & 18 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan
//Performance
public boolean mEnd = false;
public boolean mHasCreateFinish = false;
public boolean mHasSetCreateFinishFsTime = false;
public static final String BUNDLE_URL = "bundleUrl";
private IWXUserTrackAdapter mUserTrackAdapter;
private IWXRenderListener mRenderListener;
Expand Down Expand Up @@ -141,6 +140,7 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan
private Map<String,String> mContainerInfo;

private WXInstanceExceptionRecord mExceptionRecorder;
public boolean isNewFsEnd = false;

/**
* bundle type
Expand Down Expand Up @@ -1236,7 +1236,9 @@ public void runOnUiThread(Runnable action) {
}

public void onRenderSuccess(final int width, final int height) {
firstScreenRenderFinished();
if (!isNewFsEnd){
getApmForInstance().arriveNewFsRenderTime();
}

long time = System.currentTimeMillis() - mRenderStartTime;
long[] renderFinishTime = WXBridgeManager.getInstance().getRenderFinishTime(getInstanceId());
Expand Down Expand Up @@ -1294,7 +1296,7 @@ public void onChangeElement(WXComponent component, boolean isOutOfScreen) {
long lazyLoadTime;

if (mHasCreateFinish){
lazyLoadTime = lastElementChangeTime - mWXPerformance.renderTimeOrigin - mWXPerformance.callCreateFinishTime;
lazyLoadTime = lastElementChangeTime - mWXPerformance.renderTimeOrigin;
if (lazyLoadTime > 8000) {
//bad case
return;
Expand All @@ -1309,12 +1311,11 @@ public void onChangeElement(WXComponent component, boolean isOutOfScreen) {
}

if (!isOutOfScreen) {
getWXPerformance().interactionViewAddCount = getWXPerformance().localInteractionViewAddCount;
getWXPerformance().interactionTime = lastElementChangeTime - mWXPerformance.renderTimeOrigin;

// WXLogUtils.renderPerformanceLog(" interactionViewAddCount", getWXPerformance().interactionViewAddCount);
// WXLogUtils.renderPerformanceLog(" interactionViewAddLimitCount", getWXPerformance().interactionViewAddLimitCount);
// WXLogUtils.renderPerformanceLog(" interactionTime", getWXPerformance().interactionTime);
mApmForInstance.arriveInteraction(getWXPerformance().interactionViewAddLimitCount,getWXPerformance().interactionViewAddCount);
mApmForInstance.arriveInteraction(component);
}
}

Expand Down Expand Up @@ -1418,6 +1419,7 @@ 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);
Expand All @@ -1426,18 +1428,6 @@ public void run() {
WXLogUtils.renderPerformanceLog(" firstScreenParseJsonTime", fitstScreenPerformance[2]);
}

public void firstScreenRenderFinished() {

mApmForInstance.arriveFSRenderTime();
mWXPerformance.screenRenderTime = System.currentTimeMillis() - mRenderStartTime;
if (!mHasSetCreateFinishFsTime) {
mWXPerformance.fsRenderTime = System.currentTimeMillis();
if (mHasCreateFinish)
mHasSetCreateFinishFsTime = true;
}
mWXPerformance.newFsRenderTime = System.currentTimeMillis() - mRenderStartTime;
}

private void destroyView(View rootView) {
try {
if (rootView instanceof ViewGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
*/
package com.taobao.weex.performance;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import android.text.TextUtils;
import android.util.Log;
import com.taobao.weex.BuildConfig;
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.common.WXPerformance;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.utils.WXExceptionUtils;
import com.taobao.weex.utils.WXUtils;

Expand Down Expand Up @@ -110,10 +116,12 @@ public class WXInstanceApm {
private boolean mEnd = false;
private boolean hasRecordFistInteractionView =false;
public final Map<String,Object> extInfo;
private List<WXComponent> mCountDownInteractionComponentList;

public WXInstanceApm(String instanceId) {
mInstanceId = instanceId;
extInfo = new ConcurrentHashMap<>();
mCountDownInteractionComponentList = new ArrayList<>(10);
IApmGenerator generator = WXSDKManager.getInstance().getApmGenerater();
if (null != generator) {
apmInstance = generator.generateApmInstance(WEEX_PAGE_TOPIC);
Expand Down Expand Up @@ -243,29 +251,60 @@ public void onEnd() {
mEnd = true;
}

public void arriveFSRenderTime() {
public void arriveNewFsRenderTime(){
if (null == apmInstance){
return;
}
onStage(WXInstanceApm.KEY_PAGE_STAGES_NEW_FSRENDER);
if (isFSEnd) {
}

public void arriveFSRenderTime() {
if (null == apmInstance){
return;
}
isFSEnd = true;
onStage(WXInstanceApm.KEY_PAGE_STAGES_FSRENDER);
}

public void arriveInteraction(int screenViewCount, int allViewCount) {
if (null == apmInstance) {
public void arriveInteraction(WXComponent targetComponent) {
if (null == apmInstance || null == targetComponent || targetComponent.getInstance() == null ) {
return;
}
targetComponent.interactionTime = WXUtils.getFixUnixTime();
WXPerformance performanceRecord = targetComponent.getInstance().getWXPerformance();
if (null == performanceRecord){
return;
}

if (BuildConfig.DEBUG){
Log.d("wxapm", "screenComponent ["+targetComponent.getComponentType()+","+targetComponent.getRef()
+"], renderTime:"+ (targetComponent.interactionTime -performanceRecord.renderTimeOrigin)
+",style:"+targetComponent.getStyles()
+",attrs:"+targetComponent.getAttrs());
}

if (!hasRecordFistInteractionView){
onStage(KEY_PAGE_STAGES_FIRST_INTERACTION_VIEW);
hasRecordFistInteractionView = true;
}
onStage(KEY_PAGE_STAGES_INTERACTION);
updateMaxStats(KEY_PAGE_STATS_I_SCREEN_VIEW_COUNT, screenViewCount);
updateMaxStats(KEY_PAGE_STATS_I_ALL_VIEW_COUNT, allViewCount);
if (mCountDownInteractionComponentList.size() <10){
mCountDownInteractionComponentList.add(targetComponent);
return;
}
mCountDownInteractionComponentList.add(targetComponent);
WXComponent preComponent = mCountDownInteractionComponentList.remove(0);
if (null == preComponent){
return;
}

if (BuildConfig.DEBUG){
Log.d("wxapm", "interaction record component ["+preComponent.getComponentType()+","+preComponent.getRef());
}

performanceRecord.interactionTime = preComponent.interactionTime - performanceRecord.renderTimeOrigin;
onStageWithTime(KEY_PAGE_STAGES_INTERACTION,preComponent.interactionTime);

updateDiffStats(KEY_PAGE_STATS_I_SCREEN_VIEW_COUNT, 1);
updateMaxStats(KEY_PAGE_STATS_I_ALL_VIEW_COUNT, performanceRecord.localInteractionViewAddCount);
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
if (null != instance) {
updateMaxStats(KEY_PAGE_STATS_I_COMPONENT_CREATE_COUNT, instance.getWXPerformance().componentCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple
private String mLastBoxShadowId;
public int mDeepInComponentTree = 0;
public boolean mIsAddElementToTree = false;
public long interactionTime;

public WXTracing.TraceInfo mTraceInfo = new WXTracing.TraceInfo();

Expand Down Expand Up @@ -948,9 +949,14 @@ public final void setLayout(WXComponent component) {
}

//calculate first screen time
if (!(mHost instanceof ViewGroup) && !mInstance.mEnd && mAbsoluteY + realHeight > mInstance.getWeexHeight() + 1) {
mInstance.firstScreenRenderFinished();
mInstance.mEnd = true;
if (!(mHost instanceof ViewGroup) && mAbsoluteY + realHeight > mInstance.getWeexHeight() + 1) {
if (!mInstance.mEnd){
mInstance.onOldFsRenderTimeLogic();
}
if (!mInstance.isNewFsEnd){
mInstance.isNewFsEnd = true;
mInstance.getApmForInstance().arriveNewFsRenderTime();
}
}

MeasureOutput measureOutput = measure(realWidth, realHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,17 @@ private void monitorImgSize(ImageView imageView,String currentImgUrlStr){
int imgWidth = img.getIntrinsicWidth();
if (!preImgUrlStr.equals(currentImgUrlStr)){
preImgUrlStr = currentImgUrlStr;
if (imgHeight > 1921 && imgWidth > 1081){
if (imgHeight > 1081 && imgWidth > 721){
instance.getApmForInstance().updateDiffStats(WXInstanceApm.KEY_PAGE_STATS_LARGE_IMG_COUNT,1);
}
if (imgHeight * imgWidth > imageView.getMeasuredHeight() * imageView.getMeasuredWidth() +10){
long imgSize = imgHeight * imgWidth;
long viewSize = imageView.getMeasuredHeight() * imageView.getMeasuredWidth();
if (viewSize == 0){
return;
}
double scaleSize = imgSize/(double)viewSize;
//max diff 40*40
if (scaleSize >1.2 && imgSize-viewSize > 1600){
instance.getWXPerformance().wrongImgSizeCount++;
instance.getApmForInstance().updateDiffStats(WXInstanceApm.KEY_PAGE_STATS_WRONG_IMG_SIZE_COUNT,1);
}
Expand Down

0 comments on commit 6b0bc9f

Please sign in to comment.