summaryrefslogtreecommitdiff
path: root/indra/llcommon/llcommon.cpp
diff options
context:
space:
mode:
authorBrad Payne (Vir Linden) <vir@lindenlab.com>2021-10-22 18:11:48 +0100
committerBrad Payne (Vir Linden) <vir@lindenlab.com>2021-10-22 18:11:48 +0100
commite5cd9cb90f74c46ad59ba697bb70e7a425bf631d (patch)
tree35cf0536f89af885f670a3b788ff534667ce656a /indra/llcommon/llcommon.cpp
parent910daee8887b41619b07a1e5c4431f77c095dac5 (diff)
parentda183230b0f08d50ad35330fc8ef51307a8b6f84 (diff)
merge
Diffstat (limited to 'indra/llcommon/llcommon.cpp')
-rw-r--r--indra/llcommon/llcommon.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp
index 96be913d17..5d4a623bf6 100644
--- a/indra/llcommon/llcommon.cpp
+++ b/indra/llcommon/llcommon.cpp
@@ -33,6 +33,47 @@
#include "lltracethreadrecorder.h"
#include "llcleanup.h"
+#if (TRACY_ENABLE)
+// Override new/delete for tracy memory profiling
+void *operator new(size_t size)
+{
+ auto ptr = (malloc) (size);
+ if (!ptr)
+ {
+ throw std::bad_alloc();
+ }
+ TracyAlloc(ptr, size);
+ return ptr;
+}
+
+void operator delete(void *ptr) noexcept
+{
+ TracyFree(ptr);
+ (free)(ptr);
+}
+
+// C-style malloc/free can't be so easily overridden, so we define tracy versions and use
+// a pre-processor #define in linden_common.h to redirect to them. The parens around the native
+// functions below prevents recursive substitution by the preprocessor.
+//
+// Unaligned mallocs are rare in LL code but hooking them causes problems in 3p lib code (looking at
+// you, Havok), so we'll only capture the aligned version.
+
+void *tracy_aligned_malloc(size_t size, size_t alignment)
+{
+ auto ptr = ll_aligned_malloc_fallback(size, alignment);
+ if (ptr) TracyAlloc(ptr, size);
+ return ptr;
+}
+
+void tracy_aligned_free(void *memblock)
+{
+ TracyFree(memblock);
+ ll_aligned_free_fallback(memblock);
+}
+
+#endif
+
//static
BOOL LLCommon::sAprInitialized = FALSE;