From bdb748135708f8ea3fa96b41d828d1e22544b869 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 14 Aug 2018 13:17:21 +0300 Subject: [PATCH] MXS-2008 Remove dependency on mxs_clock() --- server/core/worker.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/server/core/worker.cc b/server/core/worker.cc index 502a68898..00056c36a 100644 --- a/server/core/worker.cc +++ b/server/core/worker.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -721,6 +720,21 @@ void Worker::resolve_poll_error(int fd, int errornum, int op) raise(SIGABRT); } +namespace +{ + +long time_in_100ms_ticks() +{ + using TenthSecondDuration = std::chrono::duration>; + + auto dur = std::chrono::steady_clock::now().time_since_epoch(); + auto tenth = std::chrono::duration_cast(dur); + + return tenth.count(); +} + +} + /** * The main polling loop */ @@ -797,12 +811,12 @@ void Worker::poll_waitevents() m_statistics.n_fds[(nfds < STATISTICS::MAXNFDS ? (nfds - 1) : STATISTICS::MAXNFDS - 1)]++; } - uint64_t cycle_start = mxs_clock(); + uint64_t cycle_start = time_in_100ms_ticks(); for (int i = 0; i < nfds; i++) { /** Calculate event queue statistics */ - int64_t started = mxs_clock(); + int64_t started = time_in_100ms_ticks(); int64_t qtime = started - cycle_start; if (qtime > STATISTICS::N_QUEUE_TIMES) @@ -846,7 +860,7 @@ void Worker::poll_waitevents() } /** Calculate event execution statistics */ - qtime = mxs_clock() - started; + qtime = time_in_100ms_ticks() - started; if (qtime > STATISTICS::N_QUEUE_TIMES) { @@ -854,7 +868,7 @@ void Worker::poll_waitevents() } else { - m_statistics.exectimes[qtime % STATISTICS::N_QUEUE_TIMES]++; + m_statistics.exectimes[qtime]++; } m_statistics.maxexectime = MXS_MAX(m_statistics.maxexectime, qtime);