comparison Platforms/Wasm/Defaults.cpp @ 877:f7e5ee59ba17 am-dev

debug code to monitor large malloc/free (currently disabled)
author Alain Mazy <alain@mazy.be>
date Wed, 03 Jul 2019 10:16:22 +0200
parents 238693c3bc51
children 8f7930f589ef
comparison
equal deleted inserted replaced
876:580dd82e13f5 877:f7e5ee59ba17
38 } 38 }
39 39
40 #ifdef __cplusplus 40 #ifdef __cplusplus
41 extern "C" { 41 extern "C" {
42 #endif 42 #endif
43
44 #if 0
45 size_t bigChunksTotalSize = 0;
46 std::map<void*, size_t> allocatedBigChunks;
47
48 extern void* emscripten_builtin_malloc(size_t bytes);
49 extern void emscripten_builtin_free(void* mem);
50
51 void * __attribute__((noinline)) malloc(size_t size)
52 {
53 void *ptr = emscripten_builtin_malloc(size);
54 if (size > 100000)
55 {
56 bigChunksTotalSize += size;
57 printf("++ Allocated %zu bytes, got %p. (%zu MB consumed by big chunks)\n", size, ptr, bigChunksTotalSize/(1024*1024));
58 allocatedBigChunks[ptr] = size;
59 }
60 return ptr;
61 }
62
63 void __attribute__((noinline)) free(void *ptr)
64 {
65 emscripten_builtin_free(ptr);
66
67 std::map<void*, size_t>::iterator it = allocatedBigChunks.find(ptr);
68 if (it != allocatedBigChunks.end())
69 {
70 bigChunksTotalSize -= it->second;
71 printf("-- Freed %zu bytes at %p. (%zu MB consumed by big chunks)\n", it->second, ptr, bigChunksTotalSize/(1024*1024));
72 allocatedBigChunks.erase(it);
73 }
74 }
75 #endif // 0
43 76
44 using namespace OrthancStone; 77 using namespace OrthancStone;
45 78
46 // when WASM needs a C++ viewport 79 // when WASM needs a C++ viewport
47 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { 80 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() {