From 9fe9d92bf37be5246361edd10e3542a75f87e32d Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 17 Jan 2023 15:11:01 -0500
Subject: [PATCH] Start to wire in tracy support

---
 autobuild.xml                         | 22 ++++------------------
 indra/cmake/LLCommon.cmake            |  1 -
 indra/cmake/Tracy.cmake               | 17 ++---------------
 indra/deps/CMakeLists.txt             | 20 ++++++++++++++++++++
 indra/llcommon/CMakeLists.txt         |  3 +--
 indra/llcommon/linden_common.h        |  2 +-
 indra/llcommon/llcommon.cpp           |  2 +-
 indra/llcommon/llframetimer.cpp       |  5 -----
 indra/llcommon/llprofiler.h           | 27 ++++++++++++++-------------
 indra/llcommon/llprofilercategories.h |  8 ++++----
 indra/llcorehttp/_thread.h            |  2 +-
 indra/newview/CMakeLists.txt          |  5 ++---
 12 files changed, 50 insertions(+), 64 deletions(-)

diff --git a/autobuild.xml b/autobuild.xml
index e3cca8e108d..494421ab67f 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -2229,30 +2229,16 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
             <key>name</key>
             <string>darwin64</string>
           </map>
-          <key>windows</key>
-          <map>
-            <key>archive</key>
-            <map>
-              <key>hash</key>
-              <string>47c696cd2966c5cc3c8ba6115dd1f886</string>
-              <key>hash_algorithm</key>
-              <string>md5</string>
-              <key>url</key>
-              <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/86973/801641/tracy-v0.7.8.563351-windows-563351.tar.bz2</string>
-            </map>
-            <key>name</key>
-            <string>windows</string>
-          </map>
           <key>windows64</key>
           <map>
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>b649ee6591e67d2341e886b3fc3484a7</string>
+              <string>773e2803356980515b066dd668fad9cee0d7dfe29bc1b29ed690503aed1dde4970300ab21985c6ac70c91318844d0ae088045034627b0cf1dd7efb5b5c1cd6aa</string>
               <key>hash_algorithm</key>
-              <string>md5</string>
+              <string>blake2b</string>
               <key>url</key>
-              <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/86974/801642/tracy-v0.7.8.563351-windows64-563351.tar.bz2</string>
+              <string>https://git.alchemyviewer.org/api/v4/projects/201/packages/generic/tracy/v0.9.0.1868/tracy-v0.9.0-windows64-1868.tar.zst</string>
             </map>
             <key>name</key>
             <string>windows64</string>
@@ -2263,7 +2249,7 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
         <key>source_type</key>
         <string>git</string>
         <key>version</key>
-        <string>v0.7.8.563351</string>
+        <string>v0.9.0</string>
       </map>
       <key>tut</key>
       <map>
