handler_tracking.qbk 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. [/
  2. / Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:handler_tracking Handler Tracking]
  8. To aid in debugging asynchronous programs, Boost.Asio provides support for handler
  9. tracking. When enabled by defining `BOOST_ASIO_ENABLE_HANDLER_TRACKING`, Boost.Asio
  10. writes debugging output to the standard error stream. The output records
  11. asynchronous operations and the relationships between their handlers.
  12. [teletype]
  13. This feature is useful when debugging and you need to know how your
  14. asynchronous operations are chained together, or what the pending asynchronous
  15. operations are. As an illustration, here is the output when you run the HTTP
  16. Server example, handle a single request, then shut down via Ctrl+C:
  17. @asio|1512254357.979980|0*1|signal_set@0x7ffeaaaa20d8.async_wait
  18. @asio|1512254357.980127|0*2|socket@0x7ffeaaaa20f8.async_accept
  19. @asio|1512254357.980150|.2|non_blocking_accept,ec=asio.system:11
  20. @asio|1512254357.980162|0|resolver@0x7ffeaaaa1fd8.cancel
  21. @asio|1512254368.457147|.2|non_blocking_accept,ec=system:0
  22. @asio|1512254368.457193|>2|ec=system:0
  23. @asio|1512254368.457219|2*3|socket@0x55cf39f0a238.async_receive
  24. @asio|1512254368.457244|.3|non_blocking_recv,ec=system:0,bytes_transferred=141
  25. @asio|1512254368.457275|2*4|socket@0x7ffeaaaa20f8.async_accept
  26. @asio|1512254368.457293|.4|non_blocking_accept,ec=asio.system:11
  27. @asio|1512254368.457301|<2|
  28. @asio|1512254368.457310|>3|ec=system:0,bytes_transferred=141
  29. @asio|1512254368.457441|3*5|socket@0x55cf39f0a238.async_send
  30. @asio|1512254368.457502|.5|non_blocking_send,ec=system:0,bytes_transferred=156
  31. @asio|1512254368.457511|<3|
  32. @asio|1512254368.457519|>5|ec=system:0,bytes_transferred=156
  33. @asio|1512254368.457544|5|socket@0x55cf39f0a238.close
  34. @asio|1512254368.457559|<5|
  35. @asio|1512254371.385106|>1|ec=system:0,signal_number=2
  36. @asio|1512254371.385130|1|socket@0x7ffeaaaa20f8.close
  37. @asio|1512254371.385163|<1|
  38. @asio|1512254371.385175|>4|ec=asio.system:125
  39. @asio|1512254371.385182|<4|
  40. @asio|1512254371.385202|0|signal_set@0x7ffeaaaa20d8.cancel
  41. Each line is of the form:
  42. <tag>|<timestamp>|<action>|<description>
  43. The `<tag>` is always `@asio`, and is used to identify and extract the handler
  44. tracking messages from the program output.
  45. The `<timestamp>` is seconds and microseconds from 1 Jan 1970 UTC.
  46. The `<action>` takes one of the following forms:
  47. [variablelist
  48. [
  49. [>n]
  50. [The program entered the handler number `n`. The `<description>` shows the
  51. arguments to the handler.]
  52. ]
  53. [
  54. [<n]
  55. [The program left handler number `n`.]
  56. ]
  57. [
  58. [!n]
  59. [The program left handler number n due to an exception.]
  60. ]
  61. [
  62. [~n]
  63. [The handler number `n` was destroyed without having been invoked. This is
  64. usually the case for any unfinished asynchronous operations when the
  65. `io_context` is destroyed.]
  66. ]
  67. [
  68. [n*m]
  69. [The handler number `n` created a new asynchronous operation with completion
  70. handler number `m`. The `<description>` shows what asynchronous operation
  71. was started.]
  72. ]
  73. [
  74. [n]
  75. [The handler number `n` performed some other operation. The `<description>`
  76. shows what function was called. Currently only `close()` and `cancel()`
  77. operations are logged, as these may affect the state of pending
  78. asynchronous operations.]
  79. ]
  80. [
  81. [.n]
  82. [The implementation performed a system call as part of the asynchronous
  83. operation for which handler number `n` is the completion handler. The
  84. `<description>` shows what function was called and its results. These
  85. tracking events are only emitted when using a reactor-based
  86. implementation.]
  87. ]
  88. ]
  89. Where the `<description>` shows a synchronous or asynchronous operation, the
  90. format is `<object-type>@<pointer>.<operation>`. For handler entry, it shows a
  91. comma-separated list of arguments and their values.
  92. As shown above, Each handler is assigned a numeric identifier. Where the
  93. handler tracking output shows a handler number of 0, it means that the action
  94. was performed outside of any handler.
  95. [heading Visual Representations]
  96. The handler tracking output may be post-processed using the included
  97. [^handlerviz.pl] tool to create a visual representation of the handlers
  98. (requires the GraphViz tool [^dot]).
  99. [c++]
  100. [heading Custom Tracking]
  101. Handling tracking may be customised by defining the
  102. `BOOST_ASIO_CUSTOM_HANDLER_TRACKING` macro to the name of a header file
  103. (enclosed in `""` or `<>`). This header file must implement the following
  104. preprocessor macros:
  105. [table
  106. [[Macro] [Description]]
  107. [
  108. [`BOOST_ASIO_INHERIT_TRACKED_HANDLER`]
  109. [Specifies a base class for classes that implement asynchronous operations.
  110. When used, the macro immediately follows the class name, so it must have
  111. the form `: public my_class`.]
  112. ]
  113. [
  114. [`BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER`]
  115. [Specifies a base class for classes that implement asynchronous operations.
  116. When used, the macro follows other base classes, so it must have the form
  117. `, public my_class`.]
  118. ]
  119. [
  120. [`BOOST_ASIO_HANDLER_TRACKING_INIT(args)`]
  121. [An expression that is used to initialise the tracking mechanism.]
  122. ]
  123. [
  124. [`BOOST_ASIO_HANDLER_CREATION(args)`]
  125. [An expression that is called on creation of an asynchronous operation.
  126. `args` is a parenthesised function argument list containing the owning
  127. execution context, the tracked handler, the name of the object type, a
  128. pointer to the object, the object's native handle, and the operation name.]
  129. ]
  130. [
  131. [`BOOST_ASIO_HANDLER_COMPLETION(args)`]
  132. [An expression that is called on completion of an asynchronous operation.
  133. `args` is a parenthesised function argument list containing the tracked
  134. handler.]
  135. ]
  136. [
  137. [`BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args)`]
  138. [An expression that is called immediately before a completion handler is
  139. invoked. `args` is a parenthesised function argument list containing the
  140. arguments to the completion handler.]
  141. ]
  142. [
  143. [`BOOST_ASIO_HANDLER_INVOCATION_END`]
  144. [An expression that is called immediately after a completion handler is
  145. invoked.]
  146. ]
  147. [
  148. [`BOOST_ASIO_HANDLER_OPERATION(args)`]
  149. [An expression that is called when some synchronous object operation is
  150. called (such as `close()` or `cancel()`). `args` is a parenthesised
  151. function argument list containing the owning execution context, the name
  152. of the object type, a pointer to the object, the object's native handle,
  153. and the operation name.]
  154. ]
  155. [
  156. [`BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args)`]
  157. [An expression that is called when an object is registered with the
  158. reactor. `args` is a parenthesised function argument list containing the
  159. owning execution context, the object's native handle, and a unique
  160. registration key.]
  161. ]
  162. [
  163. [`BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args)`]
  164. [An expression that is called when an object is deregistered from the
  165. reactor. `args` is a parenthesised function argument list containing the
  166. owning execution context, the object's native handle, and a unique
  167. registration key.]
  168. ]
  169. [
  170. [`BOOST_ASIO_HANDLER_REACTOR_READ_EVENT`]
  171. [A bitmask constant used to identify reactor read readiness events.]
  172. ]
  173. [
  174. [`BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT`]
  175. [A bitmask constant used to identify reactor write readiness events.]
  176. ]
  177. [
  178. [`BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT`]
  179. [A bitmask constant used to identify reactor error readiness events.]
  180. ]
  181. [
  182. [`BOOST_ASIO_HANDLER_REACTOR_EVENTS(args)`]
  183. [An expression that is called when an object registered with the reactor
  184. becomes ready. `args` is a parenthesised function argument list containing
  185. the owning execution context, the unique registration key, and a bitmask of
  186. the ready events.]
  187. ]
  188. [
  189. [`BOOST_ASIO_HANDLER_REACTOR_OPERATION(args)`]
  190. [An expression that is called when the implementation performs a system
  191. call as part of a reactor-based asynchronous operation. `args` is a
  192. parenthesised function argument list containing the tracked handler, the
  193. operation name, the error code produced by the operation, and (optionally)
  194. the number of bytes transferred.]
  195. ]
  196. ]
  197. [heading See Also]
  198. [link boost_asio.examples.cpp11_examples.handler_tracking Custom handler tracking
  199. example].
  200. [endsect]