feat:add performance anchor hook
This commit is contained in:
@@ -24,6 +24,14 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol DoricPerformanceAnchorHookProtocol <NSObject>
|
||||
- (void)onAnchorName:(NSString *)name
|
||||
prepare:(NSNumber *)prepare
|
||||
start:(NSNumber *)start
|
||||
end:(NSNumber *)end;
|
||||
@end
|
||||
|
||||
|
||||
@interface DoricPerformanceProfile : NSObject
|
||||
- (instancetype)initWithName:(NSString *)name;
|
||||
|
||||
@@ -32,6 +40,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)start:(NSString *)anchorName;
|
||||
|
||||
- (void)end:(NSString *)anchorName;
|
||||
|
||||
- (void)addAnchorHook:(id <DoricPerformanceAnchorHookProtocol>)hook;
|
||||
|
||||
- (void)removeAnchorHook:(id <DoricPerformanceAnchorHookProtocol>)hook;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -28,6 +28,7 @@ @interface DoricPerformanceProfile ()
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSString *, NSNumber *> *anchorMap;
|
||||
@property(nonatomic, strong) dispatch_queue_t anchorQueue;
|
||||
@property(nonatomic, assign) BOOL enable;
|
||||
@property(nonatomic, strong) NSHashTable<id <DoricPerformanceAnchorHookProtocol>> *hooks;
|
||||
@end
|
||||
|
||||
@implementation DoricPerformanceProfile
|
||||
@@ -37,10 +38,19 @@ - (instancetype)initWithName:(NSString *)name {
|
||||
_anchorQueue = dispatch_queue_create("doric.performance.profile", DISPATCH_QUEUE_SERIAL);
|
||||
_anchorMap = [NSMutableDictionary new];
|
||||
_enable = [DoricRegistry isEnablePerformance];
|
||||
_hooks = [NSHashTable new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addAnchorHook:(id)hook {
|
||||
[self.hooks addObject:hook];
|
||||
}
|
||||
|
||||
- (void)removeAnchorHook:(id)hook {
|
||||
[self.hooks removeObject:hook];
|
||||
}
|
||||
|
||||
- (NSString *)getPrepareAnchor:(NSString *)anchorName {
|
||||
return [NSString stringWithFormat:@"%@#prepare", anchorName];
|
||||
}
|
||||
@@ -100,6 +110,9 @@ - (void)print:(NSString *)anchorName {
|
||||
@(start.integerValue - prepare.integerValue),
|
||||
@(end.integerValue - start.integerValue)
|
||||
);
|
||||
for (id <DoricPerformanceAnchorHookProtocol> hook in self.hooks) {
|
||||
[hook onAnchorName:anchorName prepare:prepare start:start end:end];
|
||||
}
|
||||
});
|
||||
}
|
||||
@end
|
||||
|
Reference in New Issue
Block a user