# HG changeset patch # User Alain Mazy # Date 1562141782 -7200 # Node ID f7e5ee59ba17f9959a2fd92295781665f57a6003 # Parent 580dd82e13f5627f3c2f0d9eb7bb630256589eb1 debug code to monitor large malloc/free (currently disabled) diff -r 580dd82e13f5 -r f7e5ee59ba17 Platforms/Wasm/Defaults.cpp --- a/Platforms/Wasm/Defaults.cpp Wed Jul 03 10:15:29 2019 +0200 +++ b/Platforms/Wasm/Defaults.cpp Wed Jul 03 10:16:22 2019 +0200 @@ -41,6 +41,39 @@ extern "C" { #endif +#if 0 + size_t bigChunksTotalSize = 0; + std::map allocatedBigChunks; + + extern void* emscripten_builtin_malloc(size_t bytes); + extern void emscripten_builtin_free(void* mem); + + void * __attribute__((noinline)) malloc(size_t size) + { + void *ptr = emscripten_builtin_malloc(size); + if (size > 100000) + { + bigChunksTotalSize += size; + printf("++ Allocated %zu bytes, got %p. (%zu MB consumed by big chunks)\n", size, ptr, bigChunksTotalSize/(1024*1024)); + allocatedBigChunks[ptr] = size; + } + return ptr; + } + + void __attribute__((noinline)) free(void *ptr) + { + emscripten_builtin_free(ptr); + + std::map::iterator it = allocatedBigChunks.find(ptr); + if (it != allocatedBigChunks.end()) + { + bigChunksTotalSize -= it->second; + printf("-- Freed %zu bytes at %p. (%zu MB consumed by big chunks)\n", it->second, ptr, bigChunksTotalSize/(1024*1024)); + allocatedBigChunks.erase(it); + } + } +#endif // 0 + using namespace OrthancStone; // when WASM needs a C++ viewport