2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H
32 #define CDSLIB_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H
34 #include <cds/algo/atomic.h>
36 namespace cds { namespace memory { namespace michael {
38 /// Statistics for large (allocated directly from %OS) block
39 struct os_allocated_atomic
42 atomics::atomic<size_t> nAllocCount ; ///< Event count of large block allocation from %OS
43 atomics::atomic<size_t> nFreeCount ; ///< Event count of large block deallocation to %OS
44 atomics::atomic<unsigned long long> nBytesAllocated ; ///< Total size of allocated large blocks, in bytes
45 atomics::atomic<unsigned long long> nBytesDeallocated ; ///< Total size of deallocated large blocks, in bytes
51 , nBytesDeallocated(0)
55 /// Adds \p nSize to nBytesAllocated counter
56 void incBytesAllocated( size_t nSize )
58 nAllocCount.fetch_add( 1, atomics::memory_order_relaxed);
59 nBytesAllocated.fetch_add( nSize, atomics::memory_order_relaxed );
62 /// Adds \p nSize to nBytesDeallocated counter
63 void incBytesDeallocated( size_t nSize )
65 nFreeCount.fetch_add( 1, atomics::memory_order_relaxed );
66 nBytesDeallocated.fetch_add( nSize, atomics::memory_order_relaxed );
69 /// Returns count of \p alloc and \p alloc_aligned function call (for large block allocated directly from %OS)
70 size_t allocCount() const
72 return nAllocCount.load(atomics::memory_order_relaxed);
75 /// Returns count of \p free and \p free_aligned function call (for large block allocated directly from %OS)
76 size_t freeCount() const
78 return nFreeCount.load(atomics::memory_order_relaxed);
81 /// Returns current value of nBytesAllocated counter
82 uint64_t allocatedBytes() const
84 return nBytesAllocated.load(atomics::memory_order_relaxed);
87 /// Returns current value of nBytesAllocated counter
88 uint64_t deallocatedBytes() const
90 return nBytesDeallocated.load(atomics::memory_order_relaxed);
94 /// Dummy statistics for large (allocated directly from %OS) block
96 This class does not gather any statistics.
97 Class interface is the same as \ref os_allocated_atomic.
99 struct os_allocated_empty
102 /// Adds \p nSize to nBytesAllocated counter
103 void incBytesAllocated( size_t nSize )
104 { CDS_UNUSED(nSize); }
106 /// Adds \p nSize to nBytesDeallocated counter
107 void incBytesDeallocated( size_t nSize )
108 { CDS_UNUSED(nSize); }
110 /// Returns count of \p alloc and \p alloc_aligned function call (for large block allocated directly from OS)
111 size_t allocCount() const
116 /// Returns count of \p free and \p free_aligned function call (for large block allocated directly from OS)
117 size_t freeCount() const
122 /// Returns current value of nBytesAllocated counter
123 uint64_t allocatedBytes() const
128 /// Returns current value of nBytesAllocated counter
129 uint64_t deallocatedBytes() const
137 }}} // namespace cds::memory::michael
139 #endif /// CDSLIB_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H