feat:add global anchor hook to monitor all performance hook

This commit is contained in:
pengfei.zhou
2021-07-20 10:50:24 +08:00
committed by osborn
parent ba3635769a
commit 17e14e7119
16 changed files with 303 additions and 12 deletions

View File

@@ -31,9 +31,17 @@ NS_ASSUME_NONNULL_BEGIN
end:(NSNumber *)end;
@end
@class DoricPerformanceProfile;
@protocol DoricPerformanceGlobalAnchorHookProtocol <NSObject, DoricPerformanceAnchorHookProtocol>
- (void)onAnchorName:(NSString *)name
prepare:(NSNumber *)prepare
start:(NSNumber *)start
end:(NSNumber *)end
in:(DoricPerformanceProfile *)profile;
@end
@interface DoricPerformanceProfile : NSObject
@property(nonatomic, strong) NSMutableDictionary <NSString *, NSNumber *> *anchorMap;
- (instancetype)initWithName:(NSString *)name;

View File

@@ -28,6 +28,7 @@ @interface DoricPerformanceProfile ()
@property(nonatomic, strong) dispatch_queue_t anchorQueue;
@property(nonatomic, assign) BOOL enable;
@property(nonatomic, strong) NSHashTable<id <DoricPerformanceAnchorHookProtocol>> *hooks;
@property(nonatomic, strong) NSMutableDictionary <NSString *, NSNumber *> *anchorMap;
@end
@implementation DoricPerformanceProfile
@@ -114,7 +115,11 @@ - (void)print:(NSString *)anchorName {
@(end.integerValue - start.integerValue)
);
for (id <DoricPerformanceAnchorHookProtocol> hook in self.hooks) {
[hook onAnchorName:anchorName prepare:prepare start:start end:end];
if ([hook conformsToProtocol:@protocol(DoricPerformanceGlobalAnchorHookProtocol)]) {
[hook onAnchorName:anchorName prepare:end start:end end:end in:self];
} else {
[hook onAnchorName:anchorName prepare:prepare start:start end:end];
}
}
});
}