Last active
December 22, 2017 11:21
-
-
Save ycditchf/bf36ec3608ad529e2b714ae6f6e30fa8 to your computer and use it in GitHub Desktop.
监测runloop
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
- (void)setupRunloopObserver | |
{ | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
CFRunLoopRef runloop = CFRunLoopGetCurrent(); | |
CFRunLoopObserverRef enterObserver; | |
enterObserver = CFRunLoopObserverCreate(CFAllocatorGetDefault(), | |
kCFRunLoopEntry | kCFRunLoopExit, | |
true, | |
-0x7FFFFFFF, | |
BBRunloopObserverCallBack, NULL); | |
CFRunLoopAddObserver(runloop, enterObserver, kCFRunLoopCommonModes); | |
CFRelease(enterObserver); | |
}); | |
} | |
static void BBRunloopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) { | |
switch (activity) { | |
case kCFRunLoopEntry: { | |
NSLog(@"enter runloop..."); | |
} | |
break; | |
case kCFRunLoopExit: { | |
NSLog(@"leave runloop..."); | |
} | |
break; | |
default: break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment