From d63a4e4b22a25668ef527444745ed3411134ccd3 Mon Sep 17 00:00:00 2001 From: Aleksandar Micic Date: Wed, 13 Sep 2023 14:26:36 -0400 Subject: [PATCH] Cumulative thread allocation stats Provide API to return allocation bytes since the start of VM. Return false if the sum rolls over. Signed-off-by: Aleksandar Micic --- gc/stats/AllocationStats.cpp | 4 ++++ gc/stats/AllocationStats.hpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/gc/stats/AllocationStats.cpp b/gc/stats/AllocationStats.cpp index cf6d46f5868..2bf49b19cec 100644 --- a/gc/stats/AllocationStats.cpp +++ b/gc/stats/AllocationStats.cpp @@ -26,6 +26,10 @@ void MM_AllocationStats::clear() { + /* calculate cumulative stats before any clear */ + _allocationBytesCumulative += bytesAllocated(); + + #if defined(OMR_GC_THREAD_LOCAL_HEAP) _tlhRefreshCountFresh = 0; _tlhRefreshCountReused = 0; diff --git a/gc/stats/AllocationStats.hpp b/gc/stats/AllocationStats.hpp index f5554b4d64d..2132c39484c 100644 --- a/gc/stats/AllocationStats.hpp +++ b/gc/stats/AllocationStats.hpp @@ -49,6 +49,7 @@ class MM_AllocationStats : public MM_Base uintptr_t _allocationCount; uintptr_t _allocationBytes; + uintptr_t _allocationBytesCumulative; /**< cumulative allocation up to last clear, excluding since last clear */ uintptr_t _ownableSynchronizerObjectCount; /**< Number of Ownable Synchronizer Object allocations */ uintptr_t _continuationObjectCount; /**< Number of Continuation Object allocations */ uintptr_t _discardedBytes; @@ -86,6 +87,18 @@ class MM_AllocationStats : public MM_Base return totalBytesAllocated; } + bool bytesAllocatedCumulative(uintptr_t *cumulativeValue) { + if (NULL != cumulativeValue) { + /* sum the values up to last clear and since last clear */ + *cumulativeValue = _allocationBytesCumulative + bytesAllocated(); + + /* return false if overflowing */ + return (_allocationBytesCumulative <= *cumulativeValue); + } + + return false; + } + MM_AllocationStats() : #if defined(OMR_GC_THREAD_LOCAL_HEAP) _tlhRefreshCountFresh(0),