Support transfer of zone name in source location payload.

This commit is contained in:
Bartosz Taudul 2017-11-14 23:54:52 +01:00 committed by Bartosz Taudul
parent 9eace41f0d
commit 334224dd36
2 changed files with 25 additions and 14 deletions

View File

@ -118,8 +118,8 @@ static inline int LuaZoneBegin( lua_State* L )
lua_getinfo( L, "Snl", &dbg ); lua_getinfo( L, "Snl", &dbg );
const uint32_t line = dbg.currentline; const uint32_t line = dbg.currentline;
const auto name = dbg.name ? dbg.name : dbg.short_src; const auto func = dbg.name ? dbg.name : dbg.short_src;
const auto fsz = strlen( name ); const auto fsz = strlen( func );
const auto ssz = strlen( dbg.source ); const auto ssz = strlen( dbg.source );
// Data layout: // Data layout:
@ -129,13 +129,14 @@ static inline int LuaZoneBegin( lua_State* L )
// fsz function name // fsz function name
// 1b null terminator // 1b null terminator
// ssz source file name // ssz source file name
const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz; // 1b null terminator
const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz + 1;
auto ptr = (char*)tracy_malloc( sz ); auto ptr = (char*)tracy_malloc( sz );
memcpy( ptr, &sz, 4 ); memcpy( ptr, &sz, 4 );
memcpy( ptr + 4, &color, 4 ); memcpy( ptr + 4, &color, 4 );
memcpy( ptr + 8, &line, 4 ); memcpy( ptr + 8, &line, 4 );
memcpy( ptr + 12, name, fsz+1 ); memcpy( ptr + 12, func, fsz+1 );
memcpy( ptr + 12 + fsz + 1, dbg.source, ssz ); memcpy( ptr + 12 + fsz + 1, dbg.source, ssz + 1 );
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
@ -158,8 +159,10 @@ static inline int LuaZoneBeginN( lua_State* L )
lua_getinfo( L, "Snl", &dbg ); lua_getinfo( L, "Snl", &dbg );
const uint32_t line = dbg.currentline; const uint32_t line = dbg.currentline;
const auto name = dbg.name ? dbg.name : dbg.short_src; const auto func = dbg.name ? dbg.name : dbg.short_src;
const auto fsz = strlen( name ); size_t nsz;
const auto name = lua_tolstring( L, 1, &nsz );
const auto fsz = strlen( func );
const auto ssz = strlen( dbg.source ); const auto ssz = strlen( dbg.source );
// Data layout: // Data layout:
@ -169,13 +172,16 @@ static inline int LuaZoneBeginN( lua_State* L )
// fsz function name // fsz function name
// 1b null terminator // 1b null terminator
// ssz source file name // ssz source file name
const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz; // 1b null terminator
// nsz zone name
const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz + 1 + nsz;
auto ptr = (char*)tracy_malloc( sz ); auto ptr = (char*)tracy_malloc( sz );
memcpy( ptr, &sz, 4 ); memcpy( ptr, &sz, 4 );
memcpy( ptr + 4, &color, 4 ); memcpy( ptr + 4, &color, 4 );
memcpy( ptr + 8, &line, 4 ); memcpy( ptr + 8, &line, 4 );
memcpy( ptr + 12, name, fsz+1 ); memcpy( ptr + 12, func, fsz+1 );
memcpy( ptr + 12 + fsz + 1, dbg.source, ssz ); memcpy( ptr + 12 + fsz + 1, dbg.source, ssz + 1 );
memcpy( ptr + 12 + fsz + 1 + ssz + 1, name, nsz );
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;

View File

@ -1020,14 +1020,19 @@ void View::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz )
memcpy( &line, data + 4, 4 ); memcpy( &line, data + 4, 4 );
data += 8; data += 8;
auto end = data; auto end = data;
while( *end ) end++;
while( *end ) end++;
const auto func = StoreString( data, end - data ); const auto func = StoreString( data, end - data );
end++; end++;
const auto ssz = sz - ( end - start );
const auto source = StoreString( end, ssz );
SourceLocation srcloc { StringRef(), StringRef( StringRef::Idx, func.idx ), StringRef( StringRef::Idx, source.idx ), line, color }; data = end;
while( *end ) end++;
const auto source = StoreString( data, end - data );
end++;
const auto nsz = sz - ( end - start );
SourceLocation srcloc { nsz == 0 ? StringRef() : StringRef( StringRef::Idx, StoreString( end, nsz ).idx ), StringRef( StringRef::Idx, func.idx ), StringRef( StringRef::Idx, source.idx ), line, color };
auto it = m_sourceLocationPayloadMap.find( &srcloc ); auto it = m_sourceLocationPayloadMap.find( &srcloc );
if( it == m_sourceLocationPayloadMap.end() ) if( it == m_sourceLocationPayloadMap.end() )
{ {