Skip to content

Commit d63a4e4

Browse files
Aleksandar MicicAleksandar Micic
authored andcommitted
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 <[email protected]>
1 parent f8fecbe commit d63a4e4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

gc/stats/AllocationStats.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
void
2727
MM_AllocationStats::clear()
2828
{
29+
/* calculate cumulative stats before any clear */
30+
_allocationBytesCumulative += bytesAllocated();
31+
32+
2933
#if defined(OMR_GC_THREAD_LOCAL_HEAP)
3034
_tlhRefreshCountFresh = 0;
3135
_tlhRefreshCountReused = 0;

gc/stats/AllocationStats.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MM_AllocationStats : public MM_Base
4949

5050
uintptr_t _allocationCount;
5151
uintptr_t _allocationBytes;
52+
uintptr_t _allocationBytesCumulative; /**< cumulative allocation up to last clear, excluding since last clear */
5253
uintptr_t _ownableSynchronizerObjectCount; /**< Number of Ownable Synchronizer Object allocations */
5354
uintptr_t _continuationObjectCount; /**< Number of Continuation Object allocations */
5455
uintptr_t _discardedBytes;
@@ -86,6 +87,18 @@ class MM_AllocationStats : public MM_Base
8687
return totalBytesAllocated;
8788
}
8889

90+
bool bytesAllocatedCumulative(uintptr_t *cumulativeValue) {
91+
if (NULL != cumulativeValue) {
92+
/* sum the values up to last clear and since last clear */
93+
*cumulativeValue = _allocationBytesCumulative + bytesAllocated();
94+
95+
/* return false if overflowing */
96+
return (_allocationBytesCumulative <= *cumulativeValue);
97+
}
98+
99+
return false;
100+
}
101+
89102
MM_AllocationStats() :
90103
#if defined(OMR_GC_THREAD_LOCAL_HEAP)
91104
_tlhRefreshCountFresh(0),

0 commit comments

Comments
 (0)