You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/09/15 14:50:36 UTC

[GitHub] YorkShen closed pull request #1527: [WEEX-614][Android] apm monitor logic fix

YorkShen closed pull request #1527: [WEEX-614][Android] apm monitor logic fix
URL: https://github.com/apache/incubator-weex/pull/1527
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
index 4a32a1d2b8..77c2027aab 100644
--- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
+++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
@@ -109,7 +109,6 @@
   //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;
@@ -141,6 +140,7 @@
   private Map<String,String> mContainerInfo;
 
   private WXInstanceExceptionRecord mExceptionRecorder;
+  public boolean isNewFsEnd = false;
 
   /**
    * bundle type
@@ -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());
@@ -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;
@@ -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);
     }
   }
 
@@ -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);
@@ -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) {
diff --git a/android/sdk/src/main/java/com/taobao/weex/performance/WXInstanceApm.java b/android/sdk/src/main/java/com/taobao/weex/performance/WXInstanceApm.java
index 611252f199..875e3d789d 100644
--- a/android/sdk/src/main/java/com/taobao/weex/performance/WXInstanceApm.java
+++ b/android/sdk/src/main/java/com/taobao/weex/performance/WXInstanceApm.java
@@ -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;
 
@@ -110,10 +116,12 @@
     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);
@@ -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);
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
index 37351670ed..91f6fd7612 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
@@ -170,6 +170,7 @@
   private String mLastBoxShadowId;
   public int mDeepInComponentTree = 0;
   public boolean mIsAddElementToTree = false;
+  public long interactionTime;
 
   public WXTracing.TraceInfo mTraceInfo = new WXTracing.TraceInfo();
 
@@ -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);
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXImage.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXImage.java
index 980bdd6b2d..061c9bfa0c 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXImage.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXImage.java
@@ -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);
       }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services