Skip to content

Commit 8a604fa

Browse files
stephanmeestersxezon
authored andcommitted
feat(profiling): Include Tracy profiler library in the solution (TheSuperHackers#2202)
1 parent 684a6f3 commit 8a604fa

6 files changed

Lines changed: 69 additions & 3 deletions

File tree

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
"inherits": "win32",
111111
"displayName": "Windows 32bit Profile",
112112
"cacheVariables": {
113-
"RTS_BUILD_OPTION_PROFILE": "ON"
113+
"RTS_BUILD_OPTION_PROFILE": "ON",
114+
"RTS_BUILD_OPTION_PROFILE_TRACY": "ON"
114115
}
115116
},
116117
{

Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ target_sources(corei_libraries_include PRIVATE
2222
)
2323
target_link_libraries(corei_always INTERFACE
2424
core_config
25+
core_profile_tracy
2526
core_utility
2627
corei_libraries_include
2728
resources

Core/Libraries/Include/rts/profile.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,43 @@
2727
// Proxy header for profile module
2828
//////////////////////////////////////////////////////////////////////////////
2929

30-
# pragma once
30+
#pragma once
3131

32+
#if defined(RTS_PROFILE_LEGACY)
3233
#include "../../Source/profile/profile.h"
34+
#endif
35+
36+
#if defined(RTS_PROFILE_TRACY)
37+
38+
#include <tracy/Tracy.hpp>
39+
40+
#define PROFILER_ENABLED
41+
#define PROFILER_FRAME_IMAGE_SIZE 256 // Horizontal size of the frame image in pixels.
42+
#define PROFILER_FRAME_IMAGE_INTERVAL_MS 500 // Will capture every render frame if set to 0
43+
#define PROFILER_SECTION ZoneScoped
44+
#define PROFILER_SECTION_NAME(name) ZoneScopedN(name)
45+
#define PROFILER_SECTION_COLOR(color) ZoneScopedC(color)
46+
#define PROFILER_SECTION_NAMECOLOR(name, color) ZoneScopedNC(name, color)
47+
#define PROFILER_FRAME_MARK FrameMark
48+
#define PROFILER_FRAME_MARK_NAME(name) FrameMarkNamed(name)
49+
#define PROFILER_FRAME_IMAGE(image, width, height, offset, flip) FrameImage(image, width, height, offset, flip)
50+
#define PROFILER_MSG(txt, size) TracyMessage(txt, size)
51+
#define PROFILER_PLOT(name, value) TracyPlot(name, value)
52+
#define PROFILER_IS_CONNECTED TracyIsConnected
53+
54+
#else
55+
56+
#define PROFILER_FRAME_IMAGE_SIZE 0
57+
#define PROFILER_FRAME_IMAGE_INTERVAL_MS 0
58+
#define PROFILER_SECTION ((void)0)
59+
#define PROFILER_SECTION_NAME(name) ((void)0)
60+
#define PROFILER_SECTION_COLOR(color) ((void)0)
61+
#define PROFILER_SECTION_NAMECOLOR(name, color) ((void)0)
62+
#define PROFILER_FRAME_MARK ((void)0)
63+
#define PROFILER_FRAME_MARK_NAME(name) ((void)0)
64+
#define PROFILER_FRAME_IMAGE(image, width, height, offset, flip) ((void)0)
65+
#define PROFILER_MSG(txt, size) ((void)0)
66+
#define PROFILER_PLOT(name, value) ((void)0)
67+
#define PROFILER_IS_CONNECTED false
68+
69+
#endif

Core/Libraries/Source/debug/debug_debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ void Debug::WriteBuildInfo()
14981498
(*this) << " internal " << m_intVersion;
14991499
#if defined(RTS_DEBUG)
15001500
operator<<(" debug");
1501-
#elif defined(RTS_PROFILE_LEGACY)
1501+
#elif defined(RTS_PROFILE_LEGACY) || defined(RTS_PROFILE_TRACY)
15021502
operator<<(" profile");
15031503
#else
15041504
operator<<(" release");

cmake/config-build.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ option(RTS_BUILD_CORE_EXTRAS "Build core extra tools/tests" OFF)
44
option(RTS_BUILD_ZEROHOUR "Build Zero Hour code." ON)
55
option(RTS_BUILD_GENERALS "Build Generals code." ON)
66
option(RTS_BUILD_OPTION_PROFILE "Build code with the \"Profile\" configuration." OFF)
7+
option(RTS_BUILD_OPTION_PROFILE_TRACY "Build code with Tracy profiling enabled." OFF)
78
option(RTS_BUILD_OPTION_DEBUG "Build code with the \"Debug\" configuration." OFF)
89
option(RTS_BUILD_OPTION_ASAN "Build code with Address Sanitizer." OFF)
910
option(RTS_BUILD_OPTION_VC6_FULL_DEBUG "Build VC6 with full debug info." OFF)
@@ -75,3 +76,10 @@ endif()
7576
if(RTS_BUILD_OPTION_PROFILE)
7677
target_compile_definitions(core_config INTERFACE RTS_PROFILE_LEGACY)
7778
endif()
79+
80+
# Define a dummy Tracy target when the build option is disabled.
81+
if(RTS_BUILD_OPTION_PROFILE_TRACY)
82+
include(cmake/tracy.cmake)
83+
else()
84+
add_library(core_profile_tracy INTERFACE)
85+
endif()

cmake/tracy.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
find_package(Tracy CONFIG QUIET)
2+
if(NOT Tracy_FOUND)
3+
FetchContent_Declare(
4+
tracy
5+
GIT_REPOSITORY https://github.com/TheSuperHackers/tracy
6+
GIT_TAG 05cceee0df3b8d7c6fa87e9638af311dbabc63cb # 0.13.1
7+
)
8+
FetchContent_MakeAvailable(tracy)
9+
endif()
10+
11+
if(NOT TARGET TracyClient)
12+
message(FATAL_ERROR "Tracy is enabled but TracyClient was not found.")
13+
endif()
14+
15+
target_compile_definitions(TracyClient INTERFACE
16+
RTS_PROFILE_TRACY
17+
)
18+
19+
add_library(core_profile_tracy ALIAS TracyClient)

0 commit comments

Comments
 (0)