summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuclid Linden <euclid@lindenlab.com>2021-09-15 20:35:45 +0000
committerEuclid Linden <euclid@lindenlab.com>2021-09-15 20:35:45 +0000
commitc09532ac13a3ca2f1ca0854cf00594a26ddcb593 (patch)
tree3b0b1e87724c1b2ff14ae52c106be22266195608
parenta1a9c02148d8d0537b3736365d4d46b09d9891d2 (diff)
parente6ae2400f3427049020cbf4fb25f7ece841f5586 (diff)
Merged in merge-541 (pull request #686)
Merge to latest 541
-rw-r--r--indra/llcommon/linden_common.h8
-rw-r--r--indra/llcommon/llcommon.cpp42
2 files changed, 50 insertions, 0 deletions
diff --git a/indra/llcommon/linden_common.h b/indra/llcommon/linden_common.h
index 45ac43910c..b2c5be6b76 100644
--- a/indra/llcommon/linden_common.h
+++ b/indra/llcommon/linden_common.h
@@ -27,6 +27,14 @@
#ifndef LL_LINDEN_COMMON_H
#define LL_LINDEN_COMMON_H
+#include "llprofiler.h"
+#if (TRACY_ENABLE) // hooks for memory profiling
+void *tracy_aligned_malloc(size_t size, size_t alignment);
+void tracy_aligned_free(void *memblock);
+#define _aligned_malloc(X, Y) tracy_aligned_malloc((X), (Y))
+#define _aligned_free(X) tracy_aligned_free((X))
+#endif
+
// *NOTE: Please keep includes here to a minimum!
//
// Files included here are included in every library .cpp file and
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;