Skip to content

Commit 7057206

Browse files
committed
Support for Tracy profiler
1 parent 2b91015 commit 7057206

37 files changed

+414
-18
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,6 @@ cmake_install.cmake
197197
/conf/search_server.conf
198198
/conf/server_message.conf
199199
/conf/server_message_fr.conf
200+
201+
# Tracy download
202+
tracy/

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ include(StandardProjectSettings)
1313
include(CompilerWarnings)
1414
include(Sanitizers)
1515
include(ClangTidy)
16+
include(Tracy)
1617

1718
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
1819
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

CMakeSettings.json

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@
4747
"ctestCommandArgs": "",
4848
"inheritEnvironments": [ "msvc_x64_x64" ],
4949
"variables": []
50+
},
51+
{
52+
"name": "x64-Debug-Tracy",
53+
"generator": "Ninja",
54+
"configurationType": "Debug",
55+
"buildRoot": "${projectDir}\\out\\build\\${name}",
56+
"installRoot": "${projectDir}\\out\\install\\${name}",
57+
"cmakeCommandArgs": "-DMYSQL_INCLUDE_DIR=${projectDir}\\ext\\include\\mysql -DMYSQL_LIBRARY=${projectDir}\\ext\\lib64\\libmariadb64.lib -DTRACY_ENABLE=ON",
58+
"buildCommandArgs": "",
59+
"ctestCommandArgs": "",
60+
"inheritEnvironments": [ "msvc_x64_x64" ],
61+
"variables": []
62+
},
63+
{
64+
"name": "x64-Release-Tracy",
65+
"generator": "Ninja",
66+
"configurationType": "RelWithDebInfo",
67+
"buildRoot": "${projectDir}\\out\\build\\${name}",
68+
"installRoot": "${projectDir}\\out\\install\\${name}",
69+
"cmakeCommandArgs": "-DMYSQL_INCLUDE_DIR=${projectDir}\\ext\\include\\mysql -DMYSQL_LIBRARY=${projectDir}\\ext\\lib64\\libmariadb64.lib -DTRACY_ENABLE=ON",
70+
"buildCommandArgs": "",
71+
"ctestCommandArgs": "",
72+
"inheritEnvironments": [ "msvc_x64_x64" ],
73+
"variables": []
5074
}
5175
]
5276
}

cmake/StandardProjectSettings.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if(MSVC)
6666
endif()
6767

6868
if(UNIX)
69-
69+
link_libraries(dl)
7070
endif()
7171

7272
# TODO: These should be applied on a per-target level, not globally like this!

cmake/Tracy.cmake

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Enable on command-line with 'cmake -DTRACY_ENABLE=ON ..'
2+
3+
option(TRACY_ENABLE "Enable Tracy profiling." OFF)
4+
message(STATUS "TRACY_ENABLE: ${TRACY_ENABLE}")
5+
6+
if(TRACY_ENABLE)
7+
set(TRACY_LINK https://github.com/wolfpld/tracy/archive/v0.7.3.tar.gz)
8+
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/tracy/tracy-0.7.3/TracyClient.cpp)
9+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/tracy)
10+
file(DOWNLOAD
11+
${TRACY_LINK}
12+
${CMAKE_SOURCE_DIR}/tracy/tracy.tar.gz
13+
TIMEOUT 60
14+
SHOW_PROGRESS)
15+
execute_process(COMMAND "${CMAKE_COMMAND}" -E
16+
tar xf "${CMAKE_SOURCE_DIR}/tracy/tracy.tar.gz"
17+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tracy)
18+
endif()
19+
20+
add_library(tracy_client ${CMAKE_SOURCE_DIR}/tracy/tracy-0.7.3/TracyClient.cpp)
21+
target_include_directories(tracy_client PUBLIC ${CMAKE_SOURCE_DIR}/tracy/tracy-0.7.3/)
22+
target_compile_definitions(tracy_client PUBLIC TRACY_ENABLE TRACY_ON_DEMAND TRACY_NO_EXIT TRACY_NO_BROADCAST)
23+
24+
if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
25+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
26+
endif()
27+
endif(TRACY_ENABLE)

