mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 04:23:51 +00:00
Implement setting client parameters from server.
This commit is contained in:
parent
c5c9dfb0c9
commit
4551553eb4
@ -64,6 +64,9 @@
|
|||||||
#define TracyMessageCS(x,y,z,w)
|
#define TracyMessageCS(x,y,z,w)
|
||||||
#define TracyMessageLCS(x,y,z)
|
#define TracyMessageLCS(x,y,z)
|
||||||
|
|
||||||
|
#define TracyParameterRegister(x)
|
||||||
|
#define TracyParameterSetup(x,y,z,w)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include "client/TracyLock.hpp"
|
#include "client/TracyLock.hpp"
|
||||||
@ -166,6 +169,9 @@
|
|||||||
# define TracyMessageLCS( txt, color, depth ) TracyMessageLC( txt, color )
|
# define TracyMessageLCS( txt, color, depth ) TracyMessageLC( txt, color )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TracyParameterRegister( cb ) tracy::Profiler::ParameterRegister( cb );
|
||||||
|
#define TracyParameterSetup( idx, name, isBool, val ) tracy::Profiler::ParameterSetup( idx, name, isBool, val );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1054,6 +1054,7 @@ Profiler::Profiler()
|
|||||||
, m_connectionId( 0 )
|
, m_connectionId( 0 )
|
||||||
, m_deferredQueue( 64*1024 )
|
, m_deferredQueue( 64*1024 )
|
||||||
#endif
|
#endif
|
||||||
|
, m_paramCallback( nullptr )
|
||||||
{
|
{
|
||||||
assert( !s_instance );
|
assert( !s_instance );
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
@ -2264,6 +2265,9 @@ bool Profiler::HandleServerQuery()
|
|||||||
SysTraceSendExternalName( ptr );
|
SysTraceSendExternalName( ptr );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case ServerQueryParameter:
|
||||||
|
HandleParameter( ptr );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert( false );
|
assert( false );
|
||||||
break;
|
break;
|
||||||
@ -2508,6 +2512,33 @@ void Profiler::ProcessSysTime()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void Profiler::ParameterSetup( uint32_t idx, const char* name, bool isBool, int32_t val )
|
||||||
|
{
|
||||||
|
tracy::Magic magic;
|
||||||
|
auto token = tracy::GetToken();
|
||||||
|
auto& tail = token->get_tail_index();
|
||||||
|
auto item = token->enqueue_begin( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ParamSetup );
|
||||||
|
tracy::MemWrite( &item->paramSetup.idx, idx );
|
||||||
|
tracy::MemWrite( &item->paramSetup.name, (uint64_t)name );
|
||||||
|
tracy::MemWrite( &item->paramSetup.isBool, (uint8_t)isBool );
|
||||||
|
tracy::MemWrite( &item->paramSetup.val, val );
|
||||||
|
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
DeferItem( *item );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Profiler::HandleParameter( uint64_t payload )
|
||||||
|
{
|
||||||
|
assert( m_paramCallback );
|
||||||
|
const auto idx = uint32_t( payload >> 32 );
|
||||||
|
const auto val = int32_t( payload & 0xFFFFFFFF );
|
||||||
|
m_paramCallback( idx, val );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -80,6 +80,8 @@ struct LuaZoneState
|
|||||||
using Magic = moodycamel::ConcurrentQueueDefaultTraits::index_t;
|
using Magic = moodycamel::ConcurrentQueueDefaultTraits::index_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef void(*ParameterCallback)( uint32_t idx, int32_t val );
|
||||||
|
|
||||||
class Profiler
|
class Profiler
|
||||||
{
|
{
|
||||||
struct FrameImageQueueItem
|
struct FrameImageQueueItem
|
||||||
@ -442,6 +444,9 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ParameterRegister( ParameterCallback cb ) { GetProfiler().m_paramCallback = cb; }
|
||||||
|
static void ParameterSetup( uint32_t idx, const char* name, bool isBool, int32_t val );
|
||||||
|
|
||||||
void SendCallstack( int depth, const char* skipBefore );
|
void SendCallstack( int depth, const char* skipBefore );
|
||||||
static void CutCallstack( void* callstack, const char* skipBefore );
|
static void CutCallstack( void* callstack, const char* skipBefore );
|
||||||
|
|
||||||
@ -506,6 +511,7 @@ private:
|
|||||||
|
|
||||||
bool HandleServerQuery();
|
bool HandleServerQuery();
|
||||||
void HandleDisconnect();
|
void HandleDisconnect();
|
||||||
|
void HandleParameter( uint64_t payload );
|
||||||
|
|
||||||
void CalibrateTimer();
|
void CalibrateTimer();
|
||||||
void CalibrateDelay();
|
void CalibrateDelay();
|
||||||
@ -605,6 +611,8 @@ private:
|
|||||||
#else
|
#else
|
||||||
void ProcessSysTime() {}
|
void ProcessSysTime() {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ParameterCallback m_paramCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ namespace tracy
|
|||||||
|
|
||||||
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
||||||
|
|
||||||
enum : uint32_t { ProtocolVersion = 23 };
|
enum : uint32_t { ProtocolVersion = 24 };
|
||||||
enum : uint32_t { BroadcastVersion = 0 };
|
enum : uint32_t { BroadcastVersion = 0 };
|
||||||
|
|
||||||
using lz4sz_t = uint32_t;
|
using lz4sz_t = uint32_t;
|
||||||
@ -46,7 +46,8 @@ enum ServerQuery : uint8_t
|
|||||||
ServerQueryCallstackFrame,
|
ServerQueryCallstackFrame,
|
||||||
ServerQueryFrameName,
|
ServerQueryFrameName,
|
||||||
ServerQueryDisconnect,
|
ServerQueryDisconnect,
|
||||||
ServerQueryExternalName
|
ServerQueryExternalName,
|
||||||
|
ServerQueryParameter
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ServerQueryPacket
|
struct ServerQueryPacket
|
||||||
|
@ -67,6 +67,7 @@ enum class QueueType : uint8_t
|
|||||||
SysTimeReport,
|
SysTimeReport,
|
||||||
TidToPid,
|
TidToPid,
|
||||||
PlotConfig,
|
PlotConfig,
|
||||||
|
ParamSetup,
|
||||||
StringData,
|
StringData,
|
||||||
ThreadName,
|
ThreadName,
|
||||||
CustomStringData,
|
CustomStringData,
|
||||||
@ -348,6 +349,14 @@ struct QueuePlotConfig
|
|||||||
uint8_t type;
|
uint8_t type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct QueueParamSetup
|
||||||
|
{
|
||||||
|
uint32_t idx;
|
||||||
|
uint64_t name; // ptr
|
||||||
|
uint8_t isBool;
|
||||||
|
int32_t val;
|
||||||
|
};
|
||||||
|
|
||||||
struct QueueHeader
|
struct QueueHeader
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
@ -397,6 +406,7 @@ struct QueueItem
|
|||||||
QueueThreadWakeup threadWakeup;
|
QueueThreadWakeup threadWakeup;
|
||||||
QueueTidToPid tidToPid;
|
QueueTidToPid tidToPid;
|
||||||
QueuePlotConfig plotConfig;
|
QueuePlotConfig plotConfig;
|
||||||
|
QueueParamSetup paramSetup;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
@ -465,6 +475,7 @@ static const size_t QueueDataSize[] = {
|
|||||||
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
|
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
|
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueuePlotConfig ),
|
sizeof( QueueHeader ) + sizeof( QueuePlotConfig ),
|
||||||
|
sizeof( QueueHeader ) + sizeof( QueueParamSetup ),
|
||||||
// keep all QueueStringTransfer below
|
// keep all QueueStringTransfer below
|
||||||
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
|
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
|
||||||
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name
|
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name
|
||||||
|
@ -593,6 +593,15 @@ struct CpuThreadData
|
|||||||
|
|
||||||
enum { CpuThreadDataSize = sizeof( CpuThreadData ) };
|
enum { CpuThreadDataSize = sizeof( CpuThreadData ) };
|
||||||
|
|
||||||
|
|
||||||
|
struct Parameter
|
||||||
|
{
|
||||||
|
uint32_t idx;
|
||||||
|
StringRef name;
|
||||||
|
bool isBool;
|
||||||
|
int32_t val;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1070,6 +1070,49 @@ bool View::DrawConnection()
|
|||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& params = m_worker.GetParameters();
|
||||||
|
if( !params.empty() )
|
||||||
|
{
|
||||||
|
ImGui::Separator();
|
||||||
|
if( ImGui::TreeNode( "Trace parameters" ) )
|
||||||
|
{
|
||||||
|
ImGui::Columns( 2 );
|
||||||
|
ImGui::TextUnformatted( "Name" );
|
||||||
|
ImGui::NextColumn();
|
||||||
|
ImGui::TextUnformatted( "Value" );
|
||||||
|
ImGui::NextColumn();
|
||||||
|
ImGui::Separator();
|
||||||
|
size_t idx = 0;
|
||||||
|
for( auto& p : params )
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted( m_worker.GetString( p.name ) );
|
||||||
|
ImGui::NextColumn();
|
||||||
|
ImGui::PushID( idx );
|
||||||
|
if( p.isBool )
|
||||||
|
{
|
||||||
|
bool val = p.val;
|
||||||
|
if( ImGui::Checkbox( "", &val ) )
|
||||||
|
{
|
||||||
|
m_worker.SetParameter( idx, int32_t( val ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto val = int( p.val );
|
||||||
|
if( ImGui::InputInt( "", &val, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue ) )
|
||||||
|
{
|
||||||
|
m_worker.SetParameter( idx, int32_t( val ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
ImGui::NextColumn();
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
ImGui::EndColumns();
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3235,6 +3235,9 @@ bool Worker::Process( const QueueItem& ev )
|
|||||||
case QueueType::TidToPid:
|
case QueueType::TidToPid:
|
||||||
ProcessTidToPid( ev.tidToPid );
|
ProcessTidToPid( ev.tidToPid );
|
||||||
break;
|
break;
|
||||||
|
case QueueType::ParamSetup:
|
||||||
|
ProcessParamSetup( ev.paramSetup );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert( false );
|
assert( false );
|
||||||
break;
|
break;
|
||||||
@ -4575,6 +4578,12 @@ void Worker::ProcessTidToPid( const QueueTidToPid& ev )
|
|||||||
m_data.tidToPid.emplace( ev.tid, ev.pid );
|
m_data.tidToPid.emplace( ev.tid, ev.pid );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Worker::ProcessParamSetup( const QueueParamSetup& ev )
|
||||||
|
{
|
||||||
|
CheckString( ev.name );
|
||||||
|
m_params.push_back( Parameter { ev.idx, StringRef( StringRef::Ptr, ev.name ), bool( ev.isBool ), ev.val } );
|
||||||
|
}
|
||||||
|
|
||||||
void Worker::MemAllocChanged( int64_t time )
|
void Worker::MemAllocChanged( int64_t time )
|
||||||
{
|
{
|
||||||
const auto val = (double)m_data.memory.usage;
|
const auto val = (double)m_data.memory.usage;
|
||||||
@ -5670,4 +5679,13 @@ const char* Worker::UnpackFrameImage( const FrameImage& image )
|
|||||||
return m_frameImageCompressedBuffer;
|
return m_frameImageCompressedBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Worker::SetParameter( size_t paramIdx, int32_t val )
|
||||||
|
{
|
||||||
|
assert( paramIdx < m_params.size() );
|
||||||
|
m_params[paramIdx].val = val;
|
||||||
|
const auto idx = uint64_t( m_params[paramIdx].idx );
|
||||||
|
const auto v = uint64_t( uint32_t( val ) );
|
||||||
|
Query( ServerQueryParameter, ( idx << 32 ) | val );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -419,6 +419,9 @@ public:
|
|||||||
const char* PackFrameImage( const char* image, uint32_t inBytes, uint32_t& csz );
|
const char* PackFrameImage( const char* image, uint32_t inBytes, uint32_t& csz );
|
||||||
const char* UnpackFrameImage( const FrameImage& image );
|
const char* UnpackFrameImage( const FrameImage& image );
|
||||||
|
|
||||||
|
const Vector<Parameter>& GetParameters() const { return m_params; }
|
||||||
|
void SetParameter( size_t paramIdx, int32_t val );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Network();
|
void Network();
|
||||||
void Exec();
|
void Exec();
|
||||||
@ -479,6 +482,7 @@ private:
|
|||||||
tracy_force_inline void ProcessContextSwitch( const QueueContextSwitch& ev );
|
tracy_force_inline void ProcessContextSwitch( const QueueContextSwitch& ev );
|
||||||
tracy_force_inline void ProcessThreadWakeup( const QueueThreadWakeup& ev );
|
tracy_force_inline void ProcessThreadWakeup( const QueueThreadWakeup& ev );
|
||||||
tracy_force_inline void ProcessTidToPid( const QueueTidToPid& ev );
|
tracy_force_inline void ProcessTidToPid( const QueueTidToPid& ev );
|
||||||
|
tracy_force_inline void ProcessParamSetup( const QueueParamSetup& ev );
|
||||||
|
|
||||||
tracy_force_inline ZoneEvent* AllocZoneEvent();
|
tracy_force_inline ZoneEvent* AllocZoneEvent();
|
||||||
tracy_force_inline void ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev );
|
tracy_force_inline void ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev );
|
||||||
@ -708,6 +712,8 @@ private:
|
|||||||
#ifdef TRACY_NO_STATISTICS
|
#ifdef TRACY_NO_STATISTICS
|
||||||
Vector<ZoneEvent*> m_zoneEventPool;
|
Vector<ZoneEvent*> m_zoneEventPool;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Vector<Parameter> m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user