Heap usage profiling
Currently the in-game profiler shows the number of memory allocations per frame in each profile node (at least when compiled with MSVC and the Debug CRT). It might be nice to also show the total amount of still-allocated memory that has ever been allocated under a particular node, to see which bits are responsible for using lots of memory.
I expect that could be done without much pain by using _CrtSetAllocHook to catch allocations and frees: allocations can be added to the count in the current profile node, and some kind of map can store the allocation request number and the current node (I'm hoping you can remember nodes like that), and frees can look up the appropriate node to subtract the size from (because we don't want to count freed memory, and because it's not necessarily going to be freed in the same place as it was allocated). That'd be a little slow, so it should be optional and disabled by default.
Change History
(12)
Milestone: |
Beta → Backlog
|
Keywords: |
patch added
|
Summary: |
Heap usage profiling → [PATCH] Heap usage profiling
|
Milestone: |
Backlog → Alpha 15
|
Milestone: |
Alpha 15 → Backlog
|
Keywords: |
patch removed
|
Summary: |
[PATCH] Heap usage profiling → Heap usage profiling
|
Description: |
modified (diff)
|
Milestone: |
Backlog
|
Resolution: |
→ wontfix
|
Status: |
new → closed
|
I extended the hooked malloc/.../free (USE_GLIBC_MALLOC_OVERRIDE) and build a global map to include the allocated memory address, the current profiler node and the memory size. The free can than call the matching node to subtract the size.
The first problem was the recursive call to allocate/free memory for the map. I build some guard, so only the first call gets proccessed. (We dont want to keep track of the memory actually used in the map.)
Another one was the StructuralReset invalidating all node pointers.
Mutex must be used to be safe with multiple threads.
Its neither very clean nor very fast. But it is usable. (As a patch; to make it build on other platforms some preprocessors need to be added.)