20 #ifndef BEAST_ASIO_IO_LATENCY_PROBE_H_INCLUDED
21 #define BEAST_ASIO_IO_LATENCY_PROBE_H_INCLUDED
23 #include <boost/asio/basic_waitable_timer.hpp>
24 #include <boost/asio/io_service.hpp>
33 template <
class Clock>
45 boost::asio::basic_waitable_timer<std::chrono::steady_clock>
m_timer;
66 boost::asio::io_service&
72 boost::asio::io_service
const&
102 template <
class Handler>
109 m_ios.post(sample_op<Handler>(
110 std::forward<Handler>(handler), Clock::now(),
false,
this));
117 template <
class Handler>
124 m_ios.post(sample_op<Handler>(
125 std::forward<Handler>(handler), Clock::now(),
true,
this));
139 m_cond.
wait(lock, [
this] {
return this->m_count == 0; });
157 template <
class Handler>
166 Handler
const& handler,
186 from.m_probe =
nullptr;
206 typename Clock::time_point
const now(Clock::now());
207 typename Clock::duration
const elapsed(now -
m_start);
222 typename Clock::time_point
const when(
247 typename Clock::time_point
const now(Clock::now());
typename std::chrono::steady_clock ::time_point time_point
typename Clock::duration duration
io_latency_probe * m_probe
boost::asio::io_service & get_io_service()
Return the io_service associated with the latency probe.
sample_op(sample_op &&from) noexcept
boost::asio::io_service const & get_io_service() const
boost::asio::io_service & m_ios
std::condition_variable_any m_cond
void sample(Handler &&handler)
Initiate continuous i/o latency sampling.
void cancel(std::unique_lock< decltype(m_mutex)> &lock, bool wait)
void sample_one(Handler &&handler)
Measure one sample of i/o latency.
Measures handler latency on an io_service queue.
sample_op operator=(sample_op const &)=delete
std::recursive_mutex m_mutex
void cancel()
Cancel all pending i/o.
void operator()(boost::system::error_code const &ec)
io_latency_probe(duration const &period, boost::asio::io_service &ios)
sample_op(Handler const &handler, time_point const &start, bool repeat, io_latency_probe *probe)
boost::asio::basic_waitable_timer< std::chrono::steady_clock > m_timer