Skip to content

Commit

Permalink
feat(tests): Display memory allocations and leaks.
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Nana <[email protected]>
  • Loading branch information
na2axl committed Oct 27, 2024
1 parent ce6296d commit 84179ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Core/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace SparkyStudios::Audio::Amplitude

void MemoryManager::Initialize(std::unique_ptr<MemoryAllocator> allocator)
{
if (gMemManager == nullptr)
if (!IsInitialized())
gMemManager = new MemoryManager(std::move(allocator));

#if !defined(AM_NO_MEMORY_STATS)
Expand Down
27 changes: 27 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ struct AmTestListener : Catch::EventListenerBase

CATCH_REGISTER_LISTENER(AmTestListener)

#if !defined(AM_NO_MEMORY_STATS)
static void printMemoryStats()
{
std::vector<eMemoryPoolKind> pools = {
eMemoryPoolKind_Amplimix, eMemoryPoolKind_Codec, eMemoryPoolKind_Engine, eMemoryPoolKind_Filtering,
eMemoryPoolKind_SoundData, eMemoryPoolKind_IO, eMemoryPoolKind_Default,
};

for (auto&& kind : pools)
{
const auto& stats = amMemory->GetStats(kind);

std::cout << "Pool Name - " << MemoryManager::GetMemoryPoolName(kind) << std::endl;
std::cout << " Allocations Count: " << stats.allocCount << std::endl;
std::cout << " Frees Count: " << stats.freeCount << std::endl;
std::cout << " Total Memory used: " << stats.maxMemoryUsed << std::endl;
std::cout << std::endl;
}
}
#endif

int main(int argc, char* argv[])
{
ConsoleLogger logger;
Expand All @@ -113,6 +134,12 @@ int main(int argc, char* argv[])

const auto res = Catch::Session().run(argc, argv);

#if !defined(AM_NO_MEMORY_STATS)
printMemoryStats();

amLogInfo("%s", amMemory->InspectMemoryLeaks().c_str());
#endif

MemoryManager::Deinitialize();

return res;
Expand Down

0 comments on commit 84179ea

Please sign in to comment.