From 10b3d7ad82c766ae0fae6e8fa26f674f4ec7fc39 Mon Sep 17 00:00:00 2001 From: Balazs Kovacsics Date: Wed, 9 Feb 2022 18:25:04 +0100 Subject: [PATCH 1/5] Fix compiling TracyClient.cpp on UWP with undefined TRACY_ENABLE --- common/TracySystem.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 38ccc6e7..63b88691 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -10,6 +10,11 @@ # endif # include # include + +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define TRACY_ON_UWP +# endif #else # include # include @@ -127,7 +132,11 @@ void ThreadNameMsvcMagic( const THREADNAME_INFO& info ) TRACY_API void SetThreadName( const char* name ) { #if defined _WIN32 +# if defined TRACY_ON_UWP + static auto _SetThreadDescription = &::SetThreadDescription; +# else static auto _SetThreadDescription = (t_SetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "SetThreadDescription" ); +# endif if( _SetThreadDescription ) { wchar_t buf[256]; @@ -191,7 +200,11 @@ TRACY_API const char* GetThreadName( uint32_t id ) } #else # if defined _WIN32 +# if defined TRACY_ON_UWP + static auto _GetThreadDescription = &::GetThreadDescription; +# else static auto _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" ); +# endif if( _GetThreadDescription ) { auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)id ); From 7169f5f30ae74efdc1f0fa079094a0b1067e81bc Mon Sep 17 00:00:00 2001 From: Balazs Kovacsics Date: Wed, 9 Feb 2022 22:14:36 +0100 Subject: [PATCH 2/5] Fix compiling TracyClient.cpp on UWP with defined TRACY_ENABLE --- client/TracyCallstack.h | 6 +++++- client/TracyProfiler.cpp | 37 ++++++++++++++++++++++++++++--------- client/TracySysTrace.hpp | 6 +++++- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/client/TracyCallstack.h b/client/TracyCallstack.h index 4145421f..06c9a595 100644 --- a/client/TracyCallstack.h +++ b/client/TracyCallstack.h @@ -6,7 +6,11 @@ #endif #if defined _WIN32 -# define TRACY_HAS_CALLSTACK 1 +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# else +# define TRACY_HAS_CALLSTACK 1 +# endif #elif defined __ANDROID__ # if !defined __arm__ || __ANDROID_API__ >= 21 # define TRACY_HAS_CALLSTACK 2 diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index ff9ce9c7..fc3c3b8c 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -9,6 +9,11 @@ # include # include # include + +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define TRACY_ON_UWP +# endif #else # include # include @@ -314,7 +319,9 @@ static void InitFailure( const char* msg ) } else { +# if !defined TRACY_ON_UWP MessageBoxA( nullptr, msg, "Tracy Profiler initialization failure", MB_ICONSTOP ); +# endif } #else fprintf( stderr, "Tracy Profiler initialization failure: %s\n", msg ); @@ -440,26 +447,30 @@ static const char* GetHostInfo() static char buf[1024]; auto ptr = buf; #if defined _WIN32 +# if defined TRACY_ON_UWP + ptr += sprintf(ptr, "OS: Windows 10\n"); +# else t_RtlGetVersion RtlGetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" ); if( !RtlGetVersion ) { -# ifdef __MINGW32__ +# ifdef __MINGW32__ ptr += sprintf( ptr, "OS: Windows (MingW)\n" ); -# else +# else ptr += sprintf( ptr, "OS: Windows\n" ); -# endif +# endif } else { RTL_OSVERSIONINFOW ver = { sizeof( RTL_OSVERSIONINFOW ) }; RtlGetVersion( &ver ); -# ifdef __MINGW32__ +# ifdef __MINGW32__ ptr += sprintf( ptr, "OS: Windows %i.%i.%i (MingW)\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber ); -# else +# else ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber ); -# endif +# endif } +# endif #elif defined __linux__ struct utsname utsName; uname( &utsName ); @@ -508,11 +519,15 @@ static const char* GetHostInfo() char hostname[512]; gethostname( hostname, 512 ); +# if defined TRACY_ON_UWP + ptr += sprintf(ptr, "Hostname: %s\n", hostname); +# else DWORD userSz = UNLEN+1; char user[UNLEN+1]; GetUserNameA( user, &userSz ); ptr += sprintf( ptr, "User: %s@%s\n", user, hostname ); +# endif #else char hostname[_POSIX_HOST_NAME_MAX]{}; char user[_POSIX_LOGIN_NAME_MAX]{}; @@ -707,7 +722,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz, return msg; } -#if defined _WIN32 +#if defined _WIN32 && !defined TRACY_ON_UWP static DWORD s_profilerThreadId = 0; static char s_crashText[1024]; @@ -1382,7 +1397,7 @@ void Profiler::SpawnWorkerThreads() new(s_symbolThread) Thread( LaunchSymbolWorker, this ); #endif -#if defined _WIN32 +#if defined _WIN32 && !defined TRACY_ON_UWP s_profilerThreadId = GetThreadId( s_thread->Handle() ); m_exceptionHandler = AddVectoredExceptionHandler( 1, CrashFilter ); #endif @@ -1416,7 +1431,7 @@ Profiler::~Profiler() { m_shutdown.store( true, std::memory_order_relaxed ); -#if defined _WIN32 +#if defined _WIN32 && !defined TRACY_ON_UWP if( m_crashHandlerInstalled ) RemoveVectoredExceptionHandler( m_exceptionHandler ); #endif @@ -3534,7 +3549,11 @@ void Profiler::ReportTopology() }; #if defined _WIN32 +# if defined TRACY_ON_UWP + t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = &::GetLogicalProcessorInformationEx; +# else t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = (t_GetLogicalProcessorInformationEx)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetLogicalProcessorInformationEx" ); +# endif if( !_GetLogicalProcessorInformationEx ) return; DWORD psz = 0; diff --git a/client/TracySysTrace.hpp b/client/TracySysTrace.hpp index d21d4338..e1b50bee 100644 --- a/client/TracySysTrace.hpp +++ b/client/TracySysTrace.hpp @@ -2,7 +2,11 @@ #define __TRACYSYSTRACE_HPP__ #if !defined TRACY_NO_SYSTEM_TRACING && ( defined _WIN32 || defined __linux__ ) -# define TRACY_HAS_SYSTEM_TRACING +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# else +# define TRACY_HAS_SYSTEM_TRACING +# endif #endif #ifdef TRACY_HAS_SYSTEM_TRACING From a0a56eaf9eafc997cd3ba41ff121bd9f8a1779fc Mon Sep 17 00:00:00 2001 From: Balazs Kovacsics Date: Thu, 10 Feb 2022 20:26:45 +0100 Subject: [PATCH 3/5] Move TRACY_UWP define to own header --- client/TracyCallstack.h | 5 ++--- client/TracyProfiler.cpp | 34 +++++++++++++++------------------- client/TracySysTrace.hpp | 5 ++--- common/TracySystem.cpp | 10 +++------- common/TracyUwp.hpp | 11 +++++++++++ 5 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 common/TracyUwp.hpp diff --git a/client/TracyCallstack.h b/client/TracyCallstack.h index 06c9a595..6a125010 100644 --- a/client/TracyCallstack.h +++ b/client/TracyCallstack.h @@ -6,9 +6,8 @@ #endif #if defined _WIN32 -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# else +# include "../common/TracyUwp.hpp" +# ifndef TRACY_UWP # define TRACY_HAS_CALLSTACK 1 # endif #elif defined __ANDROID__ diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index fc3c3b8c..9723b301 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -9,11 +9,7 @@ # include # include # include - -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define TRACY_ON_UWP -# endif +# include "../common/TracyUwp.hpp" #else # include # include @@ -319,7 +315,7 @@ static void InitFailure( const char* msg ) } else { -# if !defined TRACY_ON_UWP +# ifndef TRACY_UWP MessageBoxA( nullptr, msg, "Tracy Profiler initialization failure", MB_ICONSTOP ); # endif } @@ -447,11 +443,12 @@ static const char* GetHostInfo() static char buf[1024]; auto ptr = buf; #if defined _WIN32 -# if defined TRACY_ON_UWP - ptr += sprintf(ptr, "OS: Windows 10\n"); +# ifdef TRACY_UWP + auto GetVersion = &::GetVersionEx; # else - t_RtlGetVersion RtlGetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" ); - if( !RtlGetVersion ) + auto GetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" ); +# endif + if( !GetVersion ) { # ifdef __MINGW32__ ptr += sprintf( ptr, "OS: Windows (MingW)\n" ); @@ -462,7 +459,7 @@ static const char* GetHostInfo() else { RTL_OSVERSIONINFOW ver = { sizeof( RTL_OSVERSIONINFOW ) }; - RtlGetVersion( &ver ); + GetVersion( &ver ); # ifdef __MINGW32__ ptr += sprintf( ptr, "OS: Windows %i.%i.%i (MingW)\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber ); @@ -470,7 +467,6 @@ static const char* GetHostInfo() ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber ); # endif } -# endif #elif defined __linux__ struct utsname utsName; uname( &utsName ); @@ -519,15 +515,15 @@ static const char* GetHostInfo() char hostname[512]; gethostname( hostname, 512 ); -# if defined TRACY_ON_UWP - ptr += sprintf(ptr, "Hostname: %s\n", hostname); +# ifdef TRACY_UWP + const char* user = ""; # else DWORD userSz = UNLEN+1; char user[UNLEN+1]; GetUserNameA( user, &userSz ); +# endif ptr += sprintf( ptr, "User: %s@%s\n", user, hostname ); -# endif #else char hostname[_POSIX_HOST_NAME_MAX]{}; char user[_POSIX_LOGIN_NAME_MAX]{}; @@ -722,7 +718,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz, return msg; } -#if defined _WIN32 && !defined TRACY_ON_UWP +#if defined _WIN32 && !defined TRACY_UWP static DWORD s_profilerThreadId = 0; static char s_crashText[1024]; @@ -1397,7 +1393,7 @@ void Profiler::SpawnWorkerThreads() new(s_symbolThread) Thread( LaunchSymbolWorker, this ); #endif -#if defined _WIN32 && !defined TRACY_ON_UWP +#if defined _WIN32 && !defined TRACY_UWP s_profilerThreadId = GetThreadId( s_thread->Handle() ); m_exceptionHandler = AddVectoredExceptionHandler( 1, CrashFilter ); #endif @@ -1431,7 +1427,7 @@ Profiler::~Profiler() { m_shutdown.store( true, std::memory_order_relaxed ); -#if defined _WIN32 && !defined TRACY_ON_UWP +#if defined _WIN32 && !defined TRACY_UWP if( m_crashHandlerInstalled ) RemoveVectoredExceptionHandler( m_exceptionHandler ); #endif @@ -3549,7 +3545,7 @@ void Profiler::ReportTopology() }; #if defined _WIN32 -# if defined TRACY_ON_UWP +# ifdef TRACY_UWP t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = &::GetLogicalProcessorInformationEx; # else t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = (t_GetLogicalProcessorInformationEx)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetLogicalProcessorInformationEx" ); diff --git a/client/TracySysTrace.hpp b/client/TracySysTrace.hpp index e1b50bee..8c663cd7 100644 --- a/client/TracySysTrace.hpp +++ b/client/TracySysTrace.hpp @@ -2,9 +2,8 @@ #define __TRACYSYSTRACE_HPP__ #if !defined TRACY_NO_SYSTEM_TRACING && ( defined _WIN32 || defined __linux__ ) -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# else +# include "../common/TracyUwp.hpp" +# ifndef TRACY_UWP # define TRACY_HAS_SYSTEM_TRACING # endif #endif diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 63b88691..b9754d33 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -10,11 +10,7 @@ # endif # include # include - -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define TRACY_ON_UWP -# endif +# include "TracyUwp.hpp" #else # include # include @@ -132,7 +128,7 @@ void ThreadNameMsvcMagic( const THREADNAME_INFO& info ) TRACY_API void SetThreadName( const char* name ) { #if defined _WIN32 -# if defined TRACY_ON_UWP +# ifdef TRACY_UWP static auto _SetThreadDescription = &::SetThreadDescription; # else static auto _SetThreadDescription = (t_SetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "SetThreadDescription" ); @@ -200,7 +196,7 @@ TRACY_API const char* GetThreadName( uint32_t id ) } #else # if defined _WIN32 -# if defined TRACY_ON_UWP +# ifdef TRACY_UWP static auto _GetThreadDescription = &::GetThreadDescription; # else static auto _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" ); diff --git a/common/TracyUwp.hpp b/common/TracyUwp.hpp new file mode 100644 index 00000000..7dce96b9 --- /dev/null +++ b/common/TracyUwp.hpp @@ -0,0 +1,11 @@ +#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 From 85e16ee33a6ee097484924d6d733a3931fe294d0 Mon Sep 17 00:00:00 2001 From: Balazs Kovacsics Date: Fri, 11 Feb 2022 14:14:27 +0100 Subject: [PATCH 4/5] Add UWP platform limitations to manual --- manual/tracy.tex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/manual/tracy.tex b/manual/tracy.tex index e53854d8..9c6fd365 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -522,6 +522,16 @@ In the case of some programming environments, you may need to take extra steps t If you are using MSVC, you will need to disable the \emph{Edit And Continue} feature, as it makes the compiler non-conformant to some aspects of the C++ standard. In order to do so, open the project properties and go to \menu[,]{C/C++,General,Debug Information Format} and make sure \emph{Program Database for Edit And Continue (/ZI)} is \emph{not} selected. +\paragraph{Universal Windows Platform} + +Due to a restricted access to Win32 APIs and other sandboxing issues (like network isolation), several limitations apply to using Tracy in a UWP application compared to Windows Desktop: + +\begin{itemize} +\item Call stack sampling is not available. +\item System profiling is not available. +\item To be able to connect from another machine on the local network, the app needs the \emph{privateNetworkClientServer} capability. To connect from localhost, an active inbound loopback exemption is also necessary \footnote{\url{https://docs.microsoft.com/en-us/windows/uwp/communication/interprocess-communication\#loopback}}. +\end{itemize} + \paragraph{Apple woes} Because Apple \emph{has} to be \emph{think different}, there are some problems with using Tracy on OSX and iOS. First, the performance hit due to profiling is higher than on other platforms. Second, some critical features are missing and won't be possible to achieve: From aa44cedcd2d539365982df6c8fb7cd818fae51b5 Mon Sep 17 00:00:00 2001 From: Balazs Kovacsics Date: Fri, 11 Feb 2022 17:11:07 +0100 Subject: [PATCH 5/5] Fix indentation --- client/TracyProfiler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 9723b301..86f872af 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -450,22 +450,22 @@ static const char* GetHostInfo() # endif if( !GetVersion ) { -# ifdef __MINGW32__ +# ifdef __MINGW32__ ptr += sprintf( ptr, "OS: Windows (MingW)\n" ); -# else +# else ptr += sprintf( ptr, "OS: Windows\n" ); -# endif +# endif } else { RTL_OSVERSIONINFOW ver = { sizeof( RTL_OSVERSIONINFOW ) }; GetVersion( &ver ); -# ifdef __MINGW32__ +# ifdef __MINGW32__ ptr += sprintf( ptr, "OS: Windows %i.%i.%i (MingW)\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber ); -# else +# else ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber ); -# endif +# endif } #elif defined __linux__ struct utsname utsName;