1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

implement lua hook function

This commit is contained in:
AnthoFoxo 2025-02-26 21:09:31 -05:00
parent b8c2e25c3d
commit 54dcbc87ad
No known key found for this signature in database
GPG Key ID: 16E2924603B5D6E7

View File

@ -120,6 +120,8 @@ static inline void LuaRemove( char* script )
}
}
static inline void LuaHook( lua_State* L, lua_Debug* ar ) {}
}
#else
@ -439,6 +441,44 @@ static inline void LuaRegister( lua_State* L )
static inline void LuaRemove( char* script ) {}
static inline void LuaHook( lua_State* L, lua_Debug* ar )
{
if ( ar->event == LUA_HOOKCALL )
{
#ifdef TRACY_ON_DEMAND
const auto zoneCnt = GetLuaZoneState().counter++;
if ( zoneCnt != 0 && !GetLuaZoneState().active ) return;
GetLuaZoneState().active = GetProfiler().IsConnected();
if ( !GetLuaZoneState().active ) return;
#endif
lua_getinfo( L, "Snl", ar );
char src[256];
detail::LuaShortenSrc( src, ar->short_src );
const auto srcloc = Profiler::AllocSourceLocation( ar->currentline, src, ar->name ? ar->name : ar->short_src );
TracyQueuePrepare( QueueType::ZoneBeginAllocSrcLoc );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, srcloc );
TracyQueueCommit( zoneBeginThread );
}
else if (ar->event == LUA_HOOKRET) {
#ifdef TRACY_ON_DEMAND
assert( GetLuaZoneState().counter != 0 );
GetLuaZoneState().counter--;
if ( !GetLuaZoneState().active ) return;
if ( !GetProfiler().IsConnected() )
{
GetLuaZoneState().active = false;
return;
}
#endif
TracyQueuePrepare( QueueType::ZoneEnd );
MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
TracyQueueCommit( zoneEndThread );
}
}
}
#endif