Implement setting client parameters from server.

This commit is contained in:
Bartosz Taudul 2019-11-25 23:59:48 +01:00
parent c5c9dfb0c9
commit 4551553eb4
9 changed files with 135 additions and 2 deletions

View File

@ -64,6 +64,9 @@
#define TracyMessageCS(x,y,z,w)
#define TracyMessageLCS(x,y,z)
#define TracyParameterRegister(x)
#define TracyParameterSetup(x,y,z,w)
#else
#include "client/TracyLock.hpp"
@ -166,6 +169,9 @@
# define TracyMessageLCS( txt, color, depth ) TracyMessageLC( txt, color )
#endif
#define TracyParameterRegister( cb ) tracy::Profiler::ParameterRegister( cb );
#define TracyParameterSetup( idx, name, isBool, val ) tracy::Profiler::ParameterSetup( idx, name, isBool, val );
#endif
#endif

View File

@ -1054,6 +1054,7 @@ Profiler::Profiler()
, m_connectionId( 0 )
, m_deferredQueue( 64*1024 )
#endif
, m_paramCallback( nullptr )
{
assert( !s_instance );
s_instance = this;
@ -2264,6 +2265,9 @@ bool Profiler::HandleServerQuery()
SysTraceSendExternalName( ptr );
break;
#endif
case ServerQueryParameter:
HandleParameter( ptr );
break;
default:
assert( false );
break;
@ -2508,6 +2512,33 @@ void Profiler::ProcessSysTime()
}
#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

View File

@ -80,6 +80,8 @@ struct LuaZoneState
using Magic = moodycamel::ConcurrentQueueDefaultTraits::index_t;
typedef void(*ParameterCallback)( uint32_t idx, int32_t val );
class Profiler
{
struct FrameImageQueueItem
@ -442,6 +444,9 @@ public:
#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 );
static void CutCallstack( void* callstack, const char* skipBefore );
@ -506,6 +511,7 @@ private:
bool HandleServerQuery();
void HandleDisconnect();
void HandleParameter( uint64_t payload );
void CalibrateTimer();
void CalibrateDelay();
@ -605,6 +611,8 @@ private:
#else
void ProcessSysTime() {}
#endif
ParameterCallback m_paramCallback;
};
};

View File

@ -9,7 +9,7 @@ namespace tracy
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 };
using lz4sz_t = uint32_t;
@ -46,7 +46,8 @@ enum ServerQuery : uint8_t
ServerQueryCallstackFrame,
ServerQueryFrameName,
ServerQueryDisconnect,
ServerQueryExternalName
ServerQueryExternalName,
ServerQueryParameter
};
struct ServerQueryPacket

View File

@ -67,6 +67,7 @@ enum class QueueType : uint8_t
SysTimeReport,
TidToPid,
PlotConfig,
ParamSetup,
StringData,
ThreadName,
CustomStringData,
@ -348,6 +349,14 @@ struct QueuePlotConfig
uint8_t type;
};
struct QueueParamSetup
{
uint32_t idx;
uint64_t name; // ptr
uint8_t isBool;
int32_t val;
};
struct QueueHeader
{
union
@ -397,6 +406,7 @@ struct QueueItem
QueueThreadWakeup threadWakeup;
QueueTidToPid tidToPid;
QueuePlotConfig plotConfig;
QueueParamSetup paramSetup;
};
};
#pragma pack()
@ -465,6 +475,7 @@ static const size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
sizeof( QueueHeader ) + sizeof( QueuePlotConfig ),
sizeof( QueueHeader ) + sizeof( QueueParamSetup ),
// keep all QueueStringTransfer below
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name

View File

@ -593,6 +593,15 @@ struct CpuThreadData
enum { CpuThreadDataSize = sizeof( CpuThreadData ) };
struct Parameter
{
uint32_t idx;
StringRef name;
bool isBool;
int32_t val;
};
}
#endif

View File

@ -1070,6 +1070,49 @@ bool View::DrawConnection()
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;
}

View File

@ -3235,6 +3235,9 @@ bool Worker::Process( const QueueItem& ev )
case QueueType::TidToPid:
ProcessTidToPid( ev.tidToPid );
break;
case QueueType::ParamSetup:
ProcessParamSetup( ev.paramSetup );
break;
default:
assert( false );
break;
@ -4575,6 +4578,12 @@ void Worker::ProcessTidToPid( const QueueTidToPid& ev )
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 )
{
const auto val = (double)m_data.memory.usage;
@ -5670,4 +5679,13 @@ const char* Worker::UnpackFrameImage( const FrameImage& image )
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 );
}
}

View File

@ -419,6 +419,9 @@ public:
const char* PackFrameImage( const char* image, uint32_t inBytes, uint32_t& csz );
const char* UnpackFrameImage( const FrameImage& image );
const Vector<Parameter>& GetParameters() const { return m_params; }
void SetParameter( size_t paramIdx, int32_t val );
private:
void Network();
void Exec();
@ -479,6 +482,7 @@ private:
tracy_force_inline void ProcessContextSwitch( const QueueContextSwitch& ev );
tracy_force_inline void ProcessThreadWakeup( const QueueThreadWakeup& 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 void ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev );
@ -708,6 +712,8 @@ private:
#ifdef TRACY_NO_STATISTICS
Vector<ZoneEvent*> m_zoneEventPool;
#endif
Vector<Parameter> m_params;
};
}