diff --git a/CMakeLists.txt b/CMakeLists.txt index bef1298c..09eacc34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/meson.build b/meson.build index bf2d8c43..af6f220b 100644 --- a/meson.build +++ b/meson.build @@ -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' ] diff --git a/public/client/TracyCallstack.h b/public/client/TracyCallstack.h index 2c7ecad9..1aca7292 100644 --- a/public/client/TracyCallstack.h +++ b/public/client/TracyCallstack.h @@ -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__ diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index a635663f..943b6490 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -9,7 +9,7 @@ # include # include # include -# include "../common/TracyUwp.hpp" +# include "../common/TracyWinFamily.hpp" # ifndef _MSC_VER # include # 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( 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" ); diff --git a/public/client/TracySysTime.cpp b/public/client/TracySysTime.cpp index b690a911..88b91570 100644 --- a/public/client/TracySysTime.cpp +++ b/public/client/TracySysTime.cpp @@ -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; diff --git a/public/client/TracySysTrace.hpp b/public/client/TracySysTrace.hpp index 8c663cd7..2a28e8b8 100644 --- a/public/client/TracySysTrace.hpp +++ b/public/client/TracySysTrace.hpp @@ -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 diff --git a/public/client/tracy_rpmalloc.cpp b/public/client/tracy_rpmalloc.cpp index 315a40f9..c43b8cab 100644 --- a/public/client/tracy_rpmalloc.cpp +++ b/public/client/tracy_rpmalloc.cpp @@ -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(); diff --git a/public/common/TracySystem.cpp b/public/common/TracySystem.cpp index a92a3457..7696ca32 100644 --- a/public/common/TracySystem.cpp +++ b/public/common/TracySystem.cpp @@ -10,7 +10,7 @@ # endif # include # include -# include "TracyUwp.hpp" +# include "TracyWinFamily.hpp" #else # include # include @@ -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" ); diff --git a/public/common/TracyUwp.hpp b/public/common/TracyUwp.hpp deleted file mode 100644 index 7dce96b9..00000000 --- a/public/common/TracyUwp.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __TRACYUWP_HPP__ -#define __TRACYUWP_HPP__ - -#ifdef _WIN32 -# include -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define TRACY_UWP -# endif -#endif - -#endif diff --git a/public/common/TracyWinFamily.hpp b/public/common/TracyWinFamily.hpp new file mode 100644 index 00000000..f6174d79 --- /dev/null +++ b/public/common/TracyWinFamily.hpp @@ -0,0 +1,16 @@ +#ifndef __TRACYUWP_HPP__ +#define __TRACYUWP_HPP__ + +#ifdef _WIN32 +# include +# 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