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/17 05:52:29 UTC

[GitHub] cxfeng1 closed pull request #1528: [WEEX-615][iOS] apm data improvement

cxfeng1 closed pull request #1528: [WEEX-615][iOS] apm data improvement
URL: https://github.com/apache/incubator-weex/pull/1528
 
 
   

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/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
index 63f3593dc9..2834d76061 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
@@ -26,7 +26,7 @@
 
 #define WX_ERROR_TYPE_NATIVE    @"NATIVE_ERROR"
 #define WX_ERROR_TYPE_JS        @"JS_ERROR"
-#define WX_ERROR_TYPE_DEGRADE    @"DEGRADE_ERROR"
+#define WX_ERROR_TYPE_DEGRADE   @"DEGRAD_ERROR"
 #define WX_ERROR_TYPE_RENDER    @"RENDER_ERROR"
 #define WX_ERROR_TYPE_DOWNLOAD  @"DOWN_LOAD_ERROR"
 
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
index 91c6e84dc7..801dd75bb5 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
@@ -818,7 +818,6 @@ - (void)createFinish
     
     WXSDKInstance *instance  = self.weexInstance;
     [self _addUITask:^{
-        [instance.performance onInstanceCreateFinish];
         
         WX_MONITOR_INSTANCE_PERF_END(WXPTFirstScreenRender, instance);
         WX_MONITOR_INSTANCE_PERF_END(WXPTAllRender, instance);
@@ -863,6 +862,7 @@ - (void)renderFinish
     WXSDKInstance *instance  = self.weexInstance;
     [self _addUITask:^{
         UIView *rootView = instance.rootView;
+        [instance.performance onInstanceRenderSuccess:instance];
         if (instance.renderFinish) {
             [WXTracingManager startTracingWithInstanceId:instance.instanceId ref:nil className:nil name:nil phase:WXTracingInstant functionName:WXTRenderFinish options:@{@"threadName":WXTUIThread}];
             instance.renderFinish(rootView);
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h b/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h
index 99b8d6ab88..042fd30a1d 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h
@@ -5,5 +5,6 @@
 @property (nonatomic,assign) bool hasAdd;
 
 
+@property (nonatomic,assign) long interactionTime;
 
 @end
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 24e213fa0c..3aaed72d65 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -252,6 +252,7 @@ - (void)renderView:(NSString *)source options:(NSDictionary *)options data:(id)d
     
     self.needValidate = [[WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)] needValidate:self.scriptURL];
     
+    [self _setPageNameValue:nil];
     [self _renderWithMainBundleString:source];
     
     [WXTracingManager setBundleJSType:source instanceId:self.instanceId];
@@ -274,6 +275,7 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString
     self.apmInstance.isStartRender = YES;
     
     self.performance.renderTimeOrigin = CACurrentMediaTime()*1000;
+    self.performance.renderUnixTimeOrigin = [WXUtility getUnixFixTimeMillis];
     [self.apmInstance onStage:KEY_PAGE_STAGES_RENDER_ORGIGIN];
     
     if (![WXUtility isBlankString:self.pageName]) {
@@ -384,6 +386,19 @@ - (void)renderWithMainBundleString:(NSNotification*)notification {
     [self _renderWithMainBundleString:_mainBundleString];
 }
 
+- (void) _setPageNameValue:(NSURL*) url
+{
+    if (!self.pageName || [self.pageName isEqualToString:@""]) {
+        self.pageName = url.absoluteString;
+    }
+    if (nil == self.pageName && nil != self.viewController) {
+        self.pageName = NSStringFromClass(self.viewController.class);
+    }
+    if (nil == self.pageName) {
+        self.pageName = @"unSetPageNameOrUrl-checkByRenderWithRequest";
+    }
+}
+
 - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)options data:(id)data;
 {
     NSURL *url = request.URL;
@@ -401,9 +416,7 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)
     }
     _options = [newOptions copy];
   
-    if (!self.pageName || [self.pageName isEqualToString:@""]) {
-        self.pageName = url.absoluteString ? : @"";
-    }
+    [self _setPageNameValue:url];
     
     request.userAgent = [WXUtility userAgent];
     
@@ -445,7 +458,7 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)
             [WXExceptionUtils commitCriticalExceptionRT:strongSelf.instanceId
                                                 errCode:[NSString stringWithFormat:@"%d", WX_KEY_EXCEPTION_JS_DOWNLOAD]
                                                function:@"_renderWithRequest:options:data:"
-                                              exception:@"no data return"
+                                              exception:errorMessage
                                               extParams:nil];
             
             if (strongSelf.onFailed) {
@@ -491,7 +504,6 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)
     };
     
     _mainBundleLoader.onFailed = ^(NSError *loadError) {
-        [weakSelf.apmInstance onStage:KEY_PAGE_STAGES_DOWN_BUNDLE_END];
         NSString *errorMessage = [NSString stringWithFormat:@"Request to %@ occurs an error:%@", request.URL, loadError.localizedDescription];
         long wxErrorCode = [loadError.domain isEqualToString:NSURLErrorDomain] && loadError.code == NSURLErrorNotConnectedToInternet ? WX_ERR_NOT_CONNECTED_TO_INTERNET : WX_ERR_JSBUNDLE_DOWNLOAD;
 
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.h
index c696fe7d8d..c9fca1622f 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.h
@@ -25,6 +25,7 @@
 @interface WXPerformance : NSObject
 
 
+@property (nonatomic, assign) double renderUnixTimeOrigin;
 @property (nonatomic, assign) double renderTimeOrigin;
 @property (nonatomic, assign) double jsCreateFinishTime;
 
@@ -61,11 +62,12 @@
 @property (nonatomic,assign) double componentCreateTime;
 
 @property (nonatomic,assign) double newFsRenderTime;
+@property (nonatomic,assign) long lastRealInteractionTime;
 //for performance record
 
 - (void)onViewLoad:(WXComponent *)targetComponent;
 - (void)recordComponentCreatePerformance:(double) diffTime forComponent:(WXComponent *)targetComponent;
-- (void)onInstanceCreateFinish;
+- (void)onInstanceRenderSuccess:(WXSDKInstance*) instance;
 
 @end
 
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
index ffe9d85303..dc1987a41c 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
@@ -29,6 +29,9 @@
 #import "WXUtility.h"
 
 @interface WXPerformance()
+{
+    NSMutableArray<WXComponent*>* _mCountDownComponentList;
+}
 @property (nonatomic, assign) bool hasRecordFsRenderTimeByPosition;
 @property (nonatomic, assign) double interactionAddCountRecord;
 @end
@@ -67,6 +70,9 @@ - (void)onViewLoad:(WXComponent *)targetComponent
 
 - (void) _handleRenderTime:(WXComponent*)targetComponent withModifyTime:(double)modifyTime
 {
+    if (nil == targetComponent) {
+        return;
+    }
     double diff = modifyTime - self.renderTimeOrigin;
     if (diff > 8000) {
         return;
@@ -89,7 +95,7 @@ - (void) _handleRenderTime:(WXComponent*)targetComponent withModifyTime:(double)
     if (!self.hasRecordFsRenderTimeByPosition && rightBottom.y > rootFrame.size.height +1 && ![self _isViewGroup:targetComponent] ) {
         self.newFsRenderTime = diff;
         self.hasRecordFsRenderTimeByPosition = true;
-        [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_FSRENDER];
+        [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_NEW_FSRENDER];
     }
     
     UIView *root = targetComponent.weexInstance.rootView;
@@ -122,9 +128,24 @@ - (void) _handleRenderTime:(WXComponent*)targetComponent withModifyTime:(double)
         targetComponent.weexInstance.apmInstance.hasRecordFirstInterationView = YES;
         [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_FIRST_INTERACTION_VIEW];
     }
-    [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_INTERACTION];
+    self.lastRealInteractionTime = [WXUtility getUnixFixTimeMillis];
+    
+    targetComponent.interactionTime = self.lastRealInteractionTime ;
+    if (nil == _mCountDownComponentList) {
+        _mCountDownComponentList = [[NSMutableArray alloc] init];
+    }
+    if (_mCountDownComponentList.count <10) {
+        [_mCountDownComponentList addObject:targetComponent];
+        return;
+    }
+    [_mCountDownComponentList addObject:targetComponent];
+    WXComponent* preComponent = [_mCountDownComponentList objectAtIndex:0];
+    [_mCountDownComponentList removeObjectAtIndex:0];
+    
+    [targetComponent.weexInstance.apmInstance onStageWithTime:KEY_PAGE_STAGES_INTERACTION time:preComponent.interactionTime];
     self.interactionLimitAddOpCount++;
     self.interactionAddCount = self.interactionAddCountRecord;
+    diff = modifyTime - self.renderTimeOrigin;
     self.interactionTime = self.interactionTime < diff ? diff :self.interactionTime;
 }
 
@@ -169,12 +190,13 @@ - (bool) _isViewGroup:(WXComponent *)targetComponent
     return isViewGroup;
 }
 
-- (void)onInstanceCreateFinish
+- (void)onInstanceRenderSuccess:(WXSDKInstance*) instance;
 {
     if (self.hasRecordFsRenderTimeByPosition) {
         return;
     }
     self.newFsRenderTime = CACurrentMediaTime()*1000 - self.renderTimeOrigin;
+    [instance.apmInstance onStage:KEY_PAGE_STAGES_NEW_FSRENDER];
 }
 
 @end
diff --git a/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m b/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
index 169047004c..02adbe6d3a 100644
--- a/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
+++ b/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
@@ -43,13 +43,19 @@ + (void)commitCriticalExceptionRT:(NSString *)instanceId errCode:(NSString *)err
             instanceIdCommit = instanceId;
             instance = [WXSDKManager instanceForID:instanceId];
             if(instance){
-                bundleUrlCommit = instance.pageName?:([instance.scriptURL absoluteString]?:bundleUrlCommit);
-               
+                bundleUrlCommit = instance.pageName?:instance.scriptURL.absoluteString;
+                if(nil == bundleUrlCommit || [@"" isEqualToString:bundleUrlCommit]){
+                    bundleUrlCommit = @"instanceUnSetPageNameOrUrl";
+                }
+
                 if (instance.containerInfo && instance.containerInfo.count >0) {
                     [extInfo addEntriesFromDictionary:instance.containerInfo];
                 }
+                if (nil != instance.viewController) {
+                    [extInfo setObject:NSStringFromClass(instance.viewController.class)?:@"unKnowVCName" forKey:KEY_PAGE_PROPERTIES_CONTAINER_NAME];
+                }
                 [extInfo setObject:[self _convertInstanceStageToStr:instance] forKey:@"wxStageList"];
-                [extInfo setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" forKey:@"wxPageName"];
+                [extInfo setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" forKey:@"wxBundlePageName"];
                 NSString* bundleTemplateCommit = @"has recycle";
                 if (nil != instance.bundleTemplate) {
                     NSUInteger strLength = instance.bundleTemplate.length;
diff --git a/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m b/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m
index 87eeb72162..e4866dda04 100644
--- a/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m
+++ b/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m
@@ -236,6 +236,11 @@ + (void)commitPerformanceWithDict:(NSMutableDictionary *)commitDict instance:(WX
         if (appMonitor && [appMonitor respondsToSelector:@selector(commitAppMonitorArgs:)]){
             [appMonitor commitAppMonitorArgs:commitDict];
         }
+        long oldFSRenderCostTime = [commitDict[FSRENDERTIME] longValue];
+        if (oldFSRenderCostTime > 0) {
+            long oldFSRenderTime = instance.performance.renderUnixTimeOrigin + oldFSRenderCostTime;
+            [instance.apmInstance onStageWithTime:KEY_PAGE_STAGES_FSRENDER time:oldFSRenderTime];
+        }
         
         [self printPerformance:commitDict];
         [WXTracingManager commitTracingSummaryInfo:commitDict withInstanceId:instance.instanceId];
diff --git a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h
index e775a461f7..c1a15610c9 100644
--- a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h
+++ b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h
@@ -29,6 +29,7 @@ extern NSString* const KEY_PAGE_STAGES_LOAD_BUNDLE_START;
 extern NSString* const KEY_PAGE_STAGES_LOAD_BUNDLE_END;
 extern NSString* const KEY_PAGE_STAGES_CREATE_FINISH;
 extern NSString* const KEY_PAGE_STAGES_FSRENDER;
+extern NSString* const KEY_PAGE_STAGES_NEW_FSRENDER;
 extern NSString* const KEY_PAGE_STAGES_INTERACTION;
 extern NSString* const KEY_PAGE_STAGES_DESTROY;
 
@@ -92,6 +93,7 @@ extern NSString* const VALUE_ERROR_CODE_DEFAULT;
 
 - (void) onEvent:(NSString *)name withValue:(id)value;
 - (void) onStage:(NSString *)name;
+- (void) onStageWithTime:(NSString*)name time:(long)unixTime;
 - (void) setProperty:(NSString *)name withValue:(id)value;
 - (void) setStatistic:(NSString *)name withValue:(double)value;
 
@@ -99,7 +101,6 @@ extern NSString* const VALUE_ERROR_CODE_DEFAULT;
 
 - (void) startRecord:(NSString*) instanceId;
 - (void) endRecord;
-- (void) arriveFSRenderTime;
 - (void) updateFSDiffStats:(NSString *)name withDiffValue:(double)diff;
 - (void) updateDiffStats:(NSString *)name withDiffValue:(double)diff;
 - (void) updateMaxStats:(NSString *)name curMaxValue:(double)maxValue;
diff --git a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m
index 281da83ae0..5959143e59 100644
--- a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m
@@ -9,6 +9,7 @@
 #import "WXSDKEngine.h"
 #import "WXSDKError.h"
 #import "WXExceptionUtils.h"
+#import "WXSDKInstance_performance.h"
 
 
 #pragma mark - const static string
@@ -39,6 +40,7 @@
 NSString* const KEY_PAGE_STAGES_LOAD_BUNDLE_END  = @"wxEndLoadBundle";
 NSString* const KEY_PAGE_STAGES_CREATE_FINISH = @"wxJSBundleCreateFinish";
 NSString* const KEY_PAGE_STAGES_FSRENDER  = @"wxFsRender";
+NSString* const KEY_PAGE_STAGES_NEW_FSRENDER = @"wxNewFsRender";
 NSString* const KEY_PAGE_STAGES_INTERACTION  = @"wxInteraction";
 NSString* const KEY_PAGE_STAGES_DESTROY  = @"wxDestroy";
 
@@ -90,6 +92,7 @@ @interface WXApmForInstance ()
     BOOL _isRecord;
     BOOL _isEnd;
     NSDictionary* _responseHeader;
+    BOOL _hasRecordInteractionTime;
 }
 
 @property (nonatomic,strong) id<WXApmProtocol> apmProtocolInstance;
@@ -131,11 +134,21 @@ - (void) onStage:(NSString *)name
     if (nil == _apmProtocolInstance || _isEnd) {
         return;
     }
-    long time = [WXUtility getUnixFixTimeMillis];
-    [self.apmProtocolInstance onStage:name withValue:time];
+    [self onStageWithTime:name time:[WXUtility getUnixFixTimeMillis]];
+}
+
+- (void) onStageWithTime:(NSString*)name time:(long)unixTime
+{
+    if (nil == _apmProtocolInstance || _isEnd) {
+        return;
+    }
+    if ([KEY_PAGE_STAGES_INTERACTION isEqualToString:name]) {
+        _hasRecordInteractionTime = YES;
+    }
+    [self.apmProtocolInstance onStage:name withValue:unixTime];
     __weak typeof(self) weakSelf = self;
     WXPerformBlockOnComponentThread(^{
-        [weakSelf.recordStageMap setObject:@(time) forKey:name];
+        [weakSelf.recordStageMap setObject:@(unixTime) forKey:name];
     });
 }
 
@@ -166,7 +179,6 @@ - (void) startRecord:(NSString*) instanceId
     _instanceId = instanceId;
     
     [self.apmProtocolInstance onStart:instanceId topic:WEEX_PAGE_TOPIC];
-    [self onStage:KEY_PAGE_STAGES_START];
     WXSDKInstance* instance = [WXSDKManager instanceForID:instanceId];
     if (nil != instance) {
         for (NSString* key in instance.continerInfo) {
@@ -201,22 +213,17 @@ - (void) endRecord;
         return;
     }
     _isEnd = YES;
+    WXSDKInstance* instance = [WXSDKManager instanceForID:self.instanceId];
+    if (!_hasRecordInteractionTime && nil!= instance.performance && instance.performance.lastRealInteractionTime > 0) {
+        [self onStageWithTime:KEY_PAGE_STAGES_INTERACTION time:instance.performance.lastRealInteractionTime];
+        _hasRecordInteractionTime = YES;
+    }
     
     [self onStage:KEY_PAGE_STAGES_DESTROY];
     [self.apmProtocolInstance onEnd];
     [self _checkScreenEmptyAndReport];
 }
 
-- (void) arriveFSRenderTime
-{
-    if (nil == _apmProtocolInstance || _isFSEnd) {
-        return;
-    }
-    self.isFSEnd = true;
-    
-    [self onStage:KEY_PAGE_STAGES_FSRENDER];
-}
-
 - (void) updateFSDiffStats:(NSString *)name withDiffValue:(double)diff
 {
     if (nil == _apmProtocolInstance || _isFSEnd) {


 

----------------------------------------------------------------
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