src/common/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ target_link_libraries(
4343
project_options
4444
# project_warnings
4545
)
46-
46+
47+
if(TRACY_ENABLE)
48+
target_link_libraries(common PUBLIC tracy_client)
49+
endif(TRACY_ENABLE)

src/common/cbasetypes.h

+2
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ using server_clock = std::chrono::system_clock;
4848
using time_point = server_clock::time_point;
4949
using duration = server_clock::duration;
5050

51+
#include "tracy.h"
52+
5153
#endif /* _CBASETYPES_H_ */

src/common/showmsg.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ int _vShowMessage(MSGTYPE flag, const std::string& string)
687687
}
688688
}
689689

690+
#ifdef TRACY_ENABLE
691+
TracyMessage(string.c_str(), string.size());
692+
#endif
693+
690694
return 0;
691695
}
692696
void ClearScreen(void)

src/common/tracy.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef _TRACY_H
2+
#define _TRACY_H
3+
4+
#ifdef TRACY_ENABLE
5+
#include "fmt/format.h"
6+
#include "Tracy.hpp"
7+
8+
#define TracyFrameMark FrameMark
9+
#define TracyZoneScoped ZoneScoped
10+
#define TracyZoneScopedN(n) ZoneScopedN(n)
11+
#define TracyZoneText(n, l) ZoneText(n, l)
12+
#define TracyZoneScopedC(c) ZoneScopedC(c)
13+
#define TracyZoneString(str) ZoneText(str.c_str(), str.size())
14+
#define TracyZoneCString(cstr) ZoneText(cstr, std::strlen(cstr))
15+
#define TracyZoneIString(istr) TracyZoneCString(reinterpret_cast<const char*>(istr))
16+
17+
inline std::string Hex8ToString(uint8 hex)
18+
{
19+
return fmt::format("0x{:2X}", hex);
20+
}
21+
22+
inline std::string Hex16ToString(uint16 hex)
23+
{
24+
return fmt::format("0x{:4X}", hex);
25+
}
26+
27+
#define TracyZoneHex8(num) auto str = Hex8ToString(num); TracyZoneText(str.c_str(), str.size());
28+
#define TracyZoneHex16(num) auto str = Hex16ToString(num); TracyZoneText(str.c_str(), str.size());
29+
30+
#define TracyReportLuaMemory(L) TracyPlotConfig("Lua Memory Usage", tracy::PlotFormatType::Memory); TracyPlot("Lua Memory Usage", static_cast<double>(lua_gc(L, LUA_GCCOUNT, 0)) * 1024.0);
31+
32+
#else // Empty stubs for regular builds
33+
#define TracyFrameMark
34+
#define TracyZoneScoped
35+
#define TracyZoneScopedN(n)
36+
#define TracyZoneText(n, l)
37+
#define TracyZoneScopedC(c)
38+
#define TracyZoneString(str)
39+
#define TracyZoneCString(cstr)
40+
#define TracyZoneIString(istr)
41+
#define TracyZoneHex8(num)
42+
#define TracyZoneHex16(num)
43+
#define TracyReportLuaMemory(L)
44+
#endif
45+
46+
#endif // _TRACY_H

src/map/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ target_link_libraries(topaz_game
145145
#project_warnings
146146
)
147147

148+
if(TRACY_ENABLE)
149+
target_link_libraries(topaz_game PUBLIC tracy_client)
150+
endif(TRACY_ENABLE)
151+
148152
if(APPLE)
149153
link_options(topaz_game PUBLIC -pagezero_size 10000 -image_base 100000000)
150154
endif()

src/map/ai/ai_container.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ void CAIContainer::Reset()
334334

335335
void CAIContainer::Tick(time_point _tick)
336336
{
337+
TracyZoneScoped;
337338
m_PrevTick = m_Tick;
338339
m_Tick = _tick;
339340

0 commit comments

Comments
 (0)