Add Tracy memory instrumentation

Does not capture C++17 aligned new/delete.
This commit is contained in:
Eidolon 2023-09-18 16:17:04 -05:00
parent 42e5646c15
commit 17f6f9297a
2 changed files with 17 additions and 0 deletions

View file

@ -355,3 +355,16 @@ int main(int argc, char **argv)
}
#endif
void* operator new(size_t count)
{
auto p = malloc(count);
TracyAlloc(p, count);
return p;
}
void operator delete(void* ptr)
{
TracyFree(ptr);
free(ptr);
}

View file

@ -25,6 +25,8 @@
/// allocator was fragmenting badly. Finally, this version is a bit
/// simpler (about half the lines of code).
#include <tracy/tracy/TracyC.h>
#include "doomdef.h"
#include "doomstat.h"
#include "r_patch.h"
@ -200,6 +202,7 @@ void Z_Free2(void *ptr, const char *file, INT32 line)
*block->user = NULL;
// Free the memory and get rid of the block.
TracyCFree(block->real);
free(block->real);
#ifdef VALGRIND_DESTROY_MEMPOOL
VALGRIND_DESTROY_MEMPOOL(block);
@ -273,6 +276,7 @@ void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits,
padsize += (1<<sizeof(size_t))*2;
#endif
ptr = xm(blocksize + padsize*2);
TracyCAlloc(ptr, blocksize);
// This horrible calculation makes sure that "given" is aligned
// properly.