Skip to content

Instantly share code, notes, and snippets.

@pavelosipov
Created January 17, 2017 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelosipov/bc293c2a943dae13ca205ad929bf713b to your computer and use it in GitHub Desktop.
Save pavelosipov/bc293c2a943dae13ca205ad929bf713b to your computer and use it in GitHub Desktop.
Hangs Reporting
@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