How is dispatch_debug supposed to be used?
I am struggling with a deadlock in my GCD code. Then I saw this function dispatch_debug
in the header file <dispatch/object.h>
.
/*!
* @function dispatch_debug
*
* @abstract
* Programmatically log debug information about a dispatch object.
*
* @param object
* The object to introspect.
*
* @param message
* The message to log above and beyond the introspection.
*/
__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NOTHROW __attribute__((__format__(printf,2,3)))
void
dispatch_debug(dispatch_object_t object, const char *message, ..开发者_如何学C.);
But I am not able to make it do anything. I was hoping it would print out the state and locks or something like that.
Here is how I use it:
grabber_queue = dispatch_queue_create("com.unpaq.tvguideplus.grabber", NULL);
dispatch_debug(grabber_queue, "grabber queue");
- Grand Central Dispatch (GCD) Reference
dispatch_debug
Debug information is logged to the Console log. This information can be useful as a debugging tool to view the internal state (current reference count, suspension count, etc.) of a dispatch object at the time the dispatch_debug function is called.
dispatch_debug sends messages to syslog. So,
grabber_queue = dispatch_queue_create("com.unpaq.tvguideplus.grabber", NULL);
dispatch_debug(grabber_queue, "grabber queue");
this code would print as the following in system.log.
May 13 08:50:17 hostname exefile[53164]: com.unpaq.tvguideplus.grabber[0x6200e10] = {
xrefcnt = 0x1, refcnt = 0x1, suspend_cnt = 0x0, locked = 0, target =
com.apple.root.default-overcommit-priority[0x1af0700], width = 0x0, running = 0x0,
barrier = 0 }: grabber queueMay
It doesn't appear in Xcode debug console. You can see in /Applications/Utilities/Console.app system.log on the iPhone simulator, or in Xcode organizer on iPhone, iPod touch and iPad.
By the way, GCD is open source. It is distributed via libdispatch. dispatch_debug is included in src/object.c.
- src/object.c - dispatch_debug
As of iOS 6.0 dispatch_debug()
is deprecated. The docs doesn't say what is intended to be used instead, but I found out that now you can handle dispatch_object_t
objects like NSObject
ones:
(lldb) po _connectScanTimer
<OS_dispatch_source: kevent-source[0x15d47440] = { xrefcnt = 0x1, refcnt = 0x2, suspend_cnt = 0x7fffffff, locked = 0, target = [0x15d7ca50], ident = 0x4, pending_data = 0x1, pending_data_mask = 0x0, timer = { target = 0x48841e442a, deadline = 0x488479d1aa, last_fire = 0x48808ac1cc, interval = 0x3938700, flags = 0x0 }, filter = DISPATCH_EVFILT_TIMER }>
That means you can use description
and debugDescription
methods to get some info about dispatch_object_t
objects.
精彩评论