Add support for GDK

This commit is contained in:
Patrik Kraif
2025-07-16 12:51:16 +02:00
parent 382b41bcce
commit 4a3713cca8
10 changed files with 53 additions and 31 deletions

View File

@@ -209,7 +209,7 @@ set(common_includes
${TRACY_PUBLIC_DIR}/common/TracySocket.hpp
${TRACY_PUBLIC_DIR}/common/TracyStackFrames.hpp
${TRACY_PUBLIC_DIR}/common/TracySystem.hpp
${TRACY_PUBLIC_DIR}/common/TracyUwp.hpp
${TRACY_PUBLIC_DIR}/common/TracyWinFamily.hpp
${TRACY_PUBLIC_DIR}/common/TracyYield.hpp)
install(TARGETS TracyClient

View File

@@ -177,7 +177,7 @@ common_includes = [
'public/common/TracySocket.hpp',
'public/common/TracyStackFrames.hpp',
'public/common/TracySystem.hpp',
'public/common/TracyUwp.hpp',
'public/common/TracyWinFamily.hpp',
'public/common/TracyYield.hpp'
]

View File

@@ -8,8 +8,8 @@
# endif
# if defined _WIN32
# include "../common/TracyUwp.hpp"
# ifndef TRACY_UWP
# include "../common/TracyWinFamily.hpp"
# if !defined TRACY_WIN32_NO_DESKTOP
# define TRACY_HAS_CALLSTACK 1
# endif
# elif defined __ANDROID__

View File

@@ -9,7 +9,7 @@
# include <tlhelp32.h>
# include <inttypes.h>
# include <intrin.h>
# include "../common/TracyUwp.hpp"
# include "../common/TracyWinFamily.hpp"
# ifndef _MSC_VER
# include <excpt.h>
# endif
@@ -327,7 +327,13 @@ static inline void CpuId( uint32_t* regs, uint32_t leaf )
static void InitFailure( const char* msg )
{
#if defined _WIN32
#if defined TRACY_GDK
const char* format = "Tracy Profiler initialization failure: %s\n";
const int length = snprintf( nullptr, 0, format, msg );
char* buffer = (char*)alloca( length + 1 );
snprintf( buffer, length + 1, format, msg );
OutputDebugStringA( buffer );
#elif defined _WIN32
bool hasConsole = false;
bool reopen = false;
const auto attached = AttachConsole( ATTACH_PARENT_PROCESS );
@@ -510,7 +516,7 @@ static const char* GetHostInfo()
static char buf[1024];
auto ptr = buf;
#if defined _WIN32
# ifdef TRACY_UWP
# if defined TRACY_WIN32_NO_DESKTOP
auto GetVersion = &::GetVersionEx;
# else
auto GetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" );
@@ -593,7 +599,7 @@ static const char* GetHostInfo()
char hostname[512];
gethostname( hostname, 512 );
# ifdef TRACY_UWP
# if defined TRACY_WIN32_NO_DESKTOP
const char* user = "";
# else
DWORD userSz = UNLEN+1;
@@ -804,7 +810,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz,
return msg;
}
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
static DWORD s_profilerThreadId = 0;
static DWORD s_symbolThreadId = 0;
static char s_crashText[1024];
@@ -1550,7 +1556,7 @@ void Profiler::InstallCrashHandler()
sigaction( SIGABRT, &crashHandler, &m_prevSignal.abrt );
#endif
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
// We cannot use Vectored Exception handling because it catches application-wide frame-based SEH blocks. We only
// want to catch unhandled exceptions.
m_prevHandler = reinterpret_cast<void*>( SetUnhandledExceptionFilter( CrashFilter ) );
@@ -1564,7 +1570,7 @@ void Profiler::InstallCrashHandler()
void Profiler::RemoveCrashHandler()
{
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
if( m_crashHandlerInstalled )
{
auto prev = SetUnhandledExceptionFilter( (LPTOP_LEVEL_EXCEPTION_FILTER)m_prevHandler );
@@ -1611,7 +1617,7 @@ void Profiler::SpawnWorkerThreads()
new(s_symbolThread) Thread( LaunchSymbolWorker, this );
#endif
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
s_profilerThreadId = GetThreadId( s_thread->Handle() );
# ifdef TRACY_HAS_CALLSTACK
s_symbolThreadId = GetThreadId( s_symbolThread->Handle() );
@@ -3843,7 +3849,7 @@ void Profiler::ReportTopology()
};
#if defined _WIN32
# ifdef TRACY_UWP
# if defined TRACY_WIN32_NO_DESKTOP
t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = &::GetLogicalProcessorInformationEx;
# else
t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = (t_GetLogicalProcessorInformationEx)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetLogicalProcessorInformationEx" );

View File

@@ -27,13 +27,24 @@ static inline uint64_t ConvertTime( const FILETIME& t )
void SysTime::ReadTimes()
{
FILETIME idleTime;
FILETIME kernelTime;
FILETIME userTime;
# if defined TRACY_GDK
FILETIME creationTime;
FILETIME exitTime;
GetProcessTimes( GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime );
idle = 0;
# else
FILETIME idleTime;
GetSystemTimes( &idleTime, &kernelTime, &userTime );
idle = ConvertTime( idleTime );
# endif
const auto kernel = ConvertTime( kernelTime );
const auto user = ConvertTime( userTime );
used = kernel + user;

View File

@@ -2,8 +2,8 @@
#define __TRACYSYSTRACE_HPP__
#if !defined TRACY_NO_SYSTEM_TRACING && ( defined _WIN32 || defined __linux__ )
# include "../common/TracyUwp.hpp"
# ifndef TRACY_UWP
# include "../common/TracyWinFamily.hpp"
# if !defined TRACY_WIN32_NO_DESKTOP
# define TRACY_HAS_SYSTEM_TRACING
# endif
#endif

View File

@@ -2780,7 +2780,7 @@ rpmalloc_initialize_config(const rpmalloc_config_t* config) {
_memory_huge_pages = 1;
}
#if PLATFORM_WINDOWS
#if PLATFORM_WINDOWS && !defined TRACY_GDK
if (_memory_config.enable_huge_pages) {
HANDLE token = 0;
size_t large_page_minimum = GetLargePageMinimum();

View File

@@ -10,7 +10,7 @@
# endif
# include <windows.h>
# include <malloc.h>
# include "TracyUwp.hpp"
# include "TracyWinFamily.hpp"
#else
# include <pthread.h>
# include <string.h>
@@ -137,7 +137,7 @@ TRACY_API void SetThreadName( const char* name )
TRACY_API void SetThreadNameWithHint( const char* name, int32_t groupHint )
{
#if defined _WIN32
# ifdef TRACY_UWP
# if defined TRACY_WIN32_NO_DESKTOP
static auto _SetThreadDescription = &::SetThreadDescription;
# else
static auto _SetThreadDescription = (t_SetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "SetThreadDescription" );
@@ -246,7 +246,7 @@ TRACY_API const char* GetThreadName( uint32_t id )
#endif
#if defined _WIN32
# ifdef TRACY_UWP
# if defined TRACY_WIN32_NO_DESKTOP
static auto _GetThreadDescription = &::GetThreadDescription;
# else
static auto _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" );

View File

@@ -1,11 +0,0 @@
#ifndef __TRACYUWP_HPP__
#define __TRACYUWP_HPP__
#ifdef _WIN32
# include <winapifamily.h>
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define TRACY_UWP
# endif
#endif
#endif

View File

@@ -0,0 +1,16 @@
#ifndef __TRACYUWP_HPP__
#define __TRACYUWP_HPP__
#ifdef _WIN32
# include <winapifamily.h>
# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define TRACY_WIN32_NO_DESKTOP
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_GAMES)
# define TRACY_GDK
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
# define TRACY_UWP
# endif
# endif
#endif
#endif