Track the underlying reactor operations associated with handlers.

For reactor-based platforms only. For example, an async send on a reactor-based
platform will now log the result to each non-blocking send system call.
This commit is contained in:
Christopher Kohlhoff 2015-03-12 10:18:27 +11:00
parent f1de530de5
commit d4f7353a9e
11 changed files with 95 additions and 8 deletions

View File

@ -51,8 +51,13 @@ public:
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(o->buffers_);
return descriptor_ops::non_blocking_read(o->descriptor_,
bool result = descriptor_ops::non_blocking_read(o->descriptor_,
bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_read",
o->ec_, o->bytes_transferred_));
return result;
}
private:

View File

@ -51,8 +51,13 @@ public:
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs(o->buffers_);
return descriptor_ops::non_blocking_write(o->descriptor_,
bool result = descriptor_ops::non_blocking_write(o->descriptor_,
bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_write",
o->ec_, o->bytes_transferred_));
return result;
}
private:

View File

@ -44,6 +44,7 @@ namespace detail {
// - ASIO_HANDLER_INVOCATION_BEGIN(args)
// - ASIO_HANDLER_INVOCATION_END
// - ASIO_HANDLER_OPERATION(args)
// - ASIO_HANDLER_REACTOR_OPERATION(args)
#elif defined(ASIO_ENABLE_HANDLER_TRACKING)
@ -116,11 +117,21 @@ public:
completion* next_;
};
// Record an operation that affects pending handlers.
// Record an operation that is not directly associated with a handler.
ASIO_DECL static void operation(execution_context& context,
const char* object_type, void* object,
uintmax_t native_handle, const char* op_name);
// Record a reactor-based operation that is associated with a handler.
ASIO_DECL static void reactor_operation(
const tracked_handler& h, const char* op_name,
const asio::error_code& ec);
// Record a reactor-based operation that is associated with a handler.
ASIO_DECL static void reactor_operation(
const tracked_handler& h, const char* op_name,
const asio::error_code& ec, std::size_t bytes_transferred);
// Write a line of output.
ASIO_DECL static void write_line(const char* format, ...);
@ -153,6 +164,9 @@ private:
# define ASIO_HANDLER_OPERATION(args) \
asio::detail::handler_tracking::operation args
# define ASIO_HANDLER_REACTOR_OPERATION(args) \
asio::detail::handler_tracking::reactor_operation args
#else // defined(ASIO_ENABLE_HANDLER_TRACKING)
# define ASIO_INHERIT_TRACKED_HANDLER
@ -163,6 +177,7 @@ private:
# define ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
# define ASIO_HANDLER_INVOCATION_END (void)0
# define ASIO_HANDLER_OPERATION(args) (void)0
# define ASIO_HANDLER_REACTOR_OPERATION(args) (void)0
#endif // defined(ASIO_ENABLE_HANDLER_TRACKING)

View File

@ -278,6 +278,39 @@ void handler_tracking::operation(execution_context&,
current_id, object_type, object, op_name);
}
void handler_tracking::reactor_operation(
const tracked_handler& h, const char* op_name,
const asio::error_code& ec)
{
handler_tracking_timestamp timestamp;
write_line(
#if defined(ASIO_WINDOWS)
"@asio|%I64u.%06I64u|.%I64u|%s,ec=%.20s:%d\n",
#else // defined(ASIO_WINDOWS)
"@asio|%llu.%06llu|.%llu|%s,ec=%.20s:%d\n",
#endif // defined(ASIO_WINDOWS)
timestamp.seconds, timestamp.microseconds,
h.id_, op_name, ec.category().name(), ec.value());
}
void handler_tracking::reactor_operation(
const tracked_handler& h, const char* op_name,
const asio::error_code& ec, std::size_t bytes_transferred)
{
handler_tracking_timestamp timestamp;
write_line(
#if defined(ASIO_WINDOWS)
"@asio|%I64u.%06I64u|.%I64u|%s,ec=%.20s:%d,bytes_transferred=%I64u\n",
#else // defined(ASIO_WINDOWS)
"@asio|%llu.%06llu|.%llu|%s,ec=%.20s:%d,bytes_transferred=%llu\n",
#endif // defined(ASIO_WINDOWS)
timestamp.seconds, timestamp.microseconds,
h.id_, op_name, ec.category().name(), ec.value(),
static_cast<uint64_t>(bytes_transferred));
}
void handler_tracking::write_line(const char* format, ...)
{
using namespace std; // For sprintf (or equivalent).

View File

@ -56,6 +56,8 @@ public:
o->state_, o->peer_endpoint_ ? o->peer_endpoint_->data() : 0,
o->peer_endpoint_ ? &addrlen : 0, o->ec_, new_socket);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_accept", o->ec_));
// On success, assign new connection to peer socket object.
if (new_socket != invalid_socket)
{

View File

@ -42,7 +42,11 @@ public:
reactive_socket_connect_op_base* o(
static_cast<reactive_socket_connect_op_base*>(base));
return socket_ops::non_blocking_connect(o->socket_, o->ec_);
bool result = socket_ops::non_blocking_connect(o->socket_, o->ec_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_connect", o->ec_));
return result;
}
private:

View File

@ -51,10 +51,15 @@ public:
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(o->buffers_);
return socket_ops::non_blocking_recv(o->socket_,
bool result = socket_ops::non_blocking_recv(o->socket_,
bufs.buffers(), bufs.count(), o->flags_,
(o->state_ & socket_ops::stream_oriented) != 0,
o->ec_, o->bytes_transferred_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recv",
o->ec_, o->bytes_transferred_));
return result;
}
private:

View File

@ -61,6 +61,9 @@ public:
if (result && !o->ec_)
o->sender_endpoint_.resize(addr_len);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recvfrom",
o->ec_, o->bytes_transferred_));
return result;
}

View File

@ -52,10 +52,15 @@ public:
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(o->buffers_);
return socket_ops::non_blocking_recvmsg(o->socket_,
bool result = socket_ops::non_blocking_recvmsg(o->socket_,
bufs.buffers(), bufs.count(),
o->in_flags_, o->out_flags_,
o->ec_, o->bytes_transferred_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recvmsg",
o->ec_, o->bytes_transferred_));
return result;
}
private:

View File

@ -50,9 +50,14 @@ public:
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs(o->buffers_);
return socket_ops::non_blocking_send(o->socket_,
bool result = socket_ops::non_blocking_send(o->socket_,
bufs.buffers(), bufs.count(), o->flags_,
o->ec_, o->bytes_transferred_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_send",
o->ec_, o->bytes_transferred_));
return result;
}
private:

View File

@ -51,10 +51,15 @@ public:
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs(o->buffers_);
return socket_ops::non_blocking_sendto(o->socket_,
bool result = socket_ops::non_blocking_sendto(o->socket_,
bufs.buffers(), bufs.count(), o->flags_,
o->destination_.data(), o->destination_.size(),
o->ec_, o->bytes_transferred_);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_sendto",
o->ec_, o->bytes_transferred_));
return result;
}
private: