1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Support for setting zone names in lua.

This commit is contained in:
Bartosz Taudul
2017-11-11 17:56:41 +01:00
parent 59ec40c045
commit 81735aea2f
7 changed files with 61 additions and 12 deletions
+23
View File
@@ -25,6 +25,8 @@ static inline void LuaRegister( lua_State* L )
lua_pushcfunction( L, detail::noop );
lua_setfield( L, -2, "ZoneText" );
lua_pushcfunction( L, detail::noop );
lua_setfield( L, -2, "ZoneName" );
lua_pushcfunction( L, detail::noop );
lua_setfield( L, -2, "Message" );
lua_setglobal( L, "tracy" );
}
@@ -173,6 +175,25 @@ static inline int LuaZoneText( lua_State* L )
return 0;
}
static inline int LuaZoneName( lua_State* L )
{
auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt );
Magic magic;
auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size );
ptr[size] = '\0';
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneNameLiteral;
item->zoneName.thread = GetThreadHandle();
item->zoneName.name = (uint64_t)ptr;
tail.store( magic + 1, std::memory_order_release );
return 0;
}
static inline int LuaMessage( lua_State* L )
{
auto txt = lua_tostring( L, 1 );
@@ -204,6 +225,8 @@ static inline void LuaRegister( lua_State* L )
lua_setfield( L, -2, "ZoneEnd" );
lua_pushcfunction( L, detail::LuaZoneText );
lua_setfield( L, -2, "ZoneText" );
lua_pushcfunction( L, detail::LuaZoneName );
lua_setfield( L, -2, "ZoneName" );
lua_pushcfunction( L, detail::LuaMessage );
lua_setfield( L, -2, "Message" );
lua_setglobal( L, "tracy" );