How is dispatch_debug supposed to be used?

给你一囗甜甜゛ 提交于 2019-12-14 03:58:33

问题


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, ...);

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");

回答1:


  • 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



回答2:


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.



来源:https://stackoverflow.com/questions/5983784/how-is-dispatch-debug-supposed-to-be-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!