summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2021-10-25 21:11:03 +0000
committerDave Parks <davep@lindenlab.com>2021-10-25 21:11:03 +0000
commit647d0224d321c706ba5936905db4265becde9d8e (patch)
tree3a9e1ddcd167d443c6f4e702b61cf68d522e704e /indra
parenta5b1c013542d93be3b4cac820f32000fa5e3cfd4 (diff)
SL-16243 Add Tracy timers to global new/delete overrides.
Diffstat (limited to 'indra')
-rw-r--r--indra/llcommon/llcommon.cpp24
-rw-r--r--indra/llcommon/llprofiler.h6
-rw-r--r--indra/newview/llappviewerwin32.cpp3
3 files changed, 28 insertions, 5 deletions
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
diff --git a/indra/llcommon/llprofiler.h b/indra/llcommon/llprofiler.h
index 49510df913..e36f693dd3 100644
--- a/indra/llcommon/llprofiler.h
+++ b/indra/llcommon/llprofiler.h
@@ -36,6 +36,8 @@
#define LL_PROFILER_CONFIGURATION LL_PROFILER_CONFIG_FAST_TIMER
#endif
+extern thread_local bool gProfilerEnabled;
+
#if defined(LL_PROFILER_CONFIGURATION) && (LL_PROFILER_CONFIGURATION > LL_PROFILER_CONFIG_NONE)
#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY || LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER
#define TRACY_ENABLE 1
@@ -52,7 +54,7 @@
#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY
#define LL_PROFILER_FRAME_END FrameMark
- #define LL_PROFILER_SET_THREAD_NAME( name ) tracy::SetThreadName( name )
+ #define LL_PROFILER_SET_THREAD_NAME( name ) tracy::SetThreadName( name ); gProfilerEnabled = true;
#define LL_RECORD_BLOCK_TIME(name) ZoneScoped // Want descriptive names; was: ZoneNamedN( ___tracy_scoped_zone, #name, true );
#define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, true );
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
@@ -82,7 +84,7 @@
#endif
#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER
#define LL_PROFILER_FRAME_END FrameMark
- #define LL_PROFILER_SET_THREAD_NAME( name ) tracy::SetThreadName( name )
+ #define LL_PROFILER_SET_THREAD_NAME( name ) tracy::SetThreadName( name ); gProfilerEnabled = true;
#define LL_RECORD_BLOCK_TIME(name) ZoneScoped const LLTrace::BlockTimer& LL_GLUE_TOKENS(block_time_recorder, __LINE__)(LLTrace::timeThisBlock(name)); (void)LL_GLUE_TOKENS(block_time_recorder, __LINE__);
#define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, #name, true );
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp
index 758bd73cb0..9074e6a6cf 100644
--- a/indra/newview/llappviewerwin32.cpp
+++ b/indra/newview/llappviewerwin32.cpp
@@ -325,7 +325,8 @@ int APIENTRY WINMAIN(HINSTANCE hInstance,
{
// Call Tracy first thing to have it allocate memory
// https://github.com/wolfpld/tracy/issues/196
- LL_PROFILER_FRAME_END
+ LL_PROFILER_FRAME_END;
+ LL_PROFILER_SET_THREAD_NAME("App");
const S32 MAX_HEAPS = 255;
DWORD heap_enable_lfh_error[MAX_HEAPS];