Atmosphere/libraries/libstratosphere/source/ncm/ncm_memory_report.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

2020-04-14 17:11:51 +00:00
/*
* Copyright (c) Atmosphère-NX
2020-04-14 17:11:51 +00:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
namespace ams::ncm {
void HeapState::Initialize(lmem::HeapHandle heap_handle) {
2021-10-10 07:14:06 +00:00
std::scoped_lock lk(m_mutex);
m_heap_handle = heap_handle;
2020-04-14 17:11:51 +00:00
}
void HeapState::Allocate(size_t size) {
2021-10-10 07:14:06 +00:00
std::scoped_lock lk(m_mutex);
m_total_alloc_size += size;
m_peak_total_alloc_size = std::max(m_total_alloc_size, m_peak_total_alloc_size);
m_peak_alloc_size = std::max(size, m_peak_alloc_size);
2020-04-14 17:11:51 +00:00
}
void HeapState::Free(size_t size) {
2021-10-10 07:14:06 +00:00
std::scoped_lock lk(m_mutex);
m_total_alloc_size -= size;
2020-04-14 17:11:51 +00:00
}
void HeapState::GetMemoryResourceState(MemoryResourceState *out) {
*out = {};
2021-10-10 07:14:06 +00:00
std::scoped_lock lk(m_mutex);
out->peak_total_alloc_size = m_peak_total_alloc_size;
out->peak_alloc_size = m_peak_alloc_size;
out->total_free_size = lmem::GetExpHeapTotalFreeSize(m_heap_handle);
out->allocatable_size = lmem::GetExpHeapAllocatableSize(m_heap_handle, alignof(s32));
2020-04-14 17:11:51 +00:00
}
HeapState &GetHeapState() {
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(HeapState, s_heap_state);
2020-04-14 17:11:51 +00:00
return s_heap_state;
}
}