From fa1b4e5c3294fc9aec033892a4a4d7b5cfc015aa Mon Sep 17 00:00:00 2001 From: MarcoFalke <6399679+MarcoFalke@users.noreply.github.com> Date: Thu, 2 Mar 2023 15:05:54 +0100 Subject: [PATCH] Use steady clock in FlushStateToDisk --- src/validation.cpp | 8 ++++---- src/validation.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 06744548836..b160e5dcfe1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2478,12 +2478,12 @@ bool Chainstate::FlushStateToDisk( } } } - const auto nNow = GetTime(); + const auto nNow{SteadyClock::now()}; // Avoid writing/flushing immediately after startup. - if (m_last_write.count() == 0) { + if (m_last_write == decltype(m_last_write){}) { m_last_write = nNow; } - if (m_last_flush.count() == 0) { + if (m_last_flush == decltype(m_last_flush){}) { m_last_flush = nNow; } // The cache is large and we're within 10% and 10 MiB of the limit, but we have time now (not in the middle of a block processing). @@ -2544,7 +2544,7 @@ bool Chainstate::FlushStateToDisk( m_last_flush = nNow; full_flush_completed = true; TRACE5(utxocache, flush, - (int64_t)(GetTimeMicros() - nNow.count()), // in microseconds (µs) + int64_t{Ticks(SteadyClock::now() - nNow)}, (uint32_t)mode, (uint64_t)coins_count, (uint64_t)coins_mem_usage, diff --git a/src/validation.h b/src/validation.h index 067d2ea6d29..d6f9509f2f2 100644 --- a/src/validation.h +++ b/src/validation.h @@ -785,8 +785,8 @@ private: void UpdateTip(const CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); - std::chrono::microseconds m_last_write{0}; - std::chrono::microseconds m_last_flush{0}; + SteadyClock::time_point m_last_write{}; + SteadyClock::time_point m_last_flush{}; friend ChainstateManager; };