Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "code/thirdparty/tracy"]
path = code/thirdparty/tracy
url = https://github.com/wolfpld/tracy.git
1 change: 1 addition & 0 deletions cmake/libraries/all.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ include(libraries/zlib)
include(libraries/libmad)
include(libraries/flex_bison)
include(libraries/recastnavigation)
include(libraries/tracy)
25 changes: 25 additions & 0 deletions cmake/libraries/tracy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Tracy profiler
option(TRACY_ENABLE "Enable the Tracy profiler" OFF)

# Make sure we build Tracy as objects with LTO that we can then link into a shared library.
set(TRACY_LTO ON)
add_subdirectory(${SOURCE_DIR}/thirdparty/tracy)

# In accordance with section 2.1.8, "Setup for multi-DLL projects" of the Tracy manual,
# we wrap TracyClient into a shared library that we then depend on.
if(TRACY_ENABLE)
add_library(tracy SHARED ${SOURCE_DIR}/sys/sys_tracy.cpp)
# Include Tracy as a private dependency so that we can control the public interface of the DLL.
target_link_libraries(tracy PRIVATE Tracy::TracyClient)
target_include_directories(tracy SYSTEM PUBLIC ${SOURCE_DIR}/thirdparty/tracy/public)
# Copy over the public compile definitions from the TracyClient target - it's already set up for MSVC imports, for example.
get_target_property(TRACY_DEFS Tracy::TracyClient INTERFACE_COMPILE_DEFINITIONS)
target_compile_definitions(tracy PUBLIC ${TRACY_DEFS})
INSTALL(TARGETS tracy DESTINATION ${INSTALL_LIBDIR_FULL})
else()
# Even when disabled, we still want the includes available so that empty Tracy macros are declared.
add_library(tracy INTERFACE)
target_include_directories(tracy SYSTEM INTERFACE ${SOURCE_DIR}/thirdparty/tracy/public)
endif()

list(APPEND COMMON_LIBRARIES tracy)
7 changes: 7 additions & 0 deletions code/cgame/cg_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "cg_local.h"
#include "cg_parsemsg.h"

#include <tracy/TracyC.h>

//============================================================================

