From f2d4f83931f77282d6cdeba582def46b51c22b89 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Wed, 15 Sep 2021 10:11:25 -0600 Subject: SL-15962 Add hooks for tracy memory profiling --- indra/llcommon/llcommon.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'indra/llcommon/llcommon.cpp') 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; -- cgit v1.2.3 From 548bfda290b556d3ab29cc8c2f810f4cc349c9d8 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 28 Sep 2021 16:53:04 -0400 Subject: SL-16040: operator new() must never return nullptr. --- indra/llcommon/llcommon.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/llcommon/llcommon.cpp') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index da61e7539a..92f4d569b1 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -34,14 +34,13 @@ #include "llcleanup.h" #if (TRACY_ENABLE) -// Override new/delet for tracy memory profiling +// Override new/delete 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; -- cgit v1.2.3 From db86ec9176dcbfabe5fddb3603da4132443f8b7f Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 28 Sep 2021 22:09:02 -0400 Subject: SL-16040: _aligned_malloc() and _aligned_free() are Microsoft only. Fortunately we already have platform-independent wrappers in llmemory.h. --- indra/llcommon/llcommon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llcommon.cpp') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 92f4d569b1..5d4a623bf6 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -61,7 +61,7 @@ void operator delete(void *ptr) noexcept void *tracy_aligned_malloc(size_t size, size_t alignment) { - auto ptr = (_aligned_malloc) (size, alignment); + auto ptr = ll_aligned_malloc_fallback(size, alignment); if (ptr) TracyAlloc(ptr, size); return ptr; } @@ -69,7 +69,7 @@ void *tracy_aligned_malloc(size_t size, size_t alignment) void tracy_aligned_free(void *memblock) { TracyFree(memblock); - (_aligned_free)(memblock); + ll_aligned_free_fallback(memblock); } #endif -- cgit v1.2.3 From 647d0224d321c706ba5936905db4265becde9d8e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 25 Oct 2021 21:11:03 +0000 Subject: SL-16243 Add Tracy timers to global new/delete overrides. --- indra/llcommon/llcommon.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llcommon.cpp') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 5d4a623bf6..abc6af2cfc 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -33,11 +33,22 @@ #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) { - auto ptr = (malloc) (size); + void* ptr; + if (gProfilerEnabled) + { + LL_PROFILE_ZONE_SCOPED; + ptr = (malloc)(size); + } + else + { + ptr = (malloc)(size); + } if (!ptr) { throw std::bad_alloc(); @@ -49,7 +60,16 @@ void *operator new(size_t size) void operator delete(void *ptr) noexcept { TracyFree(ptr); - (free)(ptr); + + if (gProfilerEnabled) + { + LL_PROFILE_ZONE_SCOPED; + (free)(ptr); + } + else + { + (free)(ptr); + } } // C-style malloc/free can't be so easily overridden, so we define tracy versions and use -- cgit v1.2.3 From 4e8cd9437bed90b3468b1bf12f545de16faefb67 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 26 Oct 2021 14:07:00 +0000 Subject: SL-16193 Fix for mesh selection outline not rendering correctly (and broken physics shapes display). --- indra/llcommon/llcommon.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/llcommon/llcommon.cpp') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index abc6af2cfc..04872564bf 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -44,6 +44,7 @@ void *operator new(size_t size) { LL_PROFILE_ZONE_SCOPED; ptr = (malloc)(size); + TracyAlloc(ptr, size); } else { @@ -53,17 +54,15 @@ void *operator new(size_t size) { throw std::bad_alloc(); } - TracyAlloc(ptr, size); return ptr; } void operator delete(void *ptr) noexcept { - TracyFree(ptr); - if (gProfilerEnabled) { LL_PROFILE_ZONE_SCOPED; + TracyFree(ptr); (free)(ptr); } else -- cgit v1.2.3 From c907d067f41930bd6a4bbef9903febfab1090982 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Tue, 26 Oct 2021 09:23:17 -0500 Subject: SL-16243 Followup -- fix for inconsistently calling TracyAlloc/TracyFree --- indra/llcommon/llcommon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llcommon.cpp') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 04872564bf..25a809dad2 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -44,7 +44,6 @@ void *operator new(size_t size) { LL_PROFILE_ZONE_SCOPED; ptr = (malloc)(size); - TracyAlloc(ptr, size); } else { @@ -54,15 +53,16 @@ void *operator new(size_t size) { throw std::bad_alloc(); } + TracyAlloc(ptr, size); return ptr; } void operator delete(void *ptr) noexcept { + TracyFree(ptr); if (gProfilerEnabled) { LL_PROFILE_ZONE_SCOPED; - TracyFree(ptr); (free)(ptr); } else -- cgit v1.2.3 From 9f2be2a0547f5e827a91cbcd9162cbe8f9cdfb53 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 13 Jan 2022 12:25:21 -0800 Subject: SL-16606: Add profiler category MEMORY --- indra/llcommon/llcommon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llcommon.cpp') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 25a809dad2..d2c4e66160 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -42,7 +42,7 @@ void *operator new(size_t size) void* ptr; if (gProfilerEnabled) { - LL_PROFILE_ZONE_SCOPED; + LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; ptr = (malloc)(size); } else @@ -62,7 +62,7 @@ void operator delete(void *ptr) noexcept TracyFree(ptr); if (gProfilerEnabled) { - LL_PROFILE_ZONE_SCOPED; + LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; (free)(ptr); } else -- cgit v1.2.3