diff --git a/indra/cmake/LLCommon.cmake b/indra/cmake/LLCommon.cmake
index 79811156096..8276820fa79 100644
--- a/indra/cmake/LLCommon.cmake
+++ b/indra/cmake/LLCommon.cmake
@@ -10,7 +10,6 @@ set(LLCOMMON_INCLUDE_DIRS
     ${LIBS_OPEN_DIR}/llcommon
     ${APRUTIL_INCLUDE_DIR}
     ${APR_INCLUDE_DIR}
-    ${TRACY_INCLUDE_DIR}
     ${Boost_INCLUDE_DIRS}
     )
 set(LLCOMMON_SYSTEM_INCLUDE_DIRS
diff --git a/indra/cmake/Tracy.cmake b/indra/cmake/Tracy.cmake
index cfff956bcf8..5cb1ff059ee 100644
--- a/indra/cmake/Tracy.cmake
+++ b/indra/cmake/Tracy.cmake
@@ -4,23 +4,10 @@ include(Prebuilt)
 set(USE_TRACY OFF CACHE BOOL "Use Tracy profiler.")
 
 if (USE_TRACY)
-  set(TRACY_INCLUDE_DIR ${LIBS_PREBUILT_DIR}/include/tracy) 
+  # use_prebuilt_binary(tracy)
 
-# See: indra/llcommon/llprofiler.h
+  # See: indra/llcommon/llprofiler.h
   add_definitions(-DLL_PROFILER_CONFIGURATION=3)
-  use_prebuilt_binary(tracy)
-
-  if (WINDOWS)
-    MESSAGE(STATUS "Including Tracy for Windows: '${TRACY_INCLUDE_DIR}'")
-  endif (WINDOWS)
-
-  if (DARWIN)
-    MESSAGE(STATUS "Including Tracy for Darwin: '${TRACY_INCLUDE_DIR}'")
-  endif (DARWIN)
-
-  if (LINUX)
-    MESSAGE(STATUS "Including Tracy for Linux: '${TRACY_INCLUDE_DIR}'")
-  endif (LINUX)
 else (USE_TRACY)
   # Tracy.cmake should not set LLCOMMON_INCLUDE_DIRS, let LLCommon.cmake do that
   set(TRACY_INCLUDE_DIR "")
diff --git a/indra/deps/CMakeLists.txt b/indra/deps/CMakeLists.txt
index e863e43df72..d931f4d29bd 100644
--- a/indra/deps/CMakeLists.txt
+++ b/indra/deps/CMakeLists.txt
@@ -33,6 +33,8 @@ FetchContent_Declare(
   meshoptimizer
   GIT_REPOSITORY https://git.alchemyviewer.org/alchemy/mirrors/meshoptimizer.git
   GIT_TAG        v0.18
+  GIT_SHALLOW TRUE
+  GIT_PROGRESS TRUE
   )
 # FetchContent_Declare(
 #   Catch2
@@ -43,11 +45,15 @@ FetchContent_Declare(
   fmt
   GIT_REPOSITORY https://github.com/fmtlib/fmt.git
   GIT_TAG        9.1.0
+  GIT_SHALLOW TRUE
+  GIT_PROGRESS TRUE
   )
 FetchContent_Declare(
   nlohmann_json
   GIT_REPOSITORY https://git.alchemyviewer.org/alchemy/mirrors/modernjson.git
   GIT_TAG        v3.11.2
+  GIT_SHALLOW TRUE
+  GIT_PROGRESS TRUE
   )
 
 # #Download the rest of the libraries
@@ -62,5 +68,19 @@ set(JSON_Install OFF CACHE INTERNAL "")
 set(JSON_BuildTests OFF CACHE INTERNAL "")
 FetchContent_MakeAvailable(nlohmann_json)
 
+if(USE_TRACY)
+  FetchContent_Declare (
+    tracy
+    GIT_REPOSITORY https://github.com/wolfpld/tracy.git
+    GIT_TAG v0.9
+    GIT_SHALLOW TRUE
+    GIT_PROGRESS TRUE
+    )
+  set(TRACY_ON_DEMAND ON)
+  set(TRACY_ONLY_LOCALHOST ON)
+  set(TRACY_FIBERS ON)
+  FetchContent_MakeAvailable (tracy)
+endif()
+
 unset(CMAKE_FOLDER)
 unset(CMAKE_POSITION_INDEPENDENT_CODE)
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 3c3eb3a9440..5892925d310 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -21,7 +21,6 @@ include_directories(
     ${LLMATH_INCLUDE_DIRS}
     ${ZLIBNG_INCLUDE_DIRS}
     ${URIPARSER_INCLUDE_DIRS}
-    ${TRACY_INCLUDE_DIR}
     )
 
 # add_executable(lltreeiterators lltreeiterators.cpp)
@@ -313,7 +312,7 @@ target_link_libraries(
     ${URIPARSER_LIBRARIES}
     nlohmann_json::nlohmann_json
     fmt::fmt
-    ${TRACY_LIBRARY}
+    TracyClient
     ${DL_LIBRARY}
     ${RT_LIBRARY}
     )
diff --git a/indra/llcommon/linden_common.h b/indra/llcommon/linden_common.h
index a228fd22be4..b1c5bbaef53 100644
--- a/indra/llcommon/linden_common.h
+++ b/indra/llcommon/linden_common.h
@@ -28,7 +28,7 @@
 #define LL_LINDEN_COMMON_H
 
 #include "llprofiler.h"
-#if TRACY_ENABLE && !defined(LL_PROFILER_ENABLE_TRACY_OPENGL)  // hooks for memory profiling
+#if (TRACY_ENABLE) && LL_PROFILER_ENABLE_TRACY_MEMORY
 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))
diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp
index 1bd38729cfe..11e73298d58 100644
--- a/indra/llcommon/llcommon.cpp
+++ b/indra/llcommon/llcommon.cpp
@@ -35,7 +35,7 @@
 
 thread_local bool gProfilerEnabled = false;
 