/*
Expand Down Expand Up @@ -826,6 +828,8 @@ Generates and draws a game scene and status information at the given time.
*/
void CG_DrawActiveFrame(int serverTime, int frameTime, stereoFrame_t stereoView, qboolean demoPlayback)
{
TracyCZone(ctx, 1);

cg.time = serverTime;
cg.frametime = frameTime;
cg.demoPlayback = demoPlayback;
Expand All @@ -843,6 +847,7 @@ void CG_DrawActiveFrame(int serverTime, int frameTime, stereoFrame_t stereoView,
// if we haven't received any snapshots yet, all
// we can draw is the information screen
if (!cg.snap || (cg.snap->snapFlags & SNAPFLAG_NOT_ACTIVE)) {
TracyCZoneEnd(ctx);
return;
}

Expand Down Expand Up @@ -1037,4 +1042,6 @@ void CG_DrawActiveFrame(int serverTime, int frameTime, stereoFrame_t stereoView,
if (cg_stats->integer) {
cgi.Printf("cg.clientFrame:%i\n", cg.clientFrame);
}

TracyCZoneEnd(ctx);
}
6 changes: 6 additions & 0 deletions code/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ extern "C" {

#include <climits>

#include <tracy/Tracy.hpp>

#ifdef USE_RENDERER_DLOPEN
cvar_t* cl_renderer;
#endif
Expand Down Expand Up @@ -850,6 +852,8 @@ void CL_MapLoading( qboolean flush, const char *pszMapName ) {
UI_ClearState();
UI_ForceMenuOff(false);

TracyMessageS(va("CL_MapLoading: %s", pszMapName), 15 + strlen(pszMapName), 16);

if (!flush) {
// Don't do anything if it's not flushingb
return;
Expand Down Expand Up @@ -2672,6 +2676,8 @@ void CL_Frame ( int msec ) {
return;
}

ZoneScoped;

#ifdef USE_CURL
if(clc.downloadCURLM) {
CL_cURL_PerformDownload();
Expand Down
4 changes: 4 additions & 0 deletions code/fgame/g_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# include <intrin.h>
#endif

#include <tracy/Tracy.hpp>

#define SAVEGAME_VERSION 80
#define PERSISTANT_VERSION 2

Expand Down Expand Up @@ -482,6 +484,8 @@ void G_RunFrame(int levelTime, int frameTime)
static int processed[MAX_GENTITIES] = {0};
static int processedFrameID = 0;

ZoneScoped;

try {
g_iInThinks = 0;

Expand Down
4 changes: 4 additions & 0 deletions code/qcommon/cm_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "cm_local.h"
#include "../client/client.h"

#include <tracy/TracyC.h>

#ifdef BSPC

#include "../bspc/l_qfiles.h"
Expand Down Expand Up @@ -838,6 +840,8 @@ void CM_LoadMap( const char *name, qboolean clientload, int *checksum ) {
Com_Error( ERR_DROP, "CM_LoadMap: NULL name" );
}

TracyCMessageS(va("CM_LoadMap: %s", name), 12 + strlen(name), 16);

#ifndef BSPC
cm_noAreas = Cvar_Get( "cm_noAreas", "0", CVAR_CHEAT );
cm_noCurves = Cvar_Get( "cm_noCurves", "0", CVAR_CHEAT );
Expand Down
4 changes: 4 additions & 0 deletions code/qcommon/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "q_shared.h"
#include "qcommon.h"

#include <tracy/TracyC.h>

#define MAX_CMD_BUFFER 128*1024
#define MAX_CMD_LINE 8192 // was increased for testing purposes
#define MAX_ALIAS_NAME 32
Expand Down Expand Up @@ -989,6 +991,8 @@ void Cmd_ExecuteString( const char *text ) {
cmd_function_t *cmd, **prev;
cmdalias_t *a;

TracyCMessageS(va("Cmd_ExecuteString: %s", text), strlen(text) + 19, 0);

// execute the command line
Cmd_TokenizeString( text );
if ( !Cmd_Argc() ) {
Expand Down
4 changes: 4 additions & 0 deletions code/qcommon/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#include "../gamespy/q_gamespy.h"

#include <tracy/TracyC.h>

qboolean CL_FinishedIntro(void);

#ifdef __cplusplus
Expand Down Expand Up @@ -2495,6 +2497,8 @@ void Com_Frame( void ) {
Sys_ProcessBackgroundTasks();

com_frameNumber++;

TracyCFrameMark;
}

/*
Expand Down
6 changes: 6 additions & 0 deletions code/sdl/sdl_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../client/client.h"
#include "../sys/sys_local.h"

#include <tracy/TracyC.h>

#if !SDL_VERSION_ATLEAST(2, 0, 17)
#define KMOD_SCROLL KMOD_RESERVED
#endif
Expand Down Expand Up @@ -1248,6 +1250,8 @@ void IN_Frame( void )
{
qboolean loading;

TracyCZone(ctx, 1);

IN_JoyMove( );

// If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading
Expand Down Expand Up @@ -1285,6 +1289,8 @@ void IN_Frame( void )
vidRestartTime = 0;
Cbuf_AddText( "vid_restart\n" );
}

TracyCZoneEnd(ctx);
}

/*
Expand Down
6 changes: 6 additions & 0 deletions code/server/sv_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/bg_compat.h"
#include "../gamespy/sv_gamespy.h"

#include <tracy/TracyC.h>

static char last_mapname[ MAX_QPATH ];
static int g_iSvsTimeFixupCount;
static int *g_piSvsTimeFixups[ 2048 ];
Expand Down Expand Up @@ -587,6 +589,8 @@ void SV_SpawnServer( const char *server, qboolean loadgame, qboolean restart, qb
qboolean keep_scripts;
const char *p;

TracyCZone(ctx, 1);

keep_scripts = restart;

Com_Printf ("------ Server Initialization ------\n");
Expand Down Expand Up @@ -975,6 +979,8 @@ void SV_SpawnServer( const char *server, qboolean loadgame, qboolean restart, qb
if( g_gametype->integer != GT_SINGLE_PLAYER ) {
SV_ServerLoaded();
}

TracyCZoneEnd(ctx);
}

/*
Expand Down
9 changes: 9 additions & 0 deletions code/server/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../gamespy/sv_gamespy.h"
#include "../gamespy/sv_gqueryreporting.h"

#include <tracy/TracyC.h>

#ifdef USE_VOIP
cvar_t *sv_voip;
cvar_t *sv_voipProtocol;
Expand Down Expand Up @@ -1059,10 +1061,13 @@ void SV_Frame( int msec ) {
return;
}

TracyCZone(ctx, 1);

SV_NET_UpdateAllNetProfileInfo();

// allow pause if only the local client is connected
if ( SV_CheckPaused() ) {
TracyCZoneEnd(ctx);
return;
}

Expand All @@ -1088,12 +1093,14 @@ void SV_Frame( int msec ) {
if ( svs.time > 0x70000000 ) {
SV_Shutdown( "Restarting server due to time wrapping" );
Cbuf_AddText( va( "map %s\n", Cvar_VariableString( "mapname" ) ) );
TracyCZoneEnd(ctx);
return;
}
// this can happen considerably earlier when lots of clients play and the map doesn't change
if ( svs.nextSnapshotEntities >= 0x7FFFFFFE - svs.numSnapshotEntities ) {
SV_Shutdown( "Restarting server due to numSnapshotEntities wrapping" );
Cbuf_AddText( va( "map %s\n", Cvar_VariableString( "mapname" ) ) );
TracyCZoneEnd(ctx);
return;
}

Expand Down Expand Up @@ -1164,6 +1171,8 @@ void SV_Frame( int msec ) {
SV_HandleNonPVSSound();

svs.lastTime = svs.time;

TracyCZoneEnd(ctx);
}

/*
Expand Down
9 changes: 9 additions & 0 deletions code/sys/sys_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"

#include <tracy/TracyC.h>
#if TRACY_ENABLE
extern TRACY_API void Sys_TracyShutdown();
#endif

static char binaryPath[ MAX_OSPATH ] = { 0 };
static char installPath[ MAX_OSPATH ] = { 0 };

Expand Down Expand Up @@ -302,6 +307,10 @@ static Q_NO_RETURN void Sys_Exit( int exitCode )

Sys_PlatformExit( );

#ifdef TRACY_ENABLE
Sys_TracyShutdown();
#endif

exit( exitCode );
}

Expand Down
41 changes: 41 additions & 0 deletions code/sys/sys_tracy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
===========================================================================
Copyright (C) 2025 the OpenMoHAA team

This file is part of OpenMoHAA source code.

OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/

// This file is compiled as part of the tracy target and contains C-linkage wrappers
// for advanced Tracy profiler functionality that isn't exposed via the TracyC API.

// We are also still "inside" the Tracy client, so we need to patch up the import/export macros.
#undef TRACY_IMPORTS
#define TRACY_EXPORTS

#include <tracy/Tracy.hpp>
#include <thread>

extern "C" {
TRACY_API void Sys_TracyShutdown()
{
tracy::GetProfiler().RequestShutdown();
while (!tracy::GetProfiler().HasShutdownFinished()) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
}
1 change: 1 addition & 0 deletions code/thirdparty/tracy
Submodule tracy added at 05ccee
Loading