Add second single string transfer.

This commit is contained in:
Bartosz Taudul 2020-07-26 01:32:49 +02:00
parent a7d2ab4d4f
commit c0b73c248f
5 changed files with 61 additions and 21 deletions

View File

@ -2264,6 +2264,21 @@ void Profiler::SendSingleString( const char* ptr, size_t len )
AppendDataUnsafe( ptr, l16 );
}
void Profiler::SendSecondString( const char* ptr, size_t len )
{
QueueItem item;
MemWrite( &item.hdr.type, QueueType::SecondStringData );
assert( len <= std::numeric_limits<uint16_t>::max() );
auto l16 = uint16_t( len );
NeedDataSize( QueueDataSize[(int)QueueType::SecondStringData] + sizeof( l16 ) + l16 );
AppendDataUnsafe( &item, QueueDataSize[(int)QueueType::SecondStringData] );
AppendDataUnsafe( &l16, sizeof( l16 ) );
AppendDataUnsafe( ptr, l16 );
}
void Profiler::SendLongString( uint64_t str, const char* ptr, size_t len, QueueType type )
{
assert( type == QueueType::FrameImageData ||
@ -2410,11 +2425,10 @@ void Profiler::SendCallstackFrame( uint64_t ptr )
const auto& frame = frameData.data[i];
SendSingleString( frame.name );
SendString( uint64_t( frame.file ), frame.file, QueueType::CustomStringData );
SendSecondString( frame.file );
QueueItem item;
MemWrite( &item.hdr.type, QueueType::CallstackFrame );
MemWrite( &item.callstackFrame.file, (uint64_t)frame.file );
MemWrite( &item.callstackFrame.line, frame.line );
MemWrite( &item.callstackFrame.symAddr, frame.symAddr );
MemWrite( &item.callstackFrame.symLen, frame.symLen );

View File

@ -487,6 +487,8 @@ public:
void SendString( uint64_t str, const char* ptr, size_t len, QueueType type );
void SendSingleString( const char* ptr ) { SendSingleString( ptr, strlen( ptr ) ); }
void SendSingleString( const char* ptr, size_t len );
void SendSecondString( const char* ptr ) { SendSecondString( ptr, strlen( ptr ) ); }
void SendSecondString( const char* ptr, size_t len );
// Allocated source location data layout:

View File

@ -84,6 +84,7 @@ enum class QueueType : uint8_t
ParamPingback,
CpuTopology,
SingleStringData,
SecondStringData,
StringData,
ThreadName,
CustomStringData,
@ -395,7 +396,6 @@ struct QueueCallstackFrameSize
struct QueueCallstackFrame
{
uint64_t file;
uint32_t line;
uint64_t symAddr;
uint32_t symLen;
@ -625,6 +625,7 @@ static constexpr size_t QueueDataSize[] = {
sizeof( QueueHeader ), // param pingback
sizeof( QueueHeader ) + sizeof( QueueCpuTopology ),
sizeof( QueueHeader ), // single string data
sizeof( QueueHeader ), // second string data
// keep all QueueStringTransfer below
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name

View File

@ -2672,7 +2672,8 @@ void Worker::Exec()
!m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 ||
m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || m_pendingFrameImageData.image != nullptr ||
!m_pendingSymbols.empty() || !m_pendingSymbolCode.empty() || m_pendingCodeInformation != 0 ||
!m_serverQueryQueue.empty() || m_pendingSourceLocationPayload != 0 || m_pendingSingleString.ptr != nullptr )
!m_serverQueryQueue.empty() || m_pendingSourceLocationPayload != 0 || m_pendingSingleString.ptr != nullptr ||
m_pendingSecondString.ptr != nullptr )
{
continue;
}
@ -2941,20 +2942,29 @@ bool Worker::DispatchProcess( const QueueItem& ev, const char*& ptr )
}
return true;
}
else if( ev.hdr.type == QueueType::SingleStringData )
{
ptr += sizeof( QueueHeader );
uint16_t sz;
memcpy( &sz, ptr, sizeof( sz ) );
ptr += sizeof( sz );
AddSingleString( ptr, sz );
ptr += sz;
return true;
}
else
{
ptr += QueueDataSize[ev.hdr.idx];
return Process( ev );
uint16_t sz;
switch( ev.hdr.type )
{
case QueueType::SingleStringData:
ptr += sizeof( QueueHeader );
memcpy( &sz, ptr, sizeof( sz ) );
ptr += sizeof( sz );
AddSingleString( ptr, sz );
ptr += sz;
return true;
case QueueType::SecondStringData:
ptr += sizeof( QueueHeader );
memcpy( &sz, ptr, sizeof( sz ) );
ptr += sizeof( sz );
AddSecondString( ptr, sz );
ptr += sz;
return true;
default:
ptr += QueueDataSize[ev.hdr.idx];
return Process( ev );
}
}
}
@ -3366,6 +3376,12 @@ void Worker::AddSingleString( const char* str, size_t sz )
m_pendingSingleString = StoreString( str, sz );
}
void Worker::AddSecondString( const char* str, size_t sz )
{
assert( m_pendingSecondString.ptr == nullptr );
m_pendingSecondString = StoreString( str, sz );
}
void Worker::AddExternalName( uint64_t ptr, const char* str, size_t sz )
{
assert( m_pendingExternalNames > 0 );
@ -3834,6 +3850,14 @@ uint32_t Worker::GetSingleStringIdx()
return idx;
}
uint32_t Worker::GetSecondStringIdx()
{
assert( m_pendingSecondString.ptr != nullptr );
const auto idx = m_pendingSecondString.idx;
m_pendingSecondString.ptr = nullptr;
return idx;
}
StringLocation Worker::StoreString( const char* str, size_t sz )
{
StringLocation ret;
@ -5421,11 +5445,7 @@ void Worker::ProcessCallstackFrame( const QueueCallstackFrame& ev )
assert( m_pendingCallstackSubframes > 0 );
const auto nitidx = GetSingleStringIdx();
auto fit = m_pendingCustomStrings.find( ev.file );
assert( fit != m_pendingCustomStrings.end() );
const auto fitidx = fit->second.idx;
m_pendingCustomStrings.erase( fit );
const auto fitidx = GetSecondStringIdx();
if( m_callstackFrameStaging )
{

View File

@ -739,6 +739,7 @@ private:
void AddThreadString( uint64_t id, const char* str, size_t sz );
void AddCustomString( uint64_t ptr, const char* str, size_t sz );
void AddSingleString( const char* str, size_t sz );
void AddSecondString( const char* str, size_t sz );
void AddExternalName( uint64_t ptr, const char* str, size_t sz );
void AddExternalThreadName( uint64_t ptr, const char* str, size_t sz );
void AddFrameImageData( uint64_t ptr, const char* data, size_t sz );
@ -762,6 +763,7 @@ private:
void DispatchFailure( const QueueItem& ev, const char*& ptr );
uint32_t GetSingleStringIdx();
uint32_t GetSecondStringIdx();
StringLocation StoreString( const char* str, size_t sz );
const ContextSwitch* const GetContextSwitchDataImpl( uint64_t thread );
@ -859,6 +861,7 @@ private:
unordered_flat_set<StringRef, StringRefHasher, StringRefComparator> m_pendingFileStrings;
unordered_flat_set<StringRef, StringRefHasher, StringRefComparator> m_checkedFileStrings;
StringLocation m_pendingSingleString = {};
StringLocation m_pendingSecondString = {};
uint32_t m_pendingStrings;
uint32_t m_pendingThreads;