[ https://issues.apache.org/jira/browse/WEEX-583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16588499#comment-16588499 ]
ASF GitHub Bot commented on WEEX-583: ------------------------------------- cxfeng1 closed pull request #1462: [WEEX-583][iOS] add fields for monitor URL: https://github.com/apache/incubator-weex/pull/1462 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/playground/WeexDemo/extend/handler/WXApmImpl.m b/ios/playground/WeexDemo/extend/handler/WXApmImpl.m index 4bb195d436..72cc0da647 100644 --- a/ios/playground/WeexDemo/extend/handler/WXApmImpl.m +++ b/ios/playground/WeexDemo/extend/handler/WXApmImpl.m @@ -1,6 +1,7 @@ #import "WXApmImpl.h" #import "WXUtility.h" +#import "WXComponentManager.h" @interface WXApmImpl() @property(nonatomic,strong) NSMutableDictionary<NSString*,NSNumber*>* stageMap; @@ -32,27 +33,43 @@ - (void) onStart:(NSString *)instanceId topic:(NSString *)topic - (void) onEnd { - [self _printApmInfo]; + __weak typeof(self) weakSelf = self; + WXPerformBlockOnComponentThread(^{ + [weakSelf _printApmInfo]; + }); + } - (void) onEvent:(NSString *)name withValue:(id)value { - [self.eventMap setObject:value forKey:name]; + __weak typeof(self) weakSelf = self; + WXPerformBlockOnComponentThread(^{ + [weakSelf.eventMap setObject:value forKey:name]; + }); } - (void) onStage:(NSString *)name withValue:(long)timestamp { - [self.stageMap setObject:[NSNumber numberWithLong:timestamp] forKey:name]; + __weak typeof(self) weakSelf = self; + WXPerformBlockOnComponentThread(^{ + [weakSelf.stageMap setObject:[NSNumber numberWithLong:timestamp] forKey:name]; + }); } - (void) addProperty:(NSString *)name withValue:(id)value { - [self.propertyMap setObject:value forKey:name]; + __weak typeof(self) weakSelf = self; + WXPerformBlockOnComponentThread(^{ + [weakSelf.propertyMap setObject:value forKey:name]; + }); } - (void) addStatistic:(NSString *)name withValue:(double)value { - [self.statisticMap setObject:[NSNumber numberWithDouble:value] forKey:name]; + __weak typeof(self) weakSelf = self; + WXPerformBlockOnComponentThread(^{ + [weakSelf.statisticMap setObject:[NSNumber numberWithDouble:value] forKey:name]; + }); } - (void) addBiz:(NSString *)bizID withValue:(NSDictionary *)properties diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m index 9b794c0e48..7497dabe5a 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m @@ -337,6 +337,7 @@ - (void)registerGlobalFunctions // Temporary here , in order to improve performance, will be refactored next version. WXSDKInstance *instance = [WXSDKManager instanceForID:instanceId]; + [instance.apmInstance onStage:KEY_PAGE_STAGES_CREATE_FINISH]; if(![weakSelf checkInstance:instance]) { return -1; @@ -526,7 +527,6 @@ - (void)createInstance:(NSString *)instanceIdString bundleType = [self _pareJSBundleType:instanceIdString jsBundleString:jsBundleString]; // bundleType can be Vue, Rax and the new framework. } if (bundleType&&shoudMultiContext) { - [sdkInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_USE_MULTI_CONTEXT withValue:[NSNumber numberWithBool:true]]; [sdkInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_BUNDLE_TYPE withValue:bundleType]; NSMutableDictionary *newOptions = [options mutableCopy]; if (!options) { @@ -608,8 +608,7 @@ - (void)createInstance:(NSString *)instanceIdString } } else { - [sdkInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_USE_MULTI_CONTEXT withValue:[NSNumber numberWithBool:false]]; - [sdkInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_BUNDLE_TYPE withValue:@"singleContextUnkonwType"]; + [sdkInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_BUNDLE_TYPE withValue:@"other"]; if (data){ args = @[instanceIdString, jsBundleString, options ?: @{}, data]; } else { diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEmbedComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXEmbedComponent.m index 4821d1bbd2..0a99d890a1 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXEmbedComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXEmbedComponent.m @@ -25,6 +25,7 @@ #import "WXSDKManager.h" #import "WXConvert.h" #import "WXUtility.h" +#import "WXApmForInstance.h" @interface WXEmbedComponent () @@ -144,7 +145,9 @@ - (void)_renderWithURL:(NSURL *)sourceURL } [_embedInstance renderWithURL:[NSURL URLWithString:newURL] options:@{@"bundleUrl":[sourceURL absoluteString]} data:nil]; - + [_embedInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_INSTANCE_TYPE withValue:@"embed"]; + [_embedInstance.apmInstance setProperty:KEY_PAGE_PROPERTIES_PARENT_PAGE withValue:_embedInstance.parentInstance.pageName]; + [self.weexInstance.apmInstance updateDiffStats:KEY_PAGE_STATS_EMBED_COUNT withDiffValue:1]; __weak typeof(self) weakSelf = self; _embedInstance.onCreate = ^(UIView *view) { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m index 1beb2cb285..a344a1a5d4 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m @@ -69,6 +69,7 @@ @interface WXImageComponent () @property (nonatomic) BOOL imageLoadEvent; @property (nonatomic) BOOL imageDownloadFinish; @property (nonatomic) BOOL downloadImageWithURL; +@property (nonatomic ,strong) NSString* preUrl; @end @@ -425,6 +426,13 @@ - (void)updateImage self.weexInstance.performance.imgWrongSizeNum++; [self.weexInstance.apmInstance updateDiffStats:KEY_PAGE_STATS_WRONG_IMG_SIZE_COUNT withDiffValue:1]; } + NSString* curUrl = imageURL.absoluteString; + if (![curUrl isEqualToString:self.preUrl]) { + self.preUrl = curUrl; + if (image.size.width >1080 && image.size.height > 1920) { + [self.weexInstance.apmInstance updateDiffStats:KEY_PAGE_STATS_LARGE_IMG_COUNT withDiffValue:1]; + } + } } }]; } else { diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index 30b717b8d5..e911d47855 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -245,6 +245,10 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString WXLogError(@"Fail to find instance!"); return; } + + //some case , with out render (url) + [self.apmInstance startRecord:self.instanceId]; + self.performance.renderTimeOrigin = CACurrentMediaTime()*1000; [self.apmInstance onStage:KEY_PAGE_STAGES_RENDER_ORGIGIN]; diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m index 9aa6807fa3..ab1e1b9cfb 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m @@ -82,6 +82,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]; } UIView *root = targetComponent.weexInstance.rootView; @@ -110,6 +111,7 @@ - (void) _handleRenderTime:(WXComponent*)targetComponent withModifyTime:(double) NSStringFromCGRect(targetComponent.weexInstance.rootView.frame) ); #endif + [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_INTERACTION]; self.interactionLimitAddOpCount++; self.interactionAddCount = self.interactionAddCountRecord; self.interactionTime = self.interactionTime < diff ? diff :self.interactionTime; diff --git a/ios/sdk/WeexSDK/Sources/Module/WXTimerModule.m b/ios/sdk/WeexSDK/Sources/Module/WXTimerModule.m index be156baf3c..cc399ac533 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXTimerModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXTimerModule.m @@ -46,6 +46,7 @@ - (instancetype)initWithCallback:(NSString *)callbackID shouldRepeat:(BOOL)shoul if (weexInstance && !weexInstance.isJSCreateFinish) { weexInstance.performance.timerNum++; + [weexInstance.apmInstance updateFSDiffStats:KEY_PAGE_STATS_FS_TIMER_NUM withDiffValue:1]; } } diff --git a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h index 466079be22..15748444a6 100644 --- a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h +++ b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h @@ -6,16 +6,18 @@ extern NSString* const WEEX_PAGE_TOPIC; /************** properties *****************/ extern NSString* const KEY_PROPERTIES_ERROR_CODE; -extern NSString* const KEY_PAGE_PROPERTIES_LAUNCH_ID; extern NSString* const KEY_PAGE_PROPERTIES_BIZ_ID; +extern NSString* const KEY_PAGE_PROPERTIES_BUBDLE_URL; extern NSString* const KEY_PAGE_PROPERTIES_JSLIB_VERSION; extern NSString* const KEY_PAGE_PROPERTIES_WEEX_VERSION; extern NSString* const KEY_PAGE_PROPERTIES_REQUEST_TYPE; -extern NSString* const KEY_PAGE_PROPERTIES_REQUEST_TYPE; -extern NSString* const KEY_PAGE_PROPERTIES_NET_TYPE; -extern NSString* const KEY_PAGE_PROPERTIES_CACHE_TYPE; -extern NSString* const KEY_PAGE_PROPERTIES_USE_MULTI_CONTEXT; +extern NSString* const KEY_PAGE_PROPERTIES_Z_CACHE_INFO; +extern NSString* const KEY_PAGE_PROPERTIES_JS_FM_INIT; extern NSString* const KEY_PAGE_PROPERTIES_BUNDLE_TYPE; +extern NSString* const KEY_PAGE_PROPERTIES_CONTAINER_NAME; +extern NSString* const KEY_PAGE_PROPERTIES_INSTANCE_TYPE; +extern NSString* const KEY_PAGE_PROPERTIES_PARENT_PAGE; + ///************** stages *****************/ extern NSString* const KEY_PAGE_STAGES_START; @@ -24,6 +26,7 @@ extern NSString* const KEY_PAGE_STAGES_DOWN_BUNDLE_END; extern NSString* const KEY_PAGE_STAGES_RENDER_ORGIGIN; 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_INTERACTION; extern NSString* const KEY_PAGE_STAGES_DESTROY; @@ -42,6 +45,8 @@ extern NSString* const KEY_PAGE_STATS_SCROLLER_NUM; extern NSString* const KEY_PAGE_STATS_CELL_EXCEED_NUM; extern NSString* const KEY_PAGE_STATS_CELL_UN_RE_USE_NUM; extern NSString* const KEY_PAGE_STATS_CELL_DATA_UN_RECYCLE_NUM; +extern NSString* const KEY_PAGE_STATS_EMBED_COUNT; +extern NSString* const KEY_PAGE_STATS_LARGE_IMG_COUNT; extern NSString* const KEY_PAGE_STATS_MAX_DEEP_VIEW; extern NSString* const KEY_PAGE_STATS_MAX_DEEP_DOM; @@ -72,6 +77,7 @@ extern NSString* const VALUE_ERROR_CODE_DEFAULT; @interface WXApmForInstance : NSObject @property (nonatomic, assign) bool isFSEnd; +@property (nonatomic, assign) bool isStartRecord; #pragma mark - basic method diff --git a/ios/sdk/WeexSDK/Sources/Performance/WXInstanceApm.m b/ios/sdk/WeexSDK/Sources/Performance/WXInstanceApm.m index ab3e914e03..3264a727ff 100644 --- a/ios/sdk/WeexSDK/Sources/Performance/WXInstanceApm.m +++ b/ios/sdk/WeexSDK/Sources/Performance/WXInstanceApm.m @@ -12,15 +12,18 @@ /************** properties *****************/ NSString* const KEY_PROPERTIES_ERROR_CODE = @"wxErrorCode"; -NSString* const KEY_PAGE_PROPERTIES_LAUNCH_ID = @"wxLaunchId"; NSString* const KEY_PAGE_PROPERTIES_BIZ_ID = @"wxBizID"; +NSString* const KEY_PAGE_PROPERTIES_BUBDLE_URL = @"wxBundleUrl"; NSString* const KEY_PAGE_PROPERTIES_JSLIB_VERSION = @"wxJSLibVersion"; NSString* const KEY_PAGE_PROPERTIES_WEEX_VERSION = @"wxSDKVersion"; NSString* const KEY_PAGE_PROPERTIES_REQUEST_TYPE = @"wxRequestType"; -NSString* const KEY_PAGE_PROPERTIES_NET_TYPE = @"wxNetType"; -NSString* const KEY_PAGE_PROPERTIES_CACHE_TYPE = @"wxCacheType"; -NSString* const KEY_PAGE_PROPERTIES_USE_MULTI_CONTEXT = @"wxUseMultiContext"; +NSString* const KEY_PAGE_PROPERTIES_Z_CACHE_INFO = @"wxZCacheInfo"; +NSString* const KEY_PAGE_PROPERTIES_JS_FM_INIT = @"wxJsFrameworkInit"; NSString* const KEY_PAGE_PROPERTIES_BUNDLE_TYPE = @"wxBundleType"; +NSString* const KEY_PAGE_PROPERTIES_CONTAINER_NAME = @"wxContainerName"; +NSString* const KEY_PAGE_PROPERTIES_INSTANCE_TYPE = @"wxInstanceType"; +NSString* const KEY_PAGE_PROPERTIES_PARENT_PAGE = @"wxParentPage"; + ///************** stages *****************/ NSString* const KEY_PAGE_STAGES_START = @"wxRecordStart"; @@ -29,6 +32,7 @@ NSString* const KEY_PAGE_STAGES_RENDER_ORGIGIN = @"wxRenderTimeOrigin"; NSString* const KEY_PAGE_STAGES_LOAD_BUNDLE_START = @"wxStartLoadBundle"; 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_INTERACTION = @"wxInteraction"; NSString* const KEY_PAGE_STAGES_DESTROY = @"wxDestroy"; @@ -47,6 +51,8 @@ NSString* const KEY_PAGE_STATS_CELL_EXCEED_NUM = @"wxCellExceedNum"; NSString* const KEY_PAGE_STATS_CELL_UN_RE_USE_NUM = @"wxCellUnReUseCount"; NSString* const KEY_PAGE_STATS_CELL_DATA_UN_RECYCLE_NUM = @"wxCellDataUnRecycleCount"; +NSString* const KEY_PAGE_STATS_EMBED_COUNT=@"wxEmbedCount"; +NSString* const KEY_PAGE_STATS_LARGE_IMG_COUNT=@"wxLargeImgMaxCount"; NSString* const KEY_PAGE_STATS_MAX_DEEP_VIEW = @"wxMaxDeepViewLayer"; NSString* const KEY_PAGE_STATS_MAX_DEEP_DOM = @"wxMaxDeepVDomLayer"; @@ -105,7 +111,7 @@ - (void) onStage:(NSString *)name if (nil == _apmProtocolInstance) { return; } - [self.apmProtocolInstance onStage:name withValue:[WXUtility getUnixCurrentTimeMillis]]; + [self.apmProtocolInstance onStage:name withValue:[WXUtility getUnixFixTimeMillis]]; } - (void) setProperty:(NSString *)name withValue:(id)value @@ -128,9 +134,10 @@ - (void) setStatistic:(NSString *)name withValue:(double)value - (void) startRecord:(NSString*) instanceId { - if (nil == _apmProtocolInstance) { + if (nil == _apmProtocolInstance || self.isStartRecord) { return; } + self.isStartRecord = YES; _instanceId = instanceId; [self.apmProtocolInstance onStart:instanceId topic:WEEX_PAGE_TOPIC]; @@ -144,8 +151,15 @@ - (void) startRecord:(NSString*) instanceId } NSString* pageUrl = instance.scriptURL.absoluteString; pageUrl = nil == pageUrl || [@"" isEqualToString:pageUrl]?@"unKnowUrl":pageUrl; - - [self setProperty:KEY_PAGE_PROPERTIES_BIZ_ID withValue:pageUrl]; + NSString* pageName = instance.pageName?:@"unKnowPageName"; + NSString* vcName = @"unKnowVCName"; + if (nil != instance.viewController) { + vcName = NSStringFromClass(instance.viewController.class); + } + [self setProperty:KEY_PAGE_PROPERTIES_CONTAINER_NAME withValue:vcName]; + [self setProperty:KEY_PAGE_PROPERTIES_INSTANCE_TYPE withValue:@"page"]; + [self setProperty:KEY_PAGE_PROPERTIES_BIZ_ID withValue:pageName]; + [self setProperty:KEY_PAGE_PROPERTIES_BUBDLE_URL withValue:pageUrl]; [self setProperty:KEY_PROPERTIES_ERROR_CODE withValue:VALUE_ERROR_CODE_DEFAULT]; [self setProperty:KEY_PAGE_PROPERTIES_JSLIB_VERSION withValue:[WXAppConfiguration JSFrameworkVersion]]; [self setProperty:KEY_PAGE_PROPERTIES_WEEX_VERSION withValue:WX_SDK_VERSION]; @@ -221,20 +235,15 @@ - (void) updateExtInfo:(NSDictionary*) extInfo [self setProperty:KEY_PAGE_PROPERTIES_REQUEST_TYPE withValue:wxRequestType]; } - id wxNetType = [extInfo objectForKey:KEY_PAGE_PROPERTIES_NET_TYPE]; - if (nil != wxRequestType && [wxNetType isKindOfClass: NSString.class]) { - [self setProperty:KEY_PAGE_PROPERTIES_NET_TYPE withValue:wxRequestType]; - } - - id wxCacheType = [extInfo objectForKey:KEY_PAGE_PROPERTIES_CACHE_TYPE]; - if (nil != wxCacheType && [wxCacheType isKindOfClass: NSString.class]) { - [self setProperty:KEY_PAGE_PROPERTIES_CACHE_TYPE withValue:wxCacheType]; - } - id wxNetLibDownBundleTime = [extInfo objectForKey:KEY_PAGE_STATS_ACTUAL_DOWNLOAD_TIME]; if (nil != wxNetLibDownBundleTime && [wxNetLibDownBundleTime isKindOfClass: NSNumber.class]) { double value = ((NSNumber *)wxNetLibDownBundleTime).doubleValue; - [self setStatistic:KEY_PAGE_PROPERTIES_CACHE_TYPE withValue:value]; + [self setStatistic:KEY_PAGE_STATS_ACTUAL_DOWNLOAD_TIME withValue:value]; + } + + id wxZcacheInfo = [extInfo objectForKey:KEY_PAGE_PROPERTIES_Z_CACHE_INFO]; + if (nil !=wxZcacheInfo && [wxZcacheInfo isKindOfClass: NSString.class]) { + [self setProperty:KEY_PAGE_PROPERTIES_Z_CACHE_INFO withValue:wxZcacheInfo]; } } diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h index a7a7abf5dd..796e400c9e 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h +++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h @@ -493,6 +493,6 @@ BOOL WXFloatGreaterThanWithPrecision(CGFloat a,CGFloat b,double precision); + (BOOL)listSectionRowThreadSafe; -+ (long) getUnixCurrentTimeMillis; ++ (long) getUnixFixTimeMillis; @end diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m index d0350551b6..2f13262053 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m @@ -974,9 +974,15 @@ + (NSData *_Nonnull)base64DictToData:(NSDictionary *_Nullable)base64Dict return nil; } -+ (long) getUnixCurrentTimeMillis ++ (long) getUnixFixTimeMillis { - return [[NSDate date] timeIntervalSince1970] * 1000; + static long sInterval; + static dispatch_once_t unixTimeToken; + + dispatch_once(&unixTimeToken, ^{ + sInterval = [[NSDate date] timeIntervalSince1970] * 1000 - CACurrentMediaTime()*1000; + }); + return sInterval+CACurrentMediaTime()*1000; } @end ---------------------------------------------------------------- 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: us...@infra.apache.org > [iOS] 监控字段缺失fix > --------------- > > Key: WEEX-583 > URL: https://issues.apache.org/jira/browse/WEEX-583 > Project: Weex > Issue Type: Bug > Reporter: peihan > Assignee: Adam Feng > Priority: Major > -- This message was sent by Atlassian JIRA (v7.6.3#76005)