32 MonitorAdaptor() noexcept =
default;
33 ~MonitorAdaptor() noexcept
override { performanceReport(); }
36 void allocCalled(
size_t iRequested,
size_t iActual)
final {
37 nAllocations_.fetch_add(1, std::memory_order_acq_rel);
38 requested_.fetch_add(iRequested, std::memory_order_acq_rel);
40 auto a = presentActual_.fetch_add(iActual, std::memory_order_acq_rel);
42 auto max = maxActual_.load(std::memory_order_relaxed);
45 if (maxActual_.compare_exchange_strong(
max,
a, std::memory_order_acq_rel)) {
51 nDeallocations_.fetch_add(1, std::memory_order_acq_rel);
52 auto present = presentActual_.load(std::memory_order_acquire);
53 if (present >= iActual) {
54 presentActual_.fetch_sub(iActual, std::memory_order_acq_rel);
58 void performanceReport()
const {
59 auto finalRequested = requested_.load(std::memory_order_acquire);
60 auto maxActual = maxActual_.load(std::memory_order_acquire);
61 auto present = presentActual_.load(std::memory_order_acquire);
62 auto allocs = nAllocations_.load(std::memory_order_acquire);
63 auto deallocs = nDeallocations_.load(std::memory_order_acquire);
66 <<
"\n total memory requested: " << finalRequested <<
"\n max memory used: " << maxActual
67 <<
"\n presently used: " << present <<
"\n # allocations calls: " << allocs
68 <<
"\n # deallocations calls: " << deallocs <<
"\n";
72 std::atomic<size_t> requested_ = 0;
73 std::atomic<size_t> presentActual_ = 0;
74 std::atomic<size_t> maxActual_ = 0;
75 std::atomic<size_t> nAllocations_ = 0;
76 std::atomic<size_t> nDeallocations_ = 0;
79 [[maybe_unused]]
auto const*
const s_instance =