Browse Source

Adds CMake option to use External Profiler (#1599)

Use external profiler to define ProfileStartMeasurement and ProfileEndMeasurement in your own code to profile.
Jeslas Pravin 4 months ago
parent
commit
829d246742
3 changed files with 13 additions and 3 deletions
  1. 5 0
      Build/CMakeLists.txt
  2. 1 1
      Build/README.md
  3. 7 2
      Jolt/Jolt.cmake

+ 5 - 0
Build/CMakeLists.txt

@@ -92,6 +92,11 @@ option(PROFILER_IN_DEBUG_AND_RELEASE "Enable the profiler in Debug and Release b
 # Note that enabling this reduces the performance of the library.
 # Note that enabling this reduces the performance of the library.
 option(PROFILER_IN_DISTRIBUTION "Enable the profiler in all builds" OFF)
 option(PROFILER_IN_DISTRIBUTION "Enable the profiler in all builds" OFF)
 
 
+# Ability to use the external profiler using CMake config. Defines preprocessor JPH_EXTERNAL_PROFILE.
+# Use external profiler set using ProfileStartMeasurement and ProfileEndMeasurement to profile.
+# Option is available only when profiling is enabled using PROFILER_IN_DEBUG_AND_RELEASE or PROFILER_IN_DISTRIBUTION.
+option(JPH_USE_EXTERNAL_PROFILE "Use external profiler when profiling is enabled" OFF)
+
 # Setting this option will force the library to use malloc/free instead of allowing the user to override the memory allocator
 # Setting this option will force the library to use malloc/free instead of allowing the user to override the memory allocator
 option(DISABLE_CUSTOM_ALLOCATOR "Disable support for a custom memory allocator" OFF)
 option(DISABLE_CUSTOM_ALLOCATOR "Disable support for a custom memory allocator" OFF)
 
 

+ 1 - 1
Build/README.md

@@ -25,7 +25,7 @@ There are a number of user configurable defines that turn on/off certain feature
 	<ul>
 	<ul>
 		<li>JPH_SHARED_LIBRARY - Use the Jolt library as a shared library. Use JPH_BUILD_SHARED_LIBRARY to build Jolt as a shared library.</li>
 		<li>JPH_SHARED_LIBRARY - Use the Jolt library as a shared library. Use JPH_BUILD_SHARED_LIBRARY to build Jolt as a shared library.</li>
 		<li>JPH_PROFILE_ENABLED - Turns on the internal profiler.</li>
 		<li>JPH_PROFILE_ENABLED - Turns on the internal profiler.</li>
-		<li>JPH_EXTERNAL_PROFILE - Turns on the internal profiler but forwards the information to a user defined external system (see Profiler.h).</li>
+		<li>JPH_EXTERNAL_PROFILE - Turns on the internal profiler but forwards the information to a user defined external system (see Profiler.h). Use JPH_USE_EXTERNAL_PROFILE option to enable this from CMake config.</li>
 		<li>JPH_DEBUG_RENDERER - Adds support to draw lines and triangles, used to be able to debug draw the state of the world.</li>
 		<li>JPH_DEBUG_RENDERER - Adds support to draw lines and triangles, used to be able to debug draw the state of the world.</li>
 		<li>JPH_DISABLE_TEMP_ALLOCATOR - Disables the temporary memory allocator, used mainly to allow ASAN to do its job.</li>
 		<li>JPH_DISABLE_TEMP_ALLOCATOR - Disables the temporary memory allocator, used mainly to allow ASAN to do its job.</li>
 		<li>JPH_DISABLE_CUSTOM_ALLOCATOR - Disables the ability to override the memory allocator.</li>
 		<li>JPH_DISABLE_CUSTOM_ALLOCATOR - Disables the ability to override the memory allocator.</li>

+ 7 - 2
Jolt/Jolt.cmake

@@ -575,10 +575,15 @@ elseif (DEBUG_RENDERER_IN_DEBUG_AND_RELEASE)
 endif()
 endif()
 
 
 # Enable the profiler
 # Enable the profiler
+if (JPH_USE_EXTERNAL_PROFILE)
+	set(JOLT_PROFILE_DEFINE JPH_EXTERNAL_PROFILE)
+else()
+	set(JOLT_PROFILE_DEFINE JPH_PROFILE_ENABLED)
+endif()
 if (PROFILER_IN_DISTRIBUTION)
 if (PROFILER_IN_DISTRIBUTION)
-	target_compile_definitions(Jolt PUBLIC "JPH_PROFILE_ENABLED")
+	target_compile_definitions(Jolt PUBLIC "${JOLT_PROFILE_DEFINE}")
 elseif (PROFILER_IN_DEBUG_AND_RELEASE)
 elseif (PROFILER_IN_DEBUG_AND_RELEASE)
-	target_compile_definitions(Jolt PUBLIC "$<$<CONFIG:Debug,Release,ReleaseASAN,ReleaseUBSAN,ReleaseTSAN>:JPH_PROFILE_ENABLED>")
+	target_compile_definitions(Jolt PUBLIC "$<$<CONFIG:Debug,Release,ReleaseASAN,ReleaseUBSAN,ReleaseTSAN>:${JOLT_PROFILE_DEFINE}>")
 endif()
 endif()
 
 
 # Compile the ObjectStream class and RTTI attribute information
 # Compile the ObjectStream class and RTTI attribute information