Skip to content

Commit 8d66cbd

Browse files
feat(profiling): Include Tracy profiler library in the solution (TheSuperHackers#2202)
1 parent 2c26a90 commit 8d66cbd

10 files changed

Lines changed: 70 additions & 7 deletions

File tree

CMakePresets.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
"inherits": "win32",
110110
"displayName": "Windows 32bit Profile",
111111
"cacheVariables": {
112-
"RTS_BUILD_OPTION_PROFILE": "ON"
112+
"RTS_BUILD_OPTION_PROFILE": "ON",
113+
"RTS_BUILD_OPTION_PROFILE_TRACY": "ON"
113114
}
114115
},
115116
{
@@ -143,7 +144,8 @@
143144
"inherits": "win32-vcpkg",
144145
"displayName": "Windows 32bit VCPKG Profile",
145146
"cacheVariables": {
146-
"RTS_BUILD_OPTION_PROFILE": "ON"
147+
"RTS_BUILD_OPTION_PROFILE": "ON",
148+
"RTS_BUILD_OPTION_PROFILE_TRACY": "ON"
147149
}
148150
},
149151
{
@@ -488,4 +490,4 @@
488490
]
489491
}
490492
]
491-
}
493+
}

Core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ target_link_libraries(corei_always_no_pch INTERFACE
3131
resources
3232
)
3333

34+
if(RTS_BUILD_OPTION_PROFILE AND RTS_BUILD_OPTION_PROFILE_TRACY)
35+
target_link_libraries(corei_libraries_include INTERFACE Tracy::TracyClient)
36+
endif()
37+
3438
# Set where the build results will end up
3539
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
3640

Core/Libraries/Include/rts/profile.h

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

30-
# pragma once
30+
#pragma once
3131

32+
#ifdef TRACY_ENABLE
33+
#include <tracy/Tracy.hpp>
34+
#define TRACY_FRAMEIMAGE_SIZE 256
35+
#else
3236
#include "../../Source/profile/profile.h"
37+
#define ZoneScopedN(name) ((void)0)
38+
#define ZoneScopedNC(name, color) ((void)0)
39+
#define TracyPlot(name, value) ((void)0)
40+
#define FrameMark ((void)0)
41+
#define FrameMarkNamed(name) ((void)0)
42+
#define FrameImage(image, width, height, offset, flip) ((void)0)
43+
#define TracyMessage(txt, size) ((void)0)
44+
#endif

GeneralsMD/Code/GameEngine/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,12 @@ target_link_libraries(z_gameengine PRIVATE
11691169
zi_always
11701170
)
11711171

1172+
if(RTS_BUILD_OPTION_PROFILE AND RTS_BUILD_OPTION_PROFILE_TRACY)
1173+
target_link_libraries(z_gameengine PRIVATE
1174+
Tracy::TracyClient
1175+
)
1176+
endif()
1177+
11721178
target_link_libraries(z_gameengine PUBLIC
11731179
corei_gameengine_public
11741180
z_wwvegas

GeneralsMD/Code/GameEngineDevice/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ target_link_libraries(z_gameenginedevice PRIVATE
216216
zi_always
217217
zi_main
218218
)
219+
if(RTS_BUILD_OPTION_PROFILE AND RTS_BUILD_OPTION_PROFILE_TRACY)
220+
target_link_libraries(z_gameenginedevice PRIVATE
221+
Tracy::TracyClient
222+
)
223+
endif()
219224

220225
target_link_libraries(z_gameenginedevice PUBLIC
221226
corei_gameenginedevice_public

GeneralsMD/Code/Main/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ target_link_libraries(z_generals PRIVATE
2525
zi_always
2626
)
2727

28+
if(RTS_BUILD_OPTION_PROFILE AND RTS_BUILD_OPTION_PROFILE_TRACY)
29+
target_link_libraries(z_generals PRIVATE
30+
Tracy::TracyClient
31+
)
32+
endif()
33+
2834
# TODO Originally referred to build host and user, replace with git info perhaps?
2935
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/GeneratedVersion.h
3036
"#pragma once

cmake/config-build.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ option(RTS_BUILD_OPTION_DEBUG "Build code with the \"Debug\" configuration." OFF
88
option(RTS_BUILD_OPTION_ASAN "Build code with Address Sanitizer." OFF)
99
option(RTS_BUILD_OPTION_VC6_FULL_DEBUG "Build VC6 with full debug info." OFF)
1010
option(RTS_BUILD_OPTION_FFMPEG "Enable FFmpeg support" OFF)
11+
option(RTS_BUILD_OPTION_PROFILE_TRACY "Enable Tracy profiling for profile builds." OFF)
1112

1213
if(NOT RTS_BUILD_ZEROHOUR AND NOT RTS_BUILD_GENERALS)
1314
set(RTS_BUILD_ZEROHOUR TRUE)
@@ -71,5 +72,18 @@ else()
7172
endif()
7273

7374
if(RTS_BUILD_OPTION_PROFILE)
74-
target_compile_definitions(core_config INTERFACE RTS_PROFILE)
75+
if(RTS_BUILD_OPTION_PROFILE_TRACY)
76+
find_package(Tracy CONFIG QUIET)
77+
if(NOT Tracy_FOUND)
78+
include(${CMAKE_CURRENT_LIST_DIR}/tracy.cmake)
79+
endif()
80+
if(NOT TARGET Tracy::TracyClient)
81+
message(FATAL_ERROR "Tracy is enabled but Tracy::TracyClient was not found.")
82+
endif()
83+
target_compile_definitions(core_config INTERFACE
84+
TRACY_ENABLE
85+
)
86+
else ()
87+
target_compile_definitions(core_config INTERFACE RTS_PROFILE)
88+
endif()
7589
endif()

cmake/tracy.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FetchContent_Declare(
2+
tracy
3+
GIT_REPOSITORY https://github.com/wolfpld/tracy
4+
GIT_TAG v0.13.1
5+
)
6+
7+
FetchContent_MakeAvailable(tracy)

vcpkg-lock.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
"version-string": "1.3.1",
4343
"port-version": 0,
4444
"git-tree": "3f05e04b9aededb96786a911a16193cdb711f0c9"
45+
},
46+
{
47+
"name": "tracy",
48+
"version-string": "0.11.1",
49+
"port-version": 2,
50+
"git-tree": "ff802e1b85c20b5f276c4b82aaa60fc933444ab2"
4551
}
4652
]
4753
}

vcpkg.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"builtin-baseline": "b02e341c927f16d991edbd915d8ea43eac52096c",
44
"dependencies": [
55
"zlib",
6-
"ffmpeg"
6+
"ffmpeg",
7+
"tracy"
78
]
8-
}
9+
}

0 commit comments

Comments
 (0)