From 80419506d96f7f8901f428d40426b25ced454565 Mon Sep 17 00:00:00 2001 From: chen Date: Thu, 20 Sep 2018 22:35:34 +0800 Subject: [PATCH] [WEEX-620][iOS] pageName check and interaction code revert (#1539) * [iOS] before render,check pagename is nil or "",if yes, set pagename order url -> vcname -> "unKnowSet" * [iOS] revert interaction code (revert ignore countDown top10 view) --- .../Sources/Model/WXComponent_performance.h | 22 +++++- ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 29 ++++---- .../Sources/Model/WXSDKInstance_performance.m | 20 +----- .../Sources/Performance/WXApmForInstance.h | 21 +++++- .../Sources/Performance/WXApmForInstance.m | 68 +++++++++++++------ 5 files changed, 103 insertions(+), 57 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h b/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h index 042fd30a1d..17153ee160 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent_performance.h @@ -1,10 +1,26 @@ +/* + * 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. + */ + #import "WXComponent.h" @interface WXComponent() @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 0a96e2d360..0ea6d59223 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -228,12 +228,25 @@ - (void)renderWithURL:(NSURL *)url [self renderWithURL:url options:nil data:nil]; } +- (void)_checkPageName +{ + if (nil == self.pageName || [self.pageName isEqualToString:@""]) { + self.pageName = [self.scriptURL isFileURL] ? self.scriptURL.path.lastPathComponent: self.scriptURL.absoluteString; + } + if (nil == self.pageName || [self.pageName isEqualToString:@""]) { + self.pageName = NSStringFromClass(self.viewController.class)?:@"unkonwPageCauseUnsetNameAndUrlAndVc"; + } +} + - (void)renderWithURL:(NSURL *)url options:(NSDictionary *)options data:(id)data { if (!url) { WXLogError(@"Url must be passed if you use renderWithURL"); return; } + + _scriptURL = url; + [self _checkPageName]; [self.apmInstance startRecord:self.instanceId]; self.apmInstance.isStartRender = YES; @@ -251,7 +264,6 @@ - (void)renderView:(id)source options:(NSDictionary *)options data:(id)data self.needValidate = [[WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)] needValidate:self.scriptURL]; - [self _setPageNameValue:nil]; if ([source isKindOfClass:[NSString class]]) { [self _renderWithMainBundleString:source]; } else if ([source isKindOfClass:[NSData class]]) { @@ -343,6 +355,7 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString } //some case , with out render (url) + [self _checkPageName]; [self.apmInstance startRecord:self.instanceId]; self.apmInstance.isStartRender = YES; @@ -458,18 +471,6 @@ - (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; { @@ -488,8 +489,6 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *) } _options = [newOptions copy]; - [self _setPageNameValue:url]; - request.userAgent = [WXUtility userAgent]; WX_MONITOR_INSTANCE_PERF_START(WXPTJSDownload, self); diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m index dc1987a41c..49da81345e 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m @@ -29,9 +29,6 @@ #import "WXUtility.h" @interface WXPerformance() -{ - NSMutableArray* _mCountDownComponentList; -} @property (nonatomic, assign) bool hasRecordFsRenderTimeByPosition; @property (nonatomic, assign) double interactionAddCountRecord; @end @@ -128,24 +125,9 @@ - (void) _handleRenderTime:(WXComponent*)targetComponent withModifyTime:(double) targetComponent.weexInstance.apmInstance.hasRecordFirstInterationView = YES; [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_FIRST_INTERACTION_VIEW]; } - 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]; + [targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_INTERACTION]; self.interactionLimitAddOpCount++; self.interactionAddCount = self.interactionAddCountRecord; - diff = modifyTime - self.renderTimeOrigin; self.interactionTime = self.interactionTime < diff ? diff :self.interactionTime; } diff --git a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h index c1a15610c9..e92bab0306 100644 --- a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h +++ b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h @@ -1,3 +1,22 @@ +/* + * 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. + */ + #import #import "WXJSExceptionInfo.h" @@ -120,6 +139,6 @@ extern NSString* const VALUE_ERROR_CODE_DEFAULT; - (void) recordErrorMsg:(WXJSExceptionInfo *)exception; - (NSDictionary*) stageDic; -#pragma templateinfo +#pragma mark templateinfo - (NSString*) templateInfo; @end diff --git a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m index 5959143e59..170e03347f 100644 --- a/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m +++ b/ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.m @@ -1,3 +1,22 @@ +/* + * 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. + */ + #import "WXApmForInstance.h" #import "WXApmProtocol.h" #import "WXHandlerFactory.h" @@ -93,6 +112,8 @@ @interface WXApmForInstance () BOOL _isEnd; NSDictionary* _responseHeader; BOOL _hasRecordInteractionTime; + BOOL _hasRecordDownLoadStart; + BOOL _hasRecordDownLoadEnd; } @property (nonatomic,strong) id apmProtocolInstance; @@ -142,6 +163,19 @@ - (void) onStageWithTime:(NSString*)name time:(long)unixTime if (nil == _apmProtocolInstance || _isEnd) { return; } + if ([KEY_PAGE_STAGES_DOWN_BUNDLE_START isEqualToString:name]) { + if (_hasRecordDownLoadStart) { + return; + } + _hasRecordDownLoadStart = YES; + } + if ([KEY_PAGE_STAGES_DOWN_BUNDLE_END isEqualToString:name]) { + if (_hasRecordDownLoadEnd) { + return; + } + _hasRecordDownLoadEnd = YES; + } + if ([KEY_PAGE_STAGES_INTERACTION isEqualToString:name]) { _hasRecordInteractionTime = YES; } @@ -175,30 +209,26 @@ - (void) startRecord:(NSString*) instanceId if (nil == _apmProtocolInstance || _isRecord) { return; } - _isRecord = YES; - _instanceId = instanceId; - - [self.apmProtocolInstance onStart:instanceId topic:WEEX_PAGE_TOPIC]; WXSDKInstance* instance = [WXSDKManager instanceForID:instanceId]; - if (nil != instance) { - for (NSString* key in instance.continerInfo) { - id value = [instance.continerInfo objectForKey:key]; - [self setProperty:key withValue:value]; - } + if (nil == instance) { + return; } - NSString* pageUrl = instance.scriptURL.absoluteString; - pageUrl = nil == pageUrl || [@"" isEqualToString:pageUrl]?@"unKnowUrl":pageUrl; - NSString* pageName = instance.pageName?:@"unKnowPageName"; - NSString* vcName = @"unKnowVCName"; - if (nil != instance.viewController) { - vcName = NSStringFromClass(instance.viewController.class); + + _isRecord = YES; + + + [self.apmProtocolInstance onStart:instance.instanceId topic:WEEX_PAGE_TOPIC]; + for (NSString* key in instance.continerInfo) { + id value = [instance.continerInfo objectForKey:key]; + [self setProperty:key withValue:value]; } - [self setProperty:KEY_PAGE_PROPERTIES_CONTAINER_NAME withValue:vcName]; + + [self setProperty:KEY_PAGE_PROPERTIES_CONTAINER_NAME withValue:NSStringFromClass(instance.viewController.class)?:@"unknownVCName"]; [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_PAGE_PROPERTIES_BIZ_ID withValue: instance.pageName?:@"unknownPageName"]; + [self setProperty:KEY_PAGE_PROPERTIES_BUBDLE_URL withValue:instance.scriptURL.absoluteString?:@"unknownUrl"]; [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_JSLIB_VERSION withValue:[WXAppConfiguration JSFrameworkVersion]?:@"unknownJSFrameworkVersion"]; [self setProperty:KEY_PAGE_PROPERTIES_WEEX_VERSION withValue:WX_SDK_VERSION]; //for apm protocl