summaryrefslogtreecommitdiff
path: root/indra/llcommon/llcommon.cpp
diff options
context:
space:
mode:
authorBrad Payne (Vir Linden) <vir@lindenlab.com>2021-09-29 11:09:15 +0100
committerBrad Payne (Vir Linden) <vir@lindenlab.com>2021-09-29 11:09:15 +0100
commit7868ba0c60ff762f56180121fd117e350767934e (patch)
treef5f5148d9c85a79c5be4e962fad77b4986da57a5 /indra/llcommon/llcommon.cpp
parent04e1962d48e36f9055f0d893fc1b7a97d9e334c6 (diff)
parent675514bdb372c25b50dd2c42b06633895c86b8ce (diff)
Merge branch 'DRTVWR-546' of ssh://bitbucket.org/lindenlab/viewer into DRTVWR-546
Diffstat (limited to 'indra/llcommon/llcommon.cpp')
-rw-r--r--indra/llcommon/llcommon.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp
index 96be913d17..da61e7539a 100644
--- a/indra/llcommon/llcommon.cpp
+++ b/indra/llcommon/llcommon.cpp
@@ -33,6 +33,48 @@
#include "lltracethreadrecorder.h"
#include "llcleanup.h"
+#if (TRACY_ENABLE)
+// Override new/delet for tracy memory profiling
+void *operator new(size_t size)
+{
+ auto ptr = (malloc) (size);
+ if (!ptr)
+ {
+ throw std::bad_alloc();
+ return nullptr;
+ }
+ 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 = (_aligned_malloc) (size, alignment);
+ if (ptr) TracyAlloc(ptr, size);
+ return ptr;
+}
+
+void tracy_aligned_free(void *memblock)
+{
+ TracyFree(memblock);
+ (_aligned_free)(memblock);
+}
+
+#endif
+
//static
BOOL LLCommon::sAprInitialized = FALSE;