diff options
author | Euclid Linden <euclid@lindenlab.com> | 2022-05-27 21:15:49 +0000 |
---|---|---|
committer | Euclid Linden <euclid@lindenlab.com> | 2022-05-27 21:15:49 +0000 |
commit | 3f98411c56f4daa06c9102346a8dd37af18d2cb6 (patch) | |
tree | 4255c2827cc3e07921275bfd7937f4f43f29d5fa /indra/llcommon/llcommon.cpp | |
parent | 3f58ec2fdfb76ce2160884a3e97be49f60b6ac90 (diff) | |
parent | 02c71b0ac2f99dd1c26a649ffce2182b2fc9a7d9 (diff) |
Merged in DV528-merge-6.6.1 (pull request #1000)
DRTVWR-528 merge up to 6.6.1
Diffstat (limited to 'indra/llcommon/llcommon.cpp')
-rw-r--r-- | indra/llcommon/llcommon.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 96be913d17..d2c4e66160 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -33,6 +33,66 @@ #include "lltracethreadrecorder.h" #include "llcleanup.h" +thread_local bool gProfilerEnabled = false; + +#if (TRACY_ENABLE) +// Override new/delete for tracy memory profiling +void *operator new(size_t size) +{ + void* ptr; + if (gProfilerEnabled) + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; + ptr = (malloc)(size); + } + else + { + ptr = (malloc)(size); + } + if (!ptr) + { + throw std::bad_alloc(); + } + TracyAlloc(ptr, size); + return ptr; +} + +void operator delete(void *ptr) noexcept +{ + TracyFree(ptr); + if (gProfilerEnabled) + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; + (free)(ptr); + } + else + { + (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; |