Add support for using Tracy profiler on Switch

This commit is contained in:
Wojtek Figat
2024-01-30 18:14:53 +01:00
parent 320024399d
commit fa58b171ec
6 changed files with 31 additions and 9 deletions

View File

@@ -34,6 +34,7 @@ public class Profiler : EngineModule
case TargetPlatform.Android:
case TargetPlatform.Linux:
case TargetPlatform.Windows:
case TargetPlatform.Switch:
options.PublicDependencies.Add("tracy");
break;
}

View File

@@ -113,6 +113,11 @@ extern "C" typedef BOOL (WINAPI *t_GetLogicalProcessorInformationEx)( LOGICAL_PR
# include <mutex>
#endif
#if !defined _WIN32 && !defined __linux__ && !defined __APPLE__
#include "Engine/Core/Types/String.h"
#include "Engine/Platform/MemoryStats.h"
#endif
namespace tracy
{
@@ -383,7 +388,7 @@ static int64_t SetupHwTimer()
static const char* GetProcessName()
{
const char* processName = "unknown";
const char* processName = "FlaxEngine";
#ifdef _WIN32
static char buf[_MAX_PATH];
GetModuleFileNameA( nullptr, buf, _MAX_PATH );
@@ -518,7 +523,10 @@ static const char* GetHostInfo()
#elif defined __OpenBSD__
ptr += sprintf( ptr, "OS: BSD (OpenBSD)\n" );
#else
ptr += sprintf( ptr, "OS: unknown\n" );
String computerName = Platform::GetComputerName();
char computerNameBuf[60];
StringUtils::ConvertUTF162ANSI(computerName.Get(), computerNameBuf, computerName.Length());
ptr += sprintf( ptr, "OS: %s\n", computerNameBuf );
#endif
#if defined _MSC_VER
@@ -690,7 +698,7 @@ static const char* GetHostInfo()
sysctlbyname( "hw.physmem", &memSize, &sz, nullptr, 0 );
ptr += sprintf( ptr, "RAM: %zu MB\n", memSize / 1024 / 1024 );
#else
ptr += sprintf( ptr, "RAM: unknown\n" );
ptr += sprintf( ptr, "RAM: %zu MB\n", (size_t)Platform::GetMemoryStats().TotalPhysicalMemory / 1024 / 1024 );
#endif
return buf;

View File

@@ -3,7 +3,7 @@
#include <stdlib.h>
#if defined TRACY_ENABLE && !defined __EMSCRIPTEN__
#if defined TRACY_ENABLE && !defined __EMSCRIPTEN__ && !defined TRACY_USE_MALLOC
# include "../client/tracy_rpmalloc.hpp"
# define TRACY_USE_RPMALLOC
#endif

View File

@@ -450,6 +450,9 @@ ListenSocket::~ListenSocket()
static int addrinfo_and_socket_for_family( uint16_t port, int ai_family, struct addrinfo** res )
{
#if PLATFORM_SWITCH
Platform::GetNetworkConnectionType(); // Ensure to have network service initialized before using sockets
#endif
struct addrinfo hints;
memset( &hints, 0, sizeof( hints ) );
hints.ai_family = ai_family;

View File

@@ -47,6 +47,10 @@ extern "C" typedef HRESULT (WINAPI *t_GetThreadDescription)( HANDLE, PWSTR* );
#ifdef TRACY_ENABLE
# include <atomic>
# include "TracyAlloc.hpp"
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__linux__)
#include "Engine/Platform/Platform.h"
#endif
#endif
namespace tracy
@@ -88,7 +92,7 @@ TRACY_API uint32_t GetThreadHandleImpl()
// thread identifier. It is a pointer to a library-allocated data structure instead.
// Such pointers will be reused heavily, making the pthread_t non-unique. Additionally
// a 64-bit pointer cannot be reliably truncated to 32 bits.
#error "Unsupported platform!"
return Platform::GetCurrentThreadID();
#endif
}

View File

@@ -40,14 +40,20 @@ public class tracy : ThirdPartyModule
options.PublicDefinitions.Add("TRACY_ENABLE");
options.PrivateDefinitions.Add("TRACY_NO_INVARIANT_CHECK");
options.PrivateDefinitions.Add("TRACY_NO_FRAME_IMAGE");
if (options.Platform.Target == TargetPlatform.Windows)
{
options.PrivateDefinitions.Add("TRACY_DBGHELP_LOCK=DbgHelp");
}
if (OnDemand)
{
options.PublicDefinitions.Add("TRACY_ON_DEMAND");
}
switch (options.Platform.Target)
{
case TargetPlatform.Windows:
options.PrivateDefinitions.Add("TRACY_DBGHELP_LOCK=DbgHelp");
break;
case TargetPlatform.Switch:
options.PrivateDefinitions.Add("TRACY_USE_MALLOC");
options.PrivateDefinitions.Add("TRACY_ONLY_IPV4");
break;
}
}
/// <inheritdoc />