From db5eb115f1428a7d8493cae9b7b0a3df0cca8d97 Mon Sep 17 00:00:00 2001 From: Valentin Balaschenko <13349202+vlntb@users.noreply.github.com> Date: Sun, 31 May 2026 10:26:36 +0100 Subject: [PATCH] added logs --- include/xrpl/basics/IntrusiveRefCounts.h | 20 ++++++++++++++++++++ src/xrpld/app/main/Application.cpp | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/xrpl/basics/IntrusiveRefCounts.h b/include/xrpl/basics/IntrusiveRefCounts.h index 0b00f1d5b1..509ab1dc1d 100644 --- a/include/xrpl/basics/IntrusiveRefCounts.h +++ b/include/xrpl/basics/IntrusiveRefCounts.h @@ -7,6 +7,24 @@ namespace xrpl { +namespace detail { +// All-time peak strong/weak ref counts ever observed across all +// IntrusiveRefCounts instances. Read from doSweep periodically. +inline std::atomic kPeakStrongObserved{0}; +inline std::atomic kPeakWeakObserved{0}; + +inline void +updateRefCountPeak(std::atomic& peak, std::uint32_t v) noexcept +{ + auto cur = peak.load(std::memory_order_relaxed); + while (v > cur && !peak.compare_exchange_weak( + cur, v, std::memory_order_relaxed)) + { + // retry; cur is updated by compare_exchange_weak on failure + } +} +} // namespace detail + /** Action to perform when releasing a strong pointer. noop: Do nothing. For example, a `noop` action will occur when a count is @@ -413,6 +431,8 @@ inline IntrusiveRefCounts::RefCountPair::RefCountPair(IntrusiveRefCounts::FieldT , partialDestroyStartedBit{v & kPartialDestroyStartedMask} , partialDestroyFinishedBit{v & kPartialDestroyFinishedMask} { + detail::updateRefCountPeak(detail::kPeakStrongObserved, strong); + detail::updateRefCountPeak(detail::kPeakWeakObserved, weak); XRPL_ASSERT( (strong < kCheckStrongMaxValue && weak < kCheckWeakMaxValue), "xrpl::IntrusiveRefCounts::RefCountPair(FieldType) : inputs inside " diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 508dfc8590..2f76dd0730 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -1088,6 +1088,21 @@ public: << "; size after: " << cachedSLEs_.size(); } + { + auto const peakStrong = + xrpl::detail::kPeakStrongObserved.load(std::memory_order_relaxed); + auto const peakWeak = + xrpl::detail::kPeakWeakObserved.load(std::memory_order_relaxed); + constexpr std::uint32_t kStrongLimit = 65503; // kCheckStrongMaxValue + constexpr std::uint32_t kWeakLimit = 16351; // kCheckWeakMaxValue + JLOG(journal_.warn()) + << "RefCount peak since startup: " + << "strong=" << peakStrong << "/" << kStrongLimit + << " (" << (peakStrong * 100 / kStrongLimit) << "%); " + << "weak=" << peakWeak << "/" << kWeakLimit + << " (" << (peakWeak * 100 / kWeakLimit) << "%)"; + } + mallocTrim("doSweep", journal_); // Set timer to do another sweep later.