Add fiber support on client side.

This commit is contained in:
Bartosz Taudul 2021-11-01 23:56:19 +01:00
parent 8b15cd049c
commit 229d547e91
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
5 changed files with 64 additions and 2 deletions

View File

@ -97,6 +97,9 @@
#define TracyParameterSetup(x,y,z,w)
#define TracyIsConnected false
#define TracyFiberEnter(x)
#define TracyFiberLeave
#else
#include <string.h>
@ -254,6 +257,11 @@
#define TracyParameterSetup( idx, name, isBool, val ) tracy::Profiler::ParameterSetup( idx, name, isBool, val );
#define TracyIsConnected tracy::GetProfiler().IsConnected()
#ifdef TRACY_FIBERS
# define TracyFiberEnter( fiber ) tracy::Profiler::EnterFiber( fiber );
# define TracyFiberLeave tracy::Profiler::LeaveFiber();
#endif
#endif
#endif

View File

@ -2752,6 +2752,24 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
tracy_free_fast( (void*)ptr );
break;
}
case QueueType::FiberEnter:
{
ThreadCtxCheckSerial( fiberEnter );
int64_t t = MemRead<int64_t>( &item->fiberEnter.time );
int64_t dt = t - refThread;
refThread = t;
MemWrite( &item->fiberEnter.time, dt );
break;
}
case QueueType::FiberLeave:
{
ThreadCtxCheckSerial( fiberLeave );
int64_t t = MemRead<int64_t>( &item->fiberLeave.time );
int64_t dt = t - refThread;
refThread = t;
MemWrite( &item->fiberLeave.time, dt );
break;
}
#endif
default:
assert( false );

View File

@ -584,6 +584,23 @@ public:
TracyLfqCommit;
}
#ifdef TRACY_FIBERS
static tracy_force_inline void EnterFiber( const char* fiber )
{
TracyQueuePrepare( QueueType::FiberEnter );
MemWrite( &item->fiberEnter.time, GetTime() );
MemWrite( &item->fiberEnter.fiber, (uint64_t)fiber );
TracyQueueCommit( fiberEnter );
}
static tracy_force_inline void LeaveFiber()
{
TracyQueuePrepare( QueueType::FiberLeave );
MemWrite( &item->fiberLeave.time, GetTime() );
TracyQueueCommit( fiberLeave );
}
#endif
void SendCallstack( int depth, const char* skipBefore );
static void CutCallstack( void* callstack, const char* skipBefore );

View File

@ -9,7 +9,7 @@ namespace tracy
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
enum : uint32_t { ProtocolVersion = 51 };
enum : uint32_t { ProtocolVersion = 52 };
enum : uint16_t { BroadcastVersion = 2 };
using lz4sz_t = uint32_t;

View File

@ -59,6 +59,8 @@ enum class QueueType : uint8_t
SymbolInformation,
CodeInformation,
ExternalNameMetadata,
FiberEnter,
FiberLeave,
Terminate,
KeepAlive,
ThreadContext,
@ -236,6 +238,19 @@ struct QueueLockAnnounce
LockType type;
};
struct QueueFiberEnter
{
int64_t time;
uint64_t fiber; // ptr
uint32_t thread;
};
struct QueueFiberLeave
{
int64_t time;
uint32_t thread;
};
struct QueueLockTerminate
{
uint32_t id;
@ -692,6 +707,8 @@ struct QueueItem
QueueParamSetup paramSetup;
QueueCpuTopology cpuTopology;
QueueExternalNameMetadata externalNameMetadata;
QueueFiberEnter fiberEnter;
QueueFiberLeave fiberLeave;
};
};
#pragma pack()
@ -750,7 +767,9 @@ static constexpr size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ),
sizeof( QueueHeader ) + sizeof( QueueSymbolInformation ),
sizeof( QueueHeader ) + sizeof( QueueCodeInformation ),
sizeof( QueueHeader), // ExternalNameMetadata - not for wire transfer
sizeof( QueueHeader ), // ExternalNameMetadata - not for wire transfer
sizeof( QueueHeader ) + sizeof( QueueFiberEnter ),
sizeof( QueueHeader ) + sizeof( QueueFiberLeave ),
// above items must be first
sizeof( QueueHeader ), // terminate
sizeof( QueueHeader ), // keep alive