Preserve zone text, zone name string length.

This commit is contained in:
Bartosz Taudul 2020-07-21 20:09:25 +02:00
parent 986a2a79da
commit 9d01fa86ab
4 changed files with 36 additions and 20 deletions

View File

@ -125,6 +125,7 @@ static inline void LuaRemove( char* script )
#else
#include <assert.h>
#include <limits>
#include "common/TracyColor.hpp"
#include "common/TracyAlign.hpp"
@ -328,12 +329,13 @@ static inline int LuaZoneText( lua_State* L )
auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt );
assert( size < std::numeric_limits<uint16_t>::max() );
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
TracyLfqPrepare( QueueType::ZoneText );
MemWrite( &item->zoneText.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommit;
return 0;
}
@ -351,12 +353,13 @@ static inline int LuaZoneName( lua_State* L )
auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt );
assert( size < std::numeric_limits<uint16_t>::max() );
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
TracyLfqPrepare( QueueType::ZoneName );
MemWrite( &item->zoneText.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommit;
return 0;
}

View File

@ -1825,6 +1825,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
while( sz-- > 0 )
{
uint64_t ptr;
uint16_t size;
auto idx = MemRead<uint8_t>( &item->hdr.idx );
if( idx < (int)QueueType::Terminate )
{
@ -1832,8 +1833,9 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
{
case QueueType::ZoneText:
case QueueType::ZoneName:
ptr = MemRead<uint64_t>( &item->zoneText.text );
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
ptr = MemRead<uint64_t>( &item->zoneTextFat.text );
size = MemRead<uint16_t>( &item->zoneTextFat.size );
SendString( ptr, (const char*)ptr, size, QueueType::CustomStringData );
tracy_free( (void*)ptr );
break;
case QueueType::Message:
@ -3046,10 +3048,10 @@ TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
if( !ctx.active ) return;
auto ptr = (char*)tracy::tracy_malloc( size+1 );
auto ptr = (char*)tracy::tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
#ifndef TRACY_NO_VERIFY
{
TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
@ -3059,17 +3061,18 @@ TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size
#endif
{
TracyLfqPrepareC( tracy::QueueType::ZoneText );
tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr );
tracy::MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
tracy::MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommitC;
}
}
TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
if( !ctx.active ) return;
auto ptr = (char*)tracy::tracy_malloc( size+1 );
auto ptr = (char*)tracy::tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
#ifndef TRACY_NO_VERIFY
{
TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
@ -3079,7 +3082,8 @@ TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size
#endif
{
TracyLfqPrepareC( tracy::QueueType::ZoneName );
tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr );
tracy::MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
tracy::MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommitC;
}
}

View File

@ -1,6 +1,7 @@
#ifndef __TRACYSCOPED_HPP__
#define __TRACYSCOPED_HPP__
#include <limits>
#include <stdint.h>
#include <string.h>
@ -64,29 +65,31 @@ public:
tracy_force_inline void Text( const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
if( !m_active ) return;
#ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return;
#endif
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
TracyLfqPrepare( QueueType::ZoneText );
MemWrite( &item->zoneText.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommit;
}
tracy_force_inline void Name( const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
if( !m_active ) return;
#ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return;
#endif
auto ptr = (char*)tracy_malloc( size+1 );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
ptr[size] = '\0';
TracyLfqPrepare( QueueType::ZoneName );
MemWrite( &item->zoneText.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommit;
}

View File

@ -170,6 +170,11 @@ struct QueueZoneText
uint64_t text; // ptr
};
struct QueueZoneTextFat : public QueueZoneText
{
uint16_t size;
};
enum class LockType : uint8_t
{
Lockable,
@ -477,6 +482,7 @@ struct QueueItem
QueueFrameImage frameImageLean;
QueueSourceLocation srcloc;
QueueZoneText zoneText;
QueueZoneTextFat zoneTextFat;
QueueLockAnnounce lockAnnounce;
QueueLockTerminate lockTerminate;
QueueLockWait lockWait;