feat:add global anchor hook to monitor all performance hook
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user