mirror of
https://github.com/wolfpld/tracy
synced 2025-04-28 20:23:51 +00:00
Compare commits
9 Commits
7e33165c40
...
40efbe8529
Author | SHA1 | Date | |
---|---|---|---|
|
40efbe8529 | ||
|
2bb5d126fd | ||
|
efc12c2032 | ||
|
fa942d18fe | ||
|
e845c23493 | ||
|
3fad55d7bc | ||
|
eac23cead2 | ||
|
fc142b4f9c | ||
|
00ac6d1d8e |
@ -234,7 +234,7 @@ static int64_t SetupHwTimer()
|
|||||||
CpuId( regs, 0x80000007 );
|
CpuId( regs, 0x80000007 );
|
||||||
if( !( regs[3] & ( 1 << 8 ) ) )
|
if( !( regs[3] & ( 1 << 8 ) ) )
|
||||||
{
|
{
|
||||||
const char* noCheck = getenv( "TRACY_NO_INVARIANT_CHECK" );
|
const char* noCheck = GetEnvVar( "TRACY_NO_INVARIANT_CHECK" );
|
||||||
if( !noCheck || noCheck[0] != '1' )
|
if( !noCheck || noCheck[0] != '1' )
|
||||||
{
|
{
|
||||||
#if defined _WIN32 || defined __CYGWIN__
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
@ -967,13 +967,11 @@ TRACY_API void InitRPMallocThread();
|
|||||||
void InitRPMallocThread()
|
void InitRPMallocThread()
|
||||||
{
|
{
|
||||||
RPMallocInit rpinit;
|
RPMallocInit rpinit;
|
||||||
rpmalloc_thread_initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProfilerData
|
struct ProfilerData
|
||||||
{
|
{
|
||||||
int64_t initTime = SetupHwTimer();
|
int64_t initTime = SetupHwTimer();
|
||||||
RPMallocInit rpmalloc_init;
|
|
||||||
moodycamel::ConcurrentQueue<QueueItem> queue;
|
moodycamel::ConcurrentQueue<QueueItem> queue;
|
||||||
Profiler profiler;
|
Profiler profiler;
|
||||||
std::atomic<uint32_t> lockCounter { 0 };
|
std::atomic<uint32_t> lockCounter { 0 };
|
||||||
@ -1003,7 +1001,9 @@ struct ProfilerThreadData
|
|||||||
ProfilerData* s_profilerData = nullptr;
|
ProfilerData* s_profilerData = nullptr;
|
||||||
TRACY_API void StartupProfiler()
|
TRACY_API void StartupProfiler()
|
||||||
{
|
{
|
||||||
s_profilerData = new ProfilerData;
|
RPMallocInit init;
|
||||||
|
s_profilerData = (ProfilerData*)tracy_malloc( sizeof( ProfilerData ) );
|
||||||
|
new (s_profilerData) ProfilerData();
|
||||||
s_profilerData->profiler.SpawnWorkerThreads();
|
s_profilerData->profiler.SpawnWorkerThreads();
|
||||||
}
|
}
|
||||||
static ProfilerData& GetProfilerData()
|
static ProfilerData& GetProfilerData()
|
||||||
@ -1013,7 +1013,8 @@ static ProfilerData& GetProfilerData()
|
|||||||
}
|
}
|
||||||
TRACY_API void ShutdownProfiler()
|
TRACY_API void ShutdownProfiler()
|
||||||
{
|
{
|
||||||
delete s_profilerData;
|
s_profilerData->~ProfilerData();
|
||||||
|
tracy_free( s_profilerData );
|
||||||
s_profilerData = nullptr;
|
s_profilerData = nullptr;
|
||||||
rpmalloc_finalize();
|
rpmalloc_finalize();
|
||||||
}
|
}
|
||||||
@ -1031,7 +1032,8 @@ static ProfilerData& GetProfilerData()
|
|||||||
ptr = profilerData.load( std::memory_order_acquire );
|
ptr = profilerData.load( std::memory_order_acquire );
|
||||||
if( !ptr )
|
if( !ptr )
|
||||||
{
|
{
|
||||||
ptr = (ProfilerData*)malloc( sizeof( ProfilerData ) );
|
RPMallocInit init;
|
||||||
|
ptr = (ProfilerData*)tracy_malloc( sizeof( ProfilerData ) );
|
||||||
new (ptr) ProfilerData();
|
new (ptr) ProfilerData();
|
||||||
profilerData.store( ptr, std::memory_order_release );
|
profilerData.store( ptr, std::memory_order_release );
|
||||||
}
|
}
|
||||||
@ -1226,14 +1228,14 @@ Profiler::Profiler()
|
|||||||
ReportTopology();
|
ReportTopology();
|
||||||
|
|
||||||
#ifndef TRACY_NO_EXIT
|
#ifndef TRACY_NO_EXIT
|
||||||
const char* noExitEnv = getenv( "TRACY_NO_EXIT" );
|
const char* noExitEnv = GetEnvVar( "TRACY_NO_EXIT" );
|
||||||
if( noExitEnv && noExitEnv[0] == '1' )
|
if( noExitEnv && noExitEnv[0] == '1' )
|
||||||
{
|
{
|
||||||
m_noExit = true;
|
m_noExit = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char* userPort = getenv( "TRACY_PORT" );
|
const char* userPort = GetEnvVar( "TRACY_PORT" );
|
||||||
if( userPort )
|
if( userPort )
|
||||||
{
|
{
|
||||||
m_userPort = atoi( userPort );
|
m_userPort = atoi( userPort );
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "TracyAlloc.hpp"
|
#include "TracyAlloc.hpp"
|
||||||
#include "TracySocket.hpp"
|
#include "TracySocket.hpp"
|
||||||
|
#include "TracySystem.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifndef NOMINMAX
|
# ifndef NOMINMAX
|
||||||
@ -454,7 +455,7 @@ static int addrinfo_and_socket_for_family( uint16_t port, int ai_family, struct
|
|||||||
hints.ai_family = ai_family;
|
hints.ai_family = ai_family;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
#ifndef TRACY_ONLY_LOCALHOST
|
#ifndef TRACY_ONLY_LOCALHOST
|
||||||
const char* onlyLocalhost = getenv( "TRACY_ONLY_LOCALHOST" );
|
const char* onlyLocalhost = GetEnvVar( "TRACY_ONLY_LOCALHOST" );
|
||||||
if( !onlyLocalhost || onlyLocalhost[0] != '1' )
|
if( !onlyLocalhost || onlyLocalhost[0] != '1' )
|
||||||
{
|
{
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
@ -475,7 +476,7 @@ bool ListenSocket::Listen( uint16_t port, int backlog )
|
|||||||
struct addrinfo* res = nullptr;
|
struct addrinfo* res = nullptr;
|
||||||
|
|
||||||
#if !defined TRACY_ONLY_IPV4 && !defined TRACY_ONLY_LOCALHOST
|
#if !defined TRACY_ONLY_IPV4 && !defined TRACY_ONLY_LOCALHOST
|
||||||
const char* onlyIPv4 = getenv( "TRACY_ONLY_IPV4" );
|
const char* onlyIPv4 = GetEnvVar( "TRACY_ONLY_IPV4" );
|
||||||
if( !onlyIPv4 || onlyIPv4[0] != '1' )
|
if( !onlyIPv4 || onlyIPv4[0] != '1' )
|
||||||
{
|
{
|
||||||
m_sock = addrinfo_and_socket_for_family( port, AF_INET6, &res );
|
m_sock = addrinfo_and_socket_for_family( port, AF_INET6, &res );
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#if defined _WIN32 || defined __CYGWIN__
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
# include <malloc.h>
|
||||||
#else
|
#else
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
@ -236,6 +237,38 @@ TRACY_API const char* GetThreadName( uint64_t id )
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACY_API const char* GetEnvVar( const char* name )
|
||||||
|
{
|
||||||
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
|
// unfortunately getenv() on Windows is just fundamentally broken. It caches the entire
|
||||||
|
// environment block once on startup, then never refreshes it again. If any environment
|
||||||
|
// strings are added or modified after startup of the CRT, those changes will not be
|
||||||
|
// seen by getenv(). This removes the possibility of an app using this SDK from
|
||||||
|
// programmatically setting any of the behaviour controlling envvars here.
|
||||||
|
//
|
||||||
|
// To work around this, we'll instead go directly to the Win32 environment strings APIs
|
||||||
|
// to get the current value.
|
||||||
|
static char buffer[1024];
|
||||||
|
DWORD const kBufferSize = DWORD(sizeof(buffer) / sizeof(buffer[0]));
|
||||||
|
DWORD count = GetEnvironmentVariableA(name, buffer, kBufferSize);
|
||||||
|
|
||||||
|
if( count == 0 )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if( count >= kBufferSize )
|
||||||
|
{
|
||||||
|
char* buf = reinterpret_cast<char*>(_alloca(count + 1));
|
||||||
|
count = GetEnvironmentVariableA(name, buf, count + 1);
|
||||||
|
memcpy(buffer, buf, kBufferSize);
|
||||||
|
buffer[kBufferSize - 1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
#else
|
||||||
|
return getenv(name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -25,6 +25,8 @@ static inline uint64_t GetThreadHandle()
|
|||||||
TRACY_API void SetThreadName( const char* name );
|
TRACY_API void SetThreadName( const char* name );
|
||||||
TRACY_API const char* GetThreadName( uint64_t id );
|
TRACY_API const char* GetThreadName( uint64_t id );
|
||||||
|
|
||||||
|
TRACY_API const char* GetEnvVar(const char* name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user