Logging RPC duration.

This commit is contained in:
clemahieu 2017-05-29 15:50:07 -05:00
commit 2df2529539

View file

@ -2025,8 +2025,9 @@ void rai::rpc_connection::parse_connection ()
{
if (!ec)
{
auto start (std::chrono::system_clock::now ());
auto version (this_l->request.version);
auto response_handler ([this_l, version] (boost::property_tree::ptree const & tree_a)
auto response_handler ([this_l, version, start] (boost::property_tree::ptree const & tree_a)
{
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree_a);
@ -2041,11 +2042,19 @@ void rai::rpc_connection::parse_connection ()
beast::http::async_write (this_l->socket, this_l->res, [this_l] (boost::system::error_code const & ec)
{
});
if (this_l->node->config.logging.log_rpc ())
{
BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast <std::chrono::microseconds> (std::chrono::system_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast <uintptr_t> (this_l.get ())));
}
});
if (this_l->request.method () == "POST")
{
auto handler (std::make_shared <rai::rpc_handler> (*this_l->node, this_l->rpc, this_l->request.body, response_handler));
handler->process_request ();
if (this_l->node->config.logging.log_rpc ())
{
BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% serviced in: %1% microseconds") % std::chrono::duration_cast <std::chrono::microseconds> (std::chrono::system_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast <uintptr_t> (this_l.get ())));
}
}
else
{