Add support for C# Profiler events to be visible in Tracy
This commit is contained in:
@@ -21,13 +21,20 @@ namespace ProfilerInternal
|
||||
void BeginEvent(MonoString* nameObj)
|
||||
{
|
||||
#if COMPILE_WITH_PROFILER
|
||||
ProfilerCPU::BeginEvent((const Char*)mono_string_chars(nameObj));
|
||||
const StringView name(mono_string_chars(nameObj), mono_string_length(nameObj));
|
||||
ProfilerCPU::BeginEvent(*name);
|
||||
#if TRACY_ENABLE
|
||||
tracy::ScopedZone::Begin(__LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name.Get(), name.Length() );
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void EndEvent()
|
||||
{
|
||||
#if COMPILE_WITH_PROFILER
|
||||
#if TRACY_ENABLE
|
||||
tracy::ScopedZone::End();
|
||||
#endif
|
||||
ProfilerCPU::EndEvent();
|
||||
#endif
|
||||
}
|
||||
|
||||
24
Source/ThirdParty/tracy/client/TracyProfiler.hpp
vendored
24
Source/ThirdParty/tracy/client/TracyProfiler.hpp
vendored
@@ -249,7 +249,7 @@ public:
|
||||
|
||||
static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz )
|
||||
{
|
||||
return AllocSourceLocation( line, source, sourceSz, function, functionSz, nullptr, 0 );
|
||||
return AllocSourceLocation( line, source, sourceSz, function, functionSz, (const char*)nullptr, 0 );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz )
|
||||
@@ -272,6 +272,28 @@ public:
|
||||
return uint64_t( ptr );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const Char* name, size_t nameSz )
|
||||
{
|
||||
const auto sz32 = uint32_t( 2 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz );
|
||||
assert( sz32 <= std::numeric_limits<uint16_t>::max() );
|
||||
const auto sz = uint16_t( sz32 );
|
||||
auto ptr = (char*)tracy_malloc( sz );
|
||||
memcpy( ptr, &sz, 2 );
|
||||
memset( ptr + 2, 0, 4 );
|
||||
memcpy( ptr + 6, &line, 4 );
|
||||
memcpy( ptr + 10, function, functionSz );
|
||||
ptr[10 + functionSz] = '\0';
|
||||
memcpy( ptr + 10 + functionSz + 1, source, sourceSz );
|
||||
ptr[10 + functionSz + 1 + sourceSz] = '\0';
|
||||
if( nameSz != 0 )
|
||||
{
|
||||
char* dst = ptr + 10 + functionSz + 1 + sourceSz + 1;
|
||||
for ( size_t i = 0; i < nameSz; i++)
|
||||
dst[i] = (char)name[i];
|
||||
}
|
||||
return uint64_t( ptr );
|
||||
}
|
||||
|
||||
private:
|
||||
enum class DequeueStatus { DataDequeued, ConnectionLost, QueueEmpty };
|
||||
|
||||
|
||||
16
Source/ThirdParty/tracy/client/TracyScoped.hpp
vendored
16
Source/ThirdParty/tracy/client/TracyScoped.hpp
vendored
@@ -12,6 +12,22 @@
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
inline void ScopedZone::Begin(uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const Char* name, size_t nameSz)
|
||||
{
|
||||
TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc );
|
||||
const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz );
|
||||
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
|
||||
MemWrite( &item->zoneBegin.srcloc, srcloc );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
|
||||
inline void ScopedZone::End()
|
||||
{
|
||||
TracyLfqPrepare( QueueType::ZoneEnd );
|
||||
MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
|
||||
inline ScopedZone::ScopedZone( const SourceLocationData* srcloc, bool is_active )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
: m_active( is_active && GetProfiler().IsConnected() )
|
||||
|
||||
@@ -46,6 +46,9 @@ struct TRACY_API SourceLocationData
|
||||
class TRACY_API ScopedZone
|
||||
{
|
||||
public:
|
||||
static void Begin( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const Char* name, size_t nameSz );
|
||||
static void End();
|
||||
|
||||
ScopedZone( const ScopedZone& ) = delete;
|
||||
ScopedZone( ScopedZone&& ) = delete;
|
||||
ScopedZone& operator=( const ScopedZone& ) = delete;
|
||||
|
||||
Reference in New Issue
Block a user