+ [ios] add tracing log for chrome devtools
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/565bab61 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/565bab61 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/565bab61 Branch: refs/heads/0.16-dev Commit: 565bab619793192b011a2401486b6360f06e35e3 Parents: 4b80dac Author: é½å±± <sunjjb...@163.com> Authored: Thu Aug 10 12:12:42 2017 +0800 Committer: é½å±± <sunjjb...@163.com> Committed: Thu Aug 10 12:12:42 2017 +0800 ---------------------------------------------------------------------- ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 4 + ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 2 +- ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.h | 4 + ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.m | 10 ++ .../WeexSDK/Sources/Manager/WXTracingManager.h | 17 ++- .../WeexSDK/Sources/Manager/WXTracingManager.m | 107 +++++++++++++++---- ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m | 2 + .../Sources/Protocol/WXTracingProtocol.h | 29 +++++ 8 files changed, 149 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj index 5785c45..0557764 100644 --- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj +++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj @@ -236,6 +236,7 @@ C401945E1E344E8300D19C31 /* WXFloatCompareTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C401945D1E344E8300D19C31 /* WXFloatCompareTests.m */; }; C41E1A971DC1FD15009C7F90 /* WXDatePickerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C41E1A951DC1FD15009C7F90 /* WXDatePickerManager.h */; }; C41E1A981DC1FD15009C7F90 /* WXDatePickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C41E1A961DC1FD15009C7F90 /* WXDatePickerManager.m */; }; + C42E8F9B1F39DF07001EBE9D /* WXTracingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C42E8F991F39DF07001EBE9D /* WXTracingProtocol.h */; }; C43C03E81EC8ACA40044C7FF /* WXPrerenderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; C43C03E91EC8ACA40044C7FF /* WXPrerenderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */; }; C4B3D6D41E6954300013F38D /* WXEditComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = C4B3D6D21E6954300013F38D /* WXEditComponent.h */; }; @@ -800,6 +801,7 @@ C401945D1E344E8300D19C31 /* WXFloatCompareTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXFloatCompareTests.m; sourceTree = "<group>"; }; C41E1A951DC1FD15009C7F90 /* WXDatePickerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXDatePickerManager.h; sourceTree = "<group>"; }; C41E1A961DC1FD15009C7F90 /* WXDatePickerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXDatePickerManager.m; sourceTree = "<group>"; }; + C42E8F991F39DF07001EBE9D /* WXTracingProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXTracingProtocol.h; sourceTree = "<group>"; }; C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXPrerenderManager.h; sourceTree = "<group>"; }; C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPrerenderManager.m; sourceTree = "<group>"; }; C4B3D6D21E6954300013F38D /* WXEditComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXEditComponent.h; sourceTree = "<group>"; }; @@ -1266,6 +1268,7 @@ 74EF31A91DE58AE600667A07 /* WXURLRewriteProtocol.h */, 042013AC1E66CD6A001FC79C /* WXValidateProtocol.h */, DC6836E51EBB12B200AD2D84 /* WXConfigCenterProtocol.h */, + C42E8F991F39DF07001EBE9D /* WXTracingProtocol.h */, ); path = Protocol; sourceTree = "<group>"; @@ -1525,6 +1528,7 @@ DCA0EF641D6EED6F00CB18B9 /* WXGlobalEventModule.h in Headers */, 2A837AB21CD9DE9200AEDF03 /* WXLoadingComponent.h in Headers */, DCA446271EFA5DAF00D0CFA8 /* WeexSDK.h in Headers */, + C42E8F9B1F39DF07001EBE9D /* WXTracingProtocol.h in Headers */, 7423899F1C32733800D748CA /* WXType.h in Headers */, 59A582FC1CF5B17B0081FD3E /* WXBridgeContext.h in Headers */, 77D161621C02ED790010B15B /* WXLog.h in Headers */, http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m index 09dc9d8..e56bf2c 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m @@ -207,7 +207,7 @@ NSDictionary *componentData = [element toDictionary]; NSString *parentRef = [ref toString]; NSInteger insertIndex = [[index toNumber] integerValue]; - [WXTracingManager startTracingWithInstanceId:instanceIdString ref:componentData[@"ref"] className:nil name:WXTJSCall phase:WXTracingBegin functionName:@"addElement" options:@{@"threadName":WXTJSBridgeThread}]; + [WXTracingManager startTracingWithInstanceId:instanceIdString ref:componentData[@"ref"] className:nil name:WXTJSCall phase:WXTracingBegin functionName:@"addElement" options:@{@"threadName":WXTJSBridgeThread,@"componentData":componentData}]; WXLogDebug(@"callAddElement...%@, %@, %@, %ld", instanceIdString, parentRef, componentData, (long)insertIndex); return [JSValue valueWithInt32:(int32_t)callAddElement(instanceIdString, parentRef, componentData, insertIndex) inContext:[JSContext currentContext]]; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.h b/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.h index 2277242..f2e0430 100644 --- a/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.h +++ b/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.h @@ -48,4 +48,8 @@ + (NSDictionary *) jsServiceCache; ++ (BOOL)isRemoteTracing; + ++ (void)setRemoteTracing:(BOOL)isRemoteTracing; + @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.m b/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.m index b599e59..5ea2a24 100644 --- a/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.m +++ b/ios/sdk/WeexSDK/Sources/Debug/WXDebugTool.m @@ -30,6 +30,7 @@ static BOOL WXIsDebug; static BOOL WXIsDevToolDebug; +static BOOL WXIsRemoteTracing; static NSString* WXDebugrepBundleJS; static NSString* WXDebugrepJSFramework; @@ -81,6 +82,15 @@ static NSString* WXDebugrepJSFramework; WXIsDevToolDebug = isDevToolDebug; } ++ (BOOL)isRemoteTracing +{ + return WXIsRemoteTracing; +} + ++ (void)setRemoteTracing:(BOOL)isRemoteTracing { + WXIsRemoteTracing = isRemoteTracing; +} + + (BOOL)isDevToolDebug { return WXIsDevToolDebug; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.h index 9c3634e..48c1eba 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.h @@ -20,8 +20,8 @@ #import <Foundation/Foundation.h> #import "WXSDKInstance.h" -#define WXTNetworkHanding @"downloadBundleJS" -#define WXTExecJS @"executeBundleJS" +#define WXTNetworkHanding @"loadJS" +#define WXTExecJS @"execJS" #define WXTJSCall @"jsCall" #define WXTDomCall @"domCall" #define WXTRender @"render" @@ -70,6 +70,7 @@ typedef enum : NSUInteger { @property (nonatomic) long long parentId;// parent event id @property (nonatomic, copy) NSString *bundleUrl; @property (nonatomic, copy) NSString *threadName; +@property (nonatomic, strong) NSMutableArray *childrenRefs; // children ids -(NSDictionary *)dictionary; @end @@ -135,4 +136,16 @@ typedef enum : NSUInteger { */ +(NSDictionary *)getTacingApi; +/** + * @discusstion commit tracing info + * @param instanceId the instance id. + */ ++(void )commitTracing:(NSString *)instanceId; + +/** + * @discusstion commit summary info + * @param instanceId the instance id. + */ ++ (void)commitTracingSummaryInfo:(NSDictionary *)info withInstanceId:(NSString *)instanceId; + @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m index b4b19d5..6da8dd4 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m @@ -26,6 +26,8 @@ #import <WeexSDK/WXHandlerFactory.h> #import "WXUtility.h" #import "WXComponentManager.h" +#import "WXTracingProtocol.h" +#import "WXSDKEngine.h" @implementation WXTracing @@ -198,10 +200,34 @@ if(options && options[@"threadName"]){ tracing.threadName = options[@"threadName"]; } + if(options && options[@"componentData"]){ + tracing.childrenRefs = [self getChildrenRefs:options[@"componentData"]]; + } [self startTracing:tracing]; } } ++ (NSMutableArray *)getChildrenRefs:(NSDictionary *)componentData +{ + NSMutableArray *mArray = [NSMutableArray new]; + [self recursively:mArray componentData:componentData]; + return mArray; +} + ++(void)recursively:(NSMutableArray *)mArray componentData:(NSDictionary *)componentData +{ + if([componentData valueForKey:@"children"]){ + NSArray *children = [componentData valueForKey:@"children"]; + for(NSDictionary *subcomponentData in children){ + NSString *ref = [subcomponentData objectForKey:@"ref"]; + if(ref){ + [mArray addObject:ref]; + } + [self recursively:mArray componentData:subcomponentData]; + } + } +} + +(WXTracing *)copyTracing:(WXTracing *)tracing { WXTracing *newTracing = [WXTracing new]; @@ -265,7 +291,8 @@ if(tracings && [tracings count]>0){ for (NSInteger i = [tracings count] - 1; i >= 0; i--) { WXTracing *t = tracings[i]; - if([t.threadName isEqualToString:WXTJSBridgeThread]&& [t.ref isEqualToString:tracing.ref] && ([t.name isEqualToString:tracing.name] || [t.name isEqualToString:WXTJSCall])){ +// if([t.threadName isEqualToString:WXTJSBridgeThread]&& [self compareRef:tracing.ref withTracing:t] && ([t.name isEqualToString:tracing.name] || [t.name isEqualToString:WXTJSCall])){ + if([t.threadName isEqualToString:WXTJSBridgeThread]&& [self compareRef:tracing.ref withTracing:t]){ if([t.fName isEqualToString:tracing.fName]){ return t.traceId; } @@ -275,6 +302,21 @@ return -1; } ++(BOOL)compareRef:(NSString *)ref withTracing:(WXTracing *)tracing +{ + if([tracing.ref isEqualToString:ref]){ + return YES; + } + if(tracing.childrenRefs && [tracing.childrenRefs count] > 0){ + for (NSString *childRef in tracing.childrenRefs) { + if([childRef isEqualToString:ref]){ + return YES; + } + } + } + return NO; +} + +(void)updateTracings:(WXTracingTask *)task tracing:(WXTracing *)tracing { if([WXTNetworkHanding isEqualToString:task.tag]){ @@ -296,25 +338,6 @@ } } -// if([WXTExecJS isEqualToString:task.tag]){ -// if([WXTJSCall isEqualToString:tracing.name]){ -// NSMutableArray *tracings = task.tracings; -// [tracings enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(WXTracing *bTracing, NSUInteger idx, BOOL *stop) { -// if(([WXTExecJS isEqualToString:bTracing.name] || [bTracing.ref isEqualToString:tracing.ref])&&[WXTracingBegin isEqualToString:bTracing.ph]){ -// WXTracing *newTracing = [self copyTracing:bTracing]; -// newTracing.iid = tracing.iid; -// newTracing.ph = WXTracingEnd; -// newTracing.ts = tracing.ts ; -// newTracing.duration = newTracing.ts - bTracing.ts ; -// bTracing.duration = newTracing.duration; -// [task.tracings addObject:newTracing]; -// *stop = YES; -// } -// }]; -// task.tag = WXTRender; -// } -// } - if([WXTracingBegin isEqualToString:tracing.ph]){ if(tracing.ref.length>0){ WXPerformBlockOnComponentThread(^{ @@ -327,13 +350,13 @@ tracing.parentRef = com.supercomponent.ref; } tracing.name = com.type; - if(tracing.parentId == -1){ - tracing.parentId = [self getParentId:task tracing:tracing]; - } if(tracing.className.length == 0){ tracing.className = [self getclassName:tracing]; } }); + if(tracing.parentId == -1){ + tracing.parentId = [self getParentId:task tracing:tracing]; + } } else { if(tracing.parentId == -1){ tracing.parentId = [self getParentId:task tracing:tracing]; @@ -368,7 +391,11 @@ } }]; } + [task.tracings addObject:tracing]; + if([@"renderFinish" isEqualToString:tracing.fName] && [WXTracingInstant isEqualToString:tracing.ph] && [WXTUIThread isEqualToString:tracing.threadName]) { + [WXTracingManager commitTracing:task.iid]; + } } +(NSMutableDictionary *)getTracingData @@ -433,4 +460,38 @@ return dict; } ++ (void)commitTracing:(NSString *)instanceId +{ + if(![self isTracing]){ + return ; + } + id tracingHandle = [WXSDKEngine handlerForProtocol:@protocol(WXTracingProtocol)]; + if ([tracingHandle respondsToSelector:@selector(commitTracingInfo:)]){ + WXTracingTask *task = [[WXTracingManager sharedInstance].tracingTasks objectForKey:instanceId]; + if(task) { + [tracingHandle commitTracingInfo:task]; + } + + } +} + ++ (void)commitTracingSummaryInfo:(NSDictionary *)info withInstanceId:(NSString *)instanceId +{ + if(![self isTracing]){ + return ; + } + id tracingHandle = [WXSDKEngine handlerForProtocol:@protocol(WXTracingProtocol)]; + if ([tracingHandle respondsToSelector:@selector(commitTracingSummaryInfo:)]){ + if(info) { + NSMutableDictionary *newInfo = [info mutableCopy]; + if(instanceId.length > 0){ + [newInfo setObject:instanceId forKey:@"instanceId"]; + [newInfo setObject:[[WXUtility getEnvironment] objectForKey:@"platform"] forKey:@"platform"]; + } + [tracingHandle commitTracingSummaryInfo:newInfo]; + } + + } +} + @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m b/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m index a2a4d6d..6759cf4 100644 --- a/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m +++ b/ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m @@ -27,6 +27,7 @@ #import "WXComponentManager.h" #import "WXThreadSafeMutableDictionary.h" #import "WXAppConfiguration.h" +#import "WXTracingManager.h" NSString *const kStartKey = @"start"; NSString *const kEndKey = @"end"; @@ -162,6 +163,7 @@ static WXThreadSafeMutableDictionary *globalPerformanceDict; } [self printPerformance:commitDict]; + [WXTracingManager commitTracingSummaryInfo:commitDict withInstanceId:instance.instanceId]; } + (NSMutableDictionary *)performanceDictForInstance:(WXSDKInstance *)instance http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/565bab61/ios/sdk/WeexSDK/Sources/Protocol/WXTracingProtocol.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXTracingProtocol.h b/ios/sdk/WeexSDK/Sources/Protocol/WXTracingProtocol.h new file mode 100644 index 0000000..4b7f140 --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/Protocol/WXTracingProtocol.h @@ -0,0 +1,29 @@ +/* + * 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 "WXTracingProtocol.h" +#import "WXTracingManager.h" + +@protocol WXTracingProtocol <NSObject> + +- (void)commitTracingInfo:(WXTracingTask *)task; + +- (void)commitTracingSummaryInfo:(NSDictionary *)info; + +@end