feat:use global anchor hook to print log

This commit is contained in:
pengfei.zhou
2021-07-20 11:29:53 +08:00
committed by osborn
parent 17e14e7119
commit a021aae3de
9 changed files with 71 additions and 43 deletions

View File

@@ -42,6 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
@end
@interface DoricPerformanceProfile : NSObject
@property(nonatomic, copy) NSString *name;
- (instancetype)initWithName:(NSString *)name;

View File

@@ -24,7 +24,6 @@
#import "DoricRegistry.h"
@interface DoricPerformanceProfile ()
@property(nonatomic, copy) NSString *name;
@property(nonatomic, strong) dispatch_queue_t anchorQueue;
@property(nonatomic, assign) BOOL enable;
@property(nonatomic, strong) NSHashTable<id <DoricPerformanceAnchorHookProtocol>> *hooks;
@@ -108,15 +107,9 @@ - (void)print:(NSString *)anchorName {
if (!prepare) {
prepare = start;
}
NSLog(@"[DoricPerformanceProfile] %@: %@ prepared %@ms, cost %@ms",
self.name,
anchorName,
@(start.integerValue - prepare.integerValue),
@(end.integerValue - start.integerValue)
);
for (id <DoricPerformanceAnchorHookProtocol> hook in self.hooks) {
if ([hook conformsToProtocol:@protocol(DoricPerformanceGlobalAnchorHookProtocol)]) {
[hook onAnchorName:anchorName prepare:end start:end end:end in:self];
[(id <DoricPerformanceGlobalAnchorHookProtocol>) hook onAnchorName:anchorName prepare:end start:end end:end in:self];
} else {
[hook onAnchorName:anchorName prepare:prepare start:start end:end];
}