From 6eac082ad27f2ac6fd2b6a343966781c7bde202f Mon Sep 17 00:00:00 2001 From: Geraint Luff Date: Tue, 7 Jan 2025 18:11:51 +0000 Subject: [PATCH] Add memory stats --- cmd/main.cpp | 10 +++++++--- cmd/util/{memory-tracker.cpp => memory-tracker.hxx} | 0 2 files changed, 7 insertions(+), 3 deletions(-) rename cmd/util/{memory-tracker.cpp => memory-tracker.hxx} (100%) diff --git a/cmd/main.cpp b/cmd/main.cpp index a8915b8..74e125e 100644 --- a/cmd/main.cpp +++ b/cmd/main.cpp @@ -6,7 +6,8 @@ #include "../signalsmith-stretch.h" #include "util/simple-args.h" #include "util/wav.h" -#include "util/memory-tracker.h" + +#include "util/memory-tracker.hxx" int main(int argc, char* argv[]) { SimpleArgs args(argc, argv); @@ -40,7 +41,7 @@ int main(int argc, char* argv[]) { stretch.setTransposeSemitones(semitones, tonality/inWav.sampleRate); memory = memory.diff(); - std::cout << "Setup (alloc/free/current):\t" << memory.allocBytes << "/" << memory.freeBytes << "/" << memory.currentBytes << "\n"; + std::cout << "Memory: allocated " << (memory.allocBytes/1000) << "kB, freed " << (memory.freeBytes/1000) << "kB\n"; // pad the input at the end, since we'll be reading slightly ahead size_t paddedInputLength = inputLength + stretch.inputLatency(); @@ -61,7 +62,10 @@ int main(int argc, char* argv[]) { stretch.process(inWav, inputLength, outWav, outputLength); processMemory = processMemory.diff(); - std::cout << "Processing (alloc/free/current):\t" << processMemory.allocBytes << "/" << processMemory.freeBytes << "/" << processMemory.currentBytes << "\n"; + if (processMemory.allocBytes + processMemory.freeBytes > 0) { + std::cout << "Processing (alloc/free/current):\t" << processMemory.allocBytes << "/" << processMemory.freeBytes << "/" << processMemory.currentBytes << "\n"; + args.errorExit("allocated during process()"); + } // Read the last bit of output without giving it any more input outWav.offset += outputLength; diff --git a/cmd/util/memory-tracker.cpp b/cmd/util/memory-tracker.hxx similarity index 100% rename from cmd/util/memory-tracker.cpp rename to cmd/util/memory-tracker.hxx