Preserve messages size.

This commit is contained in:
Bartosz Taudul 2020-07-21 20:22:59 +02:00
parent 9d01fa86ab
commit 02e7893c75
4 changed files with 39 additions and 18 deletions

View File

@ -372,13 +372,14 @@ static inline int LuaMessage( lua_State* L )
auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt );
assert( size < std::numeric_limits<uint16_t>::max() );
TracyLfqPrepare( QueueType::Message );
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
MemWrite( &item->message.time, Profiler::GetTime() );
MemWrite( &item->message.text, (uint64_t)ptr );
MemWrite( &item->messageFat.time, Profiler::GetTime() );
MemWrite( &item->messageFat.text, (uint64_t)ptr );
MemWrite( &item->messageFat.size, (uint16_t)size );
TracyLfqCommit;
return 0;
}

View File

@ -1839,11 +1839,17 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
tracy_free( (void*)ptr );
break;
case QueueType::Message:
case QueueType::MessageColor:
case QueueType::MessageCallstack:
ptr = MemRead<uint64_t>( &item->messageFat.text );
size = MemRead<uint16_t>( &item->messageFat.size );
SendString( ptr, (const char*)ptr, size, QueueType::CustomStringData );
tracy_free( (void*)ptr );
break;
case QueueType::MessageColor:
case QueueType::MessageColorCallstack:
ptr = MemRead<uint64_t>( &item->message.text );
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
ptr = MemRead<uint64_t>( &item->messageColorFat.text );
size = MemRead<uint16_t>( &item->messageColorFat.size );
SendString( ptr, (const char*)ptr, size, QueueType::CustomStringData );
tracy_free( (void*)ptr );
break;
case QueueType::MessageAppInfo:

View File

@ -277,15 +277,16 @@ public:
static tracy_force_inline void Message( const char* txt, size_t size, int callstack )
{
assert( size < std::numeric_limits<uint16_t>::max() );
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
TracyLfqPrepare( callstack == 0 ? QueueType::Message : QueueType::MessageCallstack );
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
MemWrite( &item->message.time, GetTime() );
MemWrite( &item->message.text, (uint64_t)ptr );
MemWrite( &item->messageFat.time, GetTime() );
MemWrite( &item->messageFat.text, (uint64_t)ptr );
MemWrite( &item->messageFat.size, (uint16_t)size );
TracyLfqCommit;
if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack );
@ -306,18 +307,19 @@ public:
static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color, int callstack )
{
assert( size < std::numeric_limits<uint16_t>::max() );
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
TracyLfqPrepare( callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack );
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
MemWrite( &item->messageColor.time, GetTime() );
MemWrite( &item->messageColor.text, (uint64_t)ptr );
MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) );
MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) );
MemWrite( &item->messageColorFat.time, GetTime() );
MemWrite( &item->messageColorFat.text, (uint64_t)ptr );
MemWrite( &item->messageColorFat.r, uint8_t( ( color ) & 0xFF ) );
MemWrite( &item->messageColorFat.g, uint8_t( ( color >> 8 ) & 0xFF ) );
MemWrite( &item->messageColorFat.b, uint8_t( ( color >> 16 ) & 0xFF ) );
MemWrite( &item->messageColorFat.size, (uint16_t)size );
TracyLfqCommit;
if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack );

View File

@ -264,6 +264,16 @@ struct QueueMessageColor : public QueueMessage
uint8_t b;
};
struct QueueMessageFat : public QueueMessage
{
uint16_t size;
};
struct QueueMessageColorFat : public QueueMessageColor
{
uint16_t size;
};
// Don't change order, only add new entries at the end, this is also used on trace dumps!
enum class GpuContextType : uint8_t
{
@ -493,6 +503,8 @@ struct QueueItem
QueuePlotData plotData;
QueueMessage message;
QueueMessageColor messageColor;
QueueMessageFat messageFat;
QueueMessageColorFat messageColorFat;
QueueGpuNewContext gpuNewContext;
QueueGpuZoneBegin gpuZoneBegin;
QueueGpuZoneEnd gpuZoneEnd;