-#if (TRACY_ENABLE)
+#if (TRACY_ENABLE) && LL_PROFILER_ENABLE_TRACY_MEMORY
 // Override new/delete for tracy memory profiling
 void *operator new(size_t size)
 {
diff --git a/indra/llcommon/llframetimer.cpp b/indra/llcommon/llframetimer.cpp
index c54029e8b44..1e9920746b0 100644
--- a/indra/llcommon/llframetimer.cpp
+++ b/indra/llcommon/llframetimer.cpp
@@ -29,11 +29,6 @@
 
 #include "llframetimer.h"
 
-// We don't bother building a stand alone lib; we just need to include the one source file for Tracy support
-#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY || LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER
-	#include "TracyClient.cpp"
-#endif // LL_PROFILER_CONFIGURATION
-
 // Static members
 //LLTimer	LLFrameTimer::sInternalTimer;
 U64 LLFrameTimer::sStartTotalTime = totalTime();
diff --git a/indra/llcommon/llprofiler.h b/indra/llcommon/llprofiler.h
index f9d7ae7ce41..c414350e8ea 100644
--- a/indra/llcommon/llprofiler.h
+++ b/indra/llcommon/llprofiler.h
@@ -84,22 +84,23 @@ extern thread_local bool gProfilerEnabled;
 //      #define TRACY_NO_BROADCAST   1
 //      #define TRACY_ONLY_LOCALHOST 1
         #define TRACY_ONLY_IPV4      1
-        #include "Tracy.hpp"
+        #include "tracy/Tracy.hpp"
 
         // Mutually exclusive with detailed memory tracing
+    	#define LL_PROFILER_ENABLE_TRACY_MEMORY 0
         #define LL_PROFILER_ENABLE_TRACY_OPENGL 0
     #endif
 
     #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 );    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)              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_SCOPED                  ZoneScoped
+        #define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ); // RGB
+        #define LL_PROFILE_ZONE_SCOPED                  ZoneScoped;
 
-        #define LL_PROFILE_ZONE_NUM( val )              ZoneValue( val )
-        #define LL_PROFILE_ZONE_TEXT( text, size )      ZoneText( text, size )
+        #define LL_PROFILE_ZONE_NUM( val )              ZoneValue( val );
+        #define LL_PROFILE_ZONE_TEXT( text, size )      ZoneText( text, size );
 
         #define LL_PROFILE_ZONE_ERR(name)               LL_PROFILE_ZONE_NAMED_COLOR( name, 0XFF0000  )  // RGB yellow
         #define LL_PROFILE_ZONE_INFO(name)              LL_PROFILE_ZONE_NAMED_COLOR( name, 0X00FFFF  )  // RGB cyan
@@ -125,15 +126,15 @@ extern thread_local bool gProfilerEnabled;
         #define LL_PROFILE_FREE(ptr)                    (void)(ptr);
     #endif
     #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 );    gProfilerEnabled = true;
         #define LL_RECORD_BLOCK_TIME(name)              ZoneNamedN(___tracy_scoped_zone, #name, true);   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
-        #define LL_PROFILE_ZONE_SCOPED                  ZoneScoped
+        #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_SCOPED                  ZoneScoped;
 
-        #define LL_PROFILE_ZONE_NUM( val )              ZoneValue( val )
-        #define LL_PROFILE_ZONE_TEXT( text, size )      ZoneText( text, size )
+        #define LL_PROFILE_ZONE_NUM( val )              ZoneValue( val );
+        #define LL_PROFILE_ZONE_TEXT( text, size )      ZoneText( text, size );
 
         #define LL_PROFILE_ZONE_ERR(name)               LL_PROFILE_ZONE_NAMED_COLOR( name, 0XFF0000  )  // RGB yellow
         #define LL_PROFILE_ZONE_INFO(name)              LL_PROFILE_ZONE_NAMED_COLOR( name, 0X00FFFF  )  // RGB cyan
diff --git a/indra/llcommon/llprofilercategories.h b/indra/llcommon/llprofilercategories.h
index 8db29468ccc..a039f393e20 100644
--- a/indra/llcommon/llprofilercategories.h
+++ b/indra/llcommon/llprofilercategories.h
@@ -48,11 +48,11 @@
 #define LL_PROFILER_CATEGORY_ENABLE_DRAWPOOL    1
 #define LL_PROFILER_CATEGORY_ENABLE_ENVIRONMENT 1
 #define LL_PROFILER_CATEGORY_ENABLE_FACE        1
-#define LL_PROFILER_CATEGORY_ENABLE_LLSD        1
+#define LL_PROFILER_CATEGORY_ENABLE_LLSD        0
 #define LL_PROFILER_CATEGORY_ENABLE_LOGGING     1
 #define LL_PROFILER_CATEGORY_ENABLE_MATERIAL    1
 #define LL_PROFILER_CATEGORY_ENABLE_MEDIA       1
-#define LL_PROFILER_CATEGORY_ENABLE_MEMORY      1
+#define LL_PROFILER_CATEGORY_ENABLE_MEMORY      0
 #define LL_PROFILER_CATEGORY_ENABLE_NETWORK     1
 #define LL_PROFILER_CATEGORY_ENABLE_OCTREE      1
 #define LL_PROFILER_CATEGORY_ENABLE_PIPELINE    1
@@ -61,12 +61,12 @@
 #define LL_PROFILER_CATEGORY_ENABLE_STATS       1
 #define LL_PROFILER_CATEGORY_ENABLE_STRING      1
 #define LL_PROFILER_CATEGORY_ENABLE_TEXTURE     1
-#define LL_PROFILER_CATEGORY_ENABLE_THREAD      1
+#define LL_PROFILER_CATEGORY_ENABLE_THREAD      0
 #define LL_PROFILER_CATEGORY_ENABLE_UI          1
 #define LL_PROFILER_CATEGORY_ENABLE_VIEWER      1
 #define LL_PROFILER_CATEGORY_ENABLE_VERTEX      1
 #define LL_PROFILER_CATEGORY_ENABLE_VOLUME      1
-#define LL_PROFILER_CATEGORY_ENABLE_WIN32       1
+#define LL_PROFILER_CATEGORY_ENABLE_WIN32       0
 
 #if LL_PROFILER_CATEGORY_ENABLE_APP
     #define LL_PROFILE_ZONE_NAMED_CATEGORY_APP  LL_PROFILE_ZONE_NAMED
diff --git a/indra/llcorehttp/_thread.h b/indra/llcorehttp/_thread.h
index 3522658e87a..206eb4371be 100644
--- a/indra/llcorehttp/_thread.h
+++ b/indra/llcorehttp/_thread.h
@@ -54,7 +54,7 @@ class HttpThread final : public RefCounted
 
 	void run()
 		{ // THREAD CONTEXT
-
+			LL_PROFILER_SET_THREAD_NAME("HTTP Service");
 			// Take out additional reference for the at_exit handler
 			addRef();
 			boost::this_thread::at_thread_exit(boost::bind(&HttpThread::at_exit, this));
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 92213e34ad3..e05cb43967b 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -106,7 +106,6 @@ include_directories(
     ${FREEALUT_INCLUDE_DIRS}
     "${LIBS_PREBUILT_DIR}/include/collada/1.4"
     ${LLAPPEARANCE_INCLUDE_DIRS}
-    ${TRACY_INCLUDE_DIR}
     ${DISCORD_INCLUDE_DIRS}
     )
 
@@ -2239,7 +2238,7 @@ target_link_libraries(${VIEWER_BINARY_NAME}
     ${LLPHYSICS_LIBRARIES}
     ${LLPHYSICSEXTENSIONS_LIBRARIES}
     ${LLAPPEARANCE_LIBRARIES}
-    ${TRACY_LIBRARY}
+    TracyClient
     ${MINIZIP_LIBRARIES}
     ${DISCORD_LIBRARIES}
     meshoptimizer
@@ -2336,7 +2335,7 @@ if (DARWIN)
   set(MACOSX_BUNDLE_BUNDLE_NAME "Alchemy")
   set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VIEWER_SHORT_VERSION}")
   set(MACOSX_BUNDLE_BUNDLE_VERSION "${VIEWER_SHORT_VERSION}")
-  set(MACOSX_BUNDLE_COPYRIGHT "Copyright (C) 2013-2021 Alchemy Development Group")
+  set(MACOSX_BUNDLE_COPYRIGHT "Copyright (C) 2013-2023 Alchemy Development Group")
   set(MACOSX_BUNDLE_NSMAIN_NIB_FILE "Alchemy.nib")
   set(MACOSX_BUNDLE_NSPRINCIPAL_CLASS "LLApplication")
 
-- 
GitLab