Created
January 17, 2017 07:26
-
-
Save pavelosipov/bc293c2a943dae13ca205ad929bf713b to your computer and use it in GitHub Desktop.
Hangs Reporting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface POSThreadWatchDogReporter () | |
@property (nonatomic, readonly) NSTimeInterval threshold; | |
@property (nonatomic, readonly) POSThreadWatchDog *watchDog; | |
@end | |
@implementation POSThreadWatchDogReporter | |
- (instancetype)initWithThreshold:(NSTimeInterval)threshold { | |
POSRX_CHECK([NSThread isMainThread]); | |
thread_t thread = mach_thread_self(); | |
mach_port_deallocate(mach_task_self(), thread); | |
if (self = [super init]) { | |
_threshold = threshold; | |
_watchDog = [[POSThreadWatchDog alloc] | |
initWithScheduler:RACTargetQueueScheduler.pos_scheduler | |
targetThread:thread | |
pingInterval:1]; | |
} | |
return self; | |
} | |
- (void)start { | |
@weakify(self); | |
[[_watchDog start] subscribeNext:^(POSThreadWatchDogReport *report) { | |
@strongify(self); | |
BOOL shouldReport = report.hangTime >= self.threshold; | |
NSLog(@"[INCOMMING] %@:%@:%@:%@", | |
report.ID, | |
report.hangerName, | |
@(report.hangTime), | |
@(report.hangCompleted)); | |
if (shouldReport && report.hangCompleted) { | |
[self p_removeReport:report]; | |
NSLog(@"[SEND ] %@", report.ID); | |
} else if (shouldReport && !report.hangCompleted) { | |
[self p_saveReport:report]; | |
} | |
} error:^(NSError *error) { | |
NSLog(@"[ERROR ] %@", error); | |
}]; | |
} | |
- (void)sendPendingReports { | |
} | |
- (void)p_saveReport:(POSThreadWatchDogReport *)report { | |
NSLog(@"[SAVE ] %@", report.ID); | |
} | |
- (void)p_removeReport:(POSThreadWatchDogReport *)report { | |
NSLog(@"[REMOVE ] %@", report.ID); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment