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

Commit

Permalink
[WEEX-661][iOS] update for weex dev-tool
Browse files Browse the repository at this point in the history
 - transfer peformance info to devtool
 - show interactionView
 - add log switch of jsengin/jsfm/weexcore ,to analyze interactionTime
  • Loading branch information
lucky-chen committed Nov 13, 2018
1 parent 3926912 commit 7a17b4d
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 182 deletions.
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ namespace WeexCore
+ (void)registerComponentAffineType:(NSString *)type asType:(NSString *)baseType;

+ (BOOL)isComponentAffineType:(NSString *)type asType:(NSString *)baseType;
+ (void)registercCoreEnv:(NSString*)key withValue:(NSString*)value;

@end

Expand Down
5 changes: 5 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1178,4 +1178,9 @@ + (void)callUpdateFinish:(NSString*)pageId
WeexCore::WeexCoreManager::Instance()->script_bridge()->core_side()->UpdateFinish([pageId UTF8String] ?: "", nullptr, 0, nullptr, 0);
}

+ (void)registercCoreEnv:(NSString*)key withValue:(NSString*)value
{
WeexCore::WeexCoreManager::Instance()->getPlatformBridge()->core_side()->RegisterCoreEnv([key UTF8String]?:"", [value UTF8String]?:"");
}

@end
12 changes: 10 additions & 2 deletions ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#import "WXAppMonitorProtocol.h"
#import "JSContext+Weex.h"
#import "WXCoreBridge.h"
#import "WXAnalyzerCenter.h"

#import <dlfcn.h>

Expand Down Expand Up @@ -200,8 +201,15 @@ - (void)registerCallAddElement:(WXJSCallAddElement)callAddElement
NSString *parentRef = [ref toString];
NSInteger insertIndex = [[index toNumber] integerValue];
WXLogDebug(@"callAddElement...%@, %@, %@, %ld", instanceIdString, parentRef, componentData, (long)insertIndex);

return [JSValue valueWithInt32:(int32_t)callAddElement(instanceIdString, parentRef, componentData, insertIndex) inContext:[JSContext currentContext]];
if (WXAnalyzerCenter.isInteractionLogOpen) {
WXLogDebug(@"wxInteractionAnalyzer : [jsengin][addElementStart],%@,%@",instanceIdString,componentData[@"ref"]);
}
JSValue * result = [JSValue valueWithInt32:(int32_t)callAddElement(instanceIdString, parentRef, componentData, insertIndex) inContext:[JSContext currentContext]];

if (WXAnalyzerCenter.isInteractionLogOpen) {
WXLogDebug(@"wxInteractionAnalyzer : [jsengin][addElementEnd],%@,%@",instanceIdString,componentData[@"ref"]);
}
return result;
};

_jsContext[@"callAddElement"] = callAddElementBlock;
Expand Down
10 changes: 10 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "WXSDKInstance_private.h"
#import "WXHandlerFactory.h"
#import "WXValidateProtocol.h"
#import "WXAnalyzerCenter.h"

@implementation WXModuleMethod

Expand All @@ -46,6 +47,9 @@ - (instancetype)initWithModuleName:(NSString *)moduleName

- (NSInvocation *)invoke
{
if ([WXAnalyzerCenter isInteractionLogOpen]) {
WXLogDebug(@"wxInteractionAnalyzer : [client][callnativemodulestart],%@,%@,%@",self.instance.instanceId,self.moduleName,self.methodName);
}
if (self.instance.needValidate) {
id<WXValidateProtocol> validateHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)];
if (validateHandler) {
Expand Down Expand Up @@ -103,6 +107,9 @@ - (NSInvocation *)invoke

if (isSync) {
[invocation invoke];
if ([WXAnalyzerCenter isInteractionLogOpen]) {
WXLogDebug(@"wxInteractionAnalyzer : [client][callnativemoduleEnd],%@,%@,%@",self.instance.instanceId,self.moduleName,self.methodName);
}
return invocation;
} else {
[self _dispatchInvocation:invocation moduleInstance:moduleInstance];
Expand Down Expand Up @@ -130,6 +137,9 @@ - (void)_dispatchInvocation:(NSInvocation *)invocation moduleInstance:(id<WXModu
// dispatch to user specified queue or thread, default is main thread
dispatch_block_t dispatchBlock = ^ (){
[invocation invoke];
if ([WXAnalyzerCenter isInteractionLogOpen]) {
WXLogDebug(@"wxInteractionAnalyzer : [client][callnativemoduleEnd],%@,%@,%@",self.instance.instanceId,self.moduleName,self.methodName);
}
};

NSThread *targetThread = nil;
Expand Down
9 changes: 9 additions & 0 deletions ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#import "WXComponent+Layout.h"
#import "WXCoreBridge.h"
#import "WXComponent_performance.h"
#import "WXAnalyzerCenter.h"

static NSThread *WXComponentThread;

Expand Down Expand Up @@ -272,6 +273,10 @@ - (void)addComponent:(NSString*)ref
WXLogWarning(@"addComponent,superRef from js never exit ! check JS action, supRef:%@", parentRef);
return;
}
if([WXAnalyzerCenter isInteractionLogOpen]){
WXLogDebug(@"wxInteractionAnalyzer: [client][addElementStart]%@,%@,%@",supercomponent.weexInstance.instanceId,type,ref);
}

supercomponent.weexInstance.apmInstance.hasAddView = YES;

WXComponent *component = [self _buildComponent:ref type:type supercomponent:supercomponent styles:styles attributes:attributes events:events renderObject:renderObject];
Expand Down Expand Up @@ -314,6 +319,7 @@ - (void)addComponent:(NSString*)ref
}

[self recordMaximumVirtualDom:component];
[component.weexInstance.apmInstance updateMaxStats:KEY_PAGE_STATS_MAX_COMPONENT_NUM curMaxValue:[_indexDict count]];

if (!component->_isTemplate) {
__weak typeof(self) weakSelf = self;
Expand All @@ -328,6 +334,9 @@ - (void)addComponent:(NSString*)ref
[WXTracingManager startTracingWithInstanceId:strongSelf.weexInstance.instanceId ref:ref className:nil name:type phase:WXTracingEnd functionName:@"addElement" options:@{@"threadName":WXTUIThread}];
}];
}
if([WXAnalyzerCenter isInteractionLogOpen]){
WXLogDebug(@"wxInteractionAnalyzer: [client][addElementEnd]%@,%@,%@",supercomponent.weexInstance.instanceId,type,ref);
}
}

