feat:use global anchor hook to print log
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
#import "DoricDebugDriver.h"
|
||||
#import "DoricDevViewController.h"
|
||||
#import "DoricDevMonitor.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricDevPerformanceAnchorHook.h"
|
||||
|
||||
@interface DoricContextDebuggable : NSObject
|
||||
@property(nonatomic, weak) DoricContext *doricContext;
|
||||
@@ -79,6 +79,7 @@ - (instancetype)init {
|
||||
_callbacks = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
|
||||
_reloadingContexts = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
|
||||
[DoricNativeDriver.instance.registry registerMonitor:[DoricDevMonitor new]];
|
||||
DoricNativeDriver.instance.registry.globalPerformanceAnchorHook = [DoricDevPerformanceAnchorHook new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -199,7 +200,7 @@ - (void)reload:(NSString *)source script:(NSString *)script {
|
||||
DoricLog(@"Context source %@ in debugging,skip reload", source);
|
||||
} else {
|
||||
DoricLog(@"Context reload :id %@,source %@", context.contextId, source);
|
||||
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[context reload:script];
|
||||
[self.reloadingContexts addObject:context];
|
||||
@@ -274,32 +275,32 @@ - (NSString *)ip {
|
||||
withString:@""];
|
||||
}
|
||||
|
||||
UIViewController* _Nonnull findBestViewController(UIViewController* _Nonnull vc) {
|
||||
UIViewController *_Nonnull findBestViewController(UIViewController *_Nonnull vc) {
|
||||
if (vc.presentedViewController && ![vc.presentedViewController isKindOfClass:[UIAlertController class]]) {
|
||||
// Return presented view controller
|
||||
return findBestViewController(vc.presentedViewController);
|
||||
} else if ([vc isKindOfClass:[UISplitViewController class]]) {
|
||||
// Return right hand side
|
||||
UISplitViewController* svc = (UISplitViewController*) vc;
|
||||
UISplitViewController *svc = (UISplitViewController *) vc;
|
||||
if (svc.viewControllers.count > 0)
|
||||
return findBestViewController(svc.viewControllers.lastObject);
|
||||
else
|
||||
return vc;
|
||||
} else if ([vc isKindOfClass:[UINavigationController class]]) {
|
||||
// Return top view
|
||||
UINavigationController* svc = (UINavigationController*) vc;
|
||||
UINavigationController *svc = (UINavigationController *) vc;
|
||||
if (svc.viewControllers.count > 0)
|
||||
return findBestViewController(svc.topViewController);
|
||||
else
|
||||
return vc;
|
||||
} else if ([vc isKindOfClass:[UITabBarController class]]) {
|
||||
// Return visible view
|
||||
UITabBarController* svc = (UITabBarController*) vc;
|
||||
UITabBarController *svc = (UITabBarController *) vc;
|
||||
if (svc.viewControllers.count > 0)
|
||||
return findBestViewController(svc.selectedViewController);
|
||||
else
|
||||
return vc;
|
||||
} else {
|
||||
} else {
|
||||
// Unknown view controller type, return last child view controller
|
||||
return vc;
|
||||
}
|
||||
|
9
doric-iOS/Devkit/Classes/DoricDevPerformanceAnchorHook.h
Normal file
9
doric-iOS/Devkit/Classes/DoricDevPerformanceAnchorHook.h
Normal file
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/7/20.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <DoricCore/Doric.h>
|
||||
|
||||
@interface DoricDevPerformanceAnchorHook : NSObject<DoricPerformanceGlobalAnchorHookProtocol>
|
||||
@end
|
17
doric-iOS/Devkit/Classes/DoricDevPerformanceAnchorHook.m
Normal file
17
doric-iOS/Devkit/Classes/DoricDevPerformanceAnchorHook.m
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/7/20.
|
||||
//
|
||||
|
||||
#import "DoricDevPerformanceAnchorHook.h"
|
||||
|
||||
|
||||
@implementation DoricDevPerformanceAnchorHook
|
||||
- (void)onAnchorName:(NSString *)name prepare:(NSNumber *)prepare start:(NSNumber *)start end:(NSNumber *)end in:(DoricPerformanceProfile *)profile {
|
||||
NSLog(@"[DoricPerformance] %@: %@ prepared %@ms, cost %@ms",
|
||||
profile.name,
|
||||
name,
|
||||
@(start.integerValue - prepare.integerValue),
|
||||
@(end.integerValue - start.integerValue)
|
||||
);
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user