3 #ifndef __CDS_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H
4 #define __CDS_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H
6 #include <cds/cxx11_atomic.h>
8 namespace cds { namespace memory { namespace michael {
10 /// Statistics for large (allocated directly from %OS) block
11 struct os_allocated_atomic
14 atomics::atomic<size_t> nAllocCount ; ///< Event count of large block allocation from %OS
15 atomics::atomic<size_t> nFreeCount ; ///< Event count of large block deallocation to %OS
16 atomics::atomic<unsigned long long> nBytesAllocated ; ///< Total size of allocated large blocks, in bytes
17 atomics::atomic<unsigned long long> nBytesDeallocated ; ///< Total size of deallocated large blocks, in bytes
23 , nBytesDeallocated(0)
27 /// Adds \p nSize to nBytesAllocated counter
28 void incBytesAllocated( size_t nSize )
30 nAllocCount.fetch_add( 1, atomics::memory_order_relaxed);
31 nBytesAllocated.fetch_add( nSize, atomics::memory_order_relaxed );
34 /// Adds \p nSize to nBytesDeallocated counter
35 void incBytesDeallocated( size_t nSize )
37 nFreeCount.fetch_add( 1, atomics::memory_order_relaxed );
38 nBytesDeallocated.fetch_add( nSize, atomics::memory_order_relaxed );
41 /// Returns count of \p alloc and \p alloc_aligned function call (for large block allocated directly from %OS)
42 size_t allocCount() const
44 return nAllocCount.load(atomics::memory_order_relaxed);
47 /// Returns count of \p free and \p free_aligned function call (for large block allocated directly from %OS)
48 size_t freeCount() const
50 return nFreeCount.load(atomics::memory_order_relaxed);
53 /// Returns current value of nBytesAllocated counter
54 atomic64u_t allocatedBytes() const
56 return nBytesAllocated.load(atomics::memory_order_relaxed);
59 /// Returns current value of nBytesAllocated counter
60 atomic64u_t deallocatedBytes() const
62 return nBytesDeallocated.load(atomics::memory_order_relaxed);
66 /// Dummy statistics for large (allocated directly from %OS) block
68 This class does not gather any statistics.
69 Class interface is the same as \ref os_allocated_atomic.
71 struct os_allocated_empty
74 /// Adds \p nSize to nBytesAllocated counter
75 void incBytesAllocated( size_t nSize )
76 { CDS_UNUSED(nSize); }
78 /// Adds \p nSize to nBytesDeallocated counter
79 void incBytesDeallocated( size_t nSize )
80 { CDS_UNUSED(nSize); }
82 /// Returns count of \p alloc and \p alloc_aligned function call (for large block allocated directly from OS)
83 size_t allocCount() const
88 /// Returns count of \p free and \p free_aligned function call (for large block allocated directly from OS)
89 size_t freeCount() const
94 /// Returns current value of nBytesAllocated counter
95 atomic64u_t allocatedBytes() const
100 /// Returns current value of nBytesAllocated counter
101 atomic64u_t deallocatedBytes() const
109 }}} // namespace cds::memory::michael
111 #endif /// __CDS_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H