From fcda1f6a7f75c19bbd0ef39e37d021202ada74a7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 9 Oct 2021 15:35:11 +0200 Subject: [PATCH] Keep Lua zone insertion time to a minimum. No functional changes here. Only the variable retrieval was separated from filling in the queue items. While with the async queue this makes no difference, it will be important when the serial queue is used here. --- TracyLua.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/TracyLua.hpp b/TracyLua.hpp index a9a95c96..0e835a0f 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -204,11 +204,12 @@ static inline int LuaZoneBeginS( lua_State* L ) #endif SendLuaCallstack( L, depth ); - TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); lua_Debug dbg; lua_getstack( L, 1, &dbg ); lua_getinfo( L, "Snl", &dbg ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); + + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; @@ -232,13 +233,14 @@ static inline int LuaZoneBeginNS( lua_State* L ) #endif SendLuaCallstack( L, depth ); - TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); lua_Debug dbg; lua_getstack( L, 1, &dbg ); lua_getinfo( L, "Snl", &dbg ); size_t nsz; const auto name = lua_tolstring( L, 1, &nsz ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); + + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; @@ -259,11 +261,12 @@ static inline int LuaZoneBegin( lua_State* L ) if( !GetLuaZoneState().active ) return 0; #endif - TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); lua_Debug dbg; lua_getstack( L, 1, &dbg ); lua_getinfo( L, "Snl", &dbg ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); + + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; @@ -283,13 +286,14 @@ static inline int LuaZoneBeginN( lua_State* L ) if( !GetLuaZoneState().active ) return 0; #endif - TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); lua_Debug dbg; lua_getstack( L, 1, &dbg ); lua_getinfo( L, "Snl", &dbg ); size_t nsz; const auto name = lua_tolstring( L, 1, &nsz ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); + + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; @@ -333,6 +337,7 @@ static inline int LuaZoneText( lua_State* L ) auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); + TracyLfqPrepare( QueueType::ZoneText ); MemWrite( &item->zoneTextFat.text, (uint64_t)ptr ); MemWrite( &item->zoneTextFat.size, (uint16_t)size ); @@ -357,6 +362,7 @@ static inline int LuaZoneName( lua_State* L ) auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); + TracyLfqPrepare( QueueType::ZoneName ); MemWrite( &item->zoneTextFat.text, (uint64_t)ptr ); MemWrite( &item->zoneTextFat.size, (uint16_t)size ); @@ -374,9 +380,10 @@ static inline int LuaMessage( lua_State* L ) const auto size = strlen( txt ); assert( size < std::numeric_limits::max() ); - TracyLfqPrepare( QueueType::Message ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); + + TracyLfqPrepare( QueueType::Message ); MemWrite( &item->messageFat.time, Profiler::GetTime() ); MemWrite( &item->messageFat.text, (uint64_t)ptr ); MemWrite( &item->messageFat.size, (uint16_t)size );