- (void)moveComponent:(NSString *)ref toSuper:(NSString *)superRef atIndex:(NSInteger)index
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ - (void)setFrame:(CGRect)frame
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
if (screenHeight>0) {
CGFloat pageRatio = frame.size.height/screenHeight *100;
self.apmInstance.wxPageRatio = pageRatio>100?100:pageRatio;
self.apmInstance.pageRatio = pageRatio>100?100:pageRatio;
}
WXPerformBlockOnMainThread(^{
if (_rootView) {
Expand Down
12 changes: 4 additions & 8 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "WXCellComponent.h"
#import "WXImageComponent.h"
#import "WXUtility.h"
#import "WXAnalyzerCenter+Transfer.h"

@interface WXPerformance()
@property (nonatomic, assign) bool hasRecordFsRenderTimeByPosition;
Expand Down Expand Up @@ -112,21 +113,16 @@ - (void) _handleRenderTime:(WXComponent*)targetComponent withModifyTime:(double)
return;
}

#ifdef DEBUG
WXLogDebug(@"onElementChange _-> size, count :%f,inScreen:%d, type:%@,attr:%@",
self.interactionAddCountRecord,
inScreen,
targetComponent.type,
targetComponent.attributes
);
#endif
if (!targetComponent.weexInstance.apmInstance.hasRecordFirstInterationView) {
targetComponent.weexInstance.apmInstance.hasRecordFirstInterationView = YES;
[targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_FIRST_INTERACTION_VIEW];
}
[WXAnalyzerCenter transferInteractionInfo:targetComponent];
[targetComponent.weexInstance.apmInstance onStage:KEY_PAGE_STAGES_INTERACTION];
self.interactionLimitAddOpCount++;
self.interactionAddCount = self.interactionAddCountRecord;
[targetComponent.weexInstance.apmInstance updateMaxStats:KEY_PAGE_STATS_I_SCREEN_VIEW_COUNT curMaxValue:self.interactionLimitAddOpCount];
[targetComponent.weexInstance.apmInstance updateMaxStats:KEY_PAGE_STATS_I_ALL_VIEW_COUNT curMaxValue:self.interactionAddCount];
self.interactionTime = self.interactionTime < diff ? diff :self.interactionTime;
}

Expand Down
6 changes: 2 additions & 4 deletions ios/sdk/WeexSDK/Sources/Monitor/WXAnalyzerCenter+Transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@

@interface WXAnalyzerCenter (Transfer)

+(void) transDataOnState:(CommitState) timeState withInstaneId:(NSString *)instanceId data:(NSDictionary *)data ;

+ (void) transferPerformance:(NSString*)instanceId withType:(NSString*) type andKey:(NSString*) key andValue:(id)value;
+ (void) transferInteractionInfo:(WXComponent*)targetComponent;
+ (void) transErrorInfo:(WXJSExceptionInfo *)errorInfo;

+ (BOOL) needTransfer;

@end
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/Monitor/WXAnalyzerCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
+(void) setOpen:(BOOL)isOpen;
+(BOOL) isOpen;

+(void) switchInteractionLog:(BOOL) isOpen;
+(BOOL) isInteractionLogOpen;

@end
Loading

0 comments on commit 7a17b4d

Please sign in to comment.