Skip to content
Snippets Groups Projects
Commit 647d0224 authored by David Parks's avatar David Parks
Browse files

SL-16243 Add Tracy timers to global new/delete overrides.

parent a5b1c013
No related branches found
No related tags found
1 merge request!83Merge Linden 6.6.7
...@@ -33,11 +33,22 @@ ...@@ -33,11 +33,22 @@
#include "lltracethreadrecorder.h" #include "lltracethreadrecorder.h"
#include "llcleanup.h" #include "llcleanup.h"
thread_local bool gProfilerEnabled = false;
#if (TRACY_ENABLE) #if (TRACY_ENABLE)
// Override new/delete for tracy memory profiling // Override new/delete for tracy memory profiling
void *operator new(size_t size) 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) if (!ptr)
{ {
throw std::bad_alloc(); throw std::bad_alloc();
...@@ -49,8 +60,17 @@ void *operator new(size_t size) ...@@ -49,8 +60,17 @@ void *operator new(size_t size)
void operator delete(void *ptr) noexcept void operator delete(void *ptr) noexcept
{ {
TracyFree(ptr); TracyFree(ptr);
if (gProfilerEnabled)
{
LL_PROFILE_ZONE_SCOPED;
(free)(ptr); (free)(ptr);
} }
else
{
(free)(ptr);
}
}
// C-style malloc/free can't be so easily overridden, so we define tracy versions and use // 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 // a pre-processor #define in linden_common.h to redirect to them. The parens around the native
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#define LL_PROFILER_CONFIGURATION LL_PROFILER_CONFIG_FAST_TIMER #define LL_PROFILER_CONFIGURATION LL_PROFILER_CONFIG_FAST_TIMER
#endif #endif
extern thread_local bool gProfilerEnabled;
#if defined(LL_PROFILER_CONFIGURATION) && (LL_PROFILER_CONFIGURATION > LL_PROFILER_CONFIG_NONE) #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 #if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY || LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER
#define TRACY_ENABLE 1 #define TRACY_ENABLE 1
...@@ -52,7 +54,7 @@ ...@@ -52,7 +54,7 @@
#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY #if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY
#define LL_PROFILER_FRAME_END FrameMark #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_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(name) ZoneNamedN( ___tracy_scoped_zone, name, true );
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB #define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
...@@ -82,7 +84,7 @@ ...@@ -82,7 +84,7 @@
#endif #endif
#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER #if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER
#define LL_PROFILER_FRAME_END FrameMark #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_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(name) ZoneNamedN( ___tracy_scoped_zone, #name, true );
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB #define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
......
...@@ -325,7 +325,8 @@ int APIENTRY WINMAIN(HINSTANCE hInstance, ...@@ -325,7 +325,8 @@ int APIENTRY WINMAIN(HINSTANCE hInstance,
{ {
// Call Tracy first thing to have it allocate memory // Call Tracy first thing to have it allocate memory
// https://github.com/wolfpld/tracy/issues/196 // 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; const S32 MAX_HEAPS = 255;
DWORD heap_enable_lfh_error[MAX_HEAPS]; DWORD heap_enable_lfh_error[MAX_HEAPS];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment