Skip to content

Commit

Permalink
Constexpr check NANO_ASIO_HANDLER_TRACKING
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 14, 2024
1 parent 6f8e1d3 commit ebc2011
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
26 changes: 14 additions & 12 deletions nano/test_common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,22 +335,24 @@ void nano::test::system::deadline_set (std::chrono::duration<double, std::nano>

std::error_code nano::test::system::poll (std::chrono::nanoseconds const & wait_time)
{
#if NANO_ASIO_HANDLER_TRACKING == 0
io_ctx->run_one_for (wait_time);
#else
nano::timer<> timer;
timer.start ();
auto count = io_ctx.poll_one ();
if (count == 0)
if constexpr (asio_handler_tracking_threshold () == 0)
{
std::this_thread::sleep_for (wait_time);
io_ctx->run_one_for (wait_time);
}
else if (count == 1 && timer.since_start ().count () >= NANO_ASIO_HANDLER_TRACKING)
else
{
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds> (std::chrono::system_clock::now ().time_since_epoch ()).count ();
std::cout << (boost::format ("[%1%] io_thread held for %2%ms") % timestamp % timer.since_start ().count ()).str () << std::endl;
nano::timer<> timer;
timer.start ();
auto count = io_ctx->poll_one ();
if (count == 0)
{
std::this_thread::sleep_for (wait_time);
}
else if (count == 1 && timer.since_start ().count () >= asio_handler_tracking_threshold ())
{
logger.warn (nano::log::type::system, "Async handler processing took too long: {}ms", timer.since_start ().count ());
}
}
#endif

std::error_code ec;
if (std::chrono::steady_clock::now () > deadline)
Expand Down
12 changes: 12 additions & 0 deletions nano/test_common/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@ namespace test
}
}
REGISTER_ERROR_CODES (nano, error_system);

namespace nano::test
{
constexpr unsigned asio_handler_tracking_threshold ()
{
#if NANO_ASIO_HANDLER_TRACKING == 0
return 0;
#else
return NANO_ASIO_HANDLER_TRACKING;
#endif
}
}

0 comments on commit ebc2011

Please sign in to comment.