mirror of
https://github.com/wolfpld/tracy.git
synced 2026-01-18 17:11:26 +01:00
Add lua to test/test.cpp
This commit is contained in:
2
.github/workflows/linux.yml
vendored
2
.github/workflows/linux.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
container: archlinux:base-devel
|
container: archlinux:base-devel
|
||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pacman -Syu --noconfirm && pacman -S --noconfirm --needed freetype2 debuginfod wayland dbus libxkbcommon libglvnd meson cmake git wayland-protocols nodejs
|
run: pacman -Syu --noconfirm && pacman -S --noconfirm --needed freetype2 debuginfod wayland dbus libxkbcommon libglvnd meson cmake git wayland-protocols nodejs lua
|
||||||
- name: Trust git repo
|
- name: Trust git repo
|
||||||
run: git config --global --add safe.directory '*'
|
run: git config --global --add safe.directory '*'
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|||||||
@@ -21,6 +21,17 @@ add_executable(tracy-test test.cpp)
|
|||||||
target_link_options(tracy-test PRIVATE -rdynamic)
|
target_link_options(tracy-test PRIVATE -rdynamic)
|
||||||
target_link_libraries(tracy-test TracyClient)
|
target_link_libraries(tracy-test TracyClient)
|
||||||
|
|
||||||
|
# Lua support (optional)
|
||||||
|
find_package(Lua)
|
||||||
|
if(LUA_FOUND)
|
||||||
|
message(STATUS "Lua found, enabling Lua support in tracy-test")
|
||||||
|
target_compile_definitions(tracy-test PRIVATE TRACY_HAS_LUA)
|
||||||
|
target_include_directories(tracy-test PRIVATE ${LUA_INCLUDE_DIR})
|
||||||
|
target_link_libraries(tracy-test ${LUA_LIBRARIES})
|
||||||
|
else()
|
||||||
|
message(STATUS "Lua not found, building tracy-test without Lua support")
|
||||||
|
endif()
|
||||||
|
|
||||||
# OS-specific options
|
# OS-specific options
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||||
|
|||||||
@@ -7,6 +7,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "tracy/Tracy.hpp"
|
#include "tracy/Tracy.hpp"
|
||||||
|
|
||||||
|
#ifdef TRACY_HAS_LUA
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
#include <lualib.h>
|
||||||
|
#include "tracy/TracyLua.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define STBI_ONLY_JPEG
|
#define STBI_ONLY_JPEG
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
@@ -344,6 +351,87 @@ void ArenaAllocatorTest()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TRACY_HAS_LUA
|
||||||
|
|
||||||
|
void LuaTest()
|
||||||
|
{
|
||||||
|
tracy::SetThreadName( "Lua test" );
|
||||||
|
|
||||||
|
lua_State* L = luaL_newstate();
|
||||||
|
luaL_openlibs( L );
|
||||||
|
tracy::LuaRegister( L );
|
||||||
|
|
||||||
|
const char* luaScript = R"(
|
||||||
|
for i = 1, 10 do
|
||||||
|
tracy.ZoneBeginN("Lua iteration")
|
||||||
|
tracy.ZoneText("Iteration: " .. i)
|
||||||
|
tracy.Message("Lua message: " .. i)
|
||||||
|
tracy.ZoneEnd()
|
||||||
|
end
|
||||||
|
)";
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
||||||
|
ZoneScopedN( "Lua script execution" );
|
||||||
|
|
||||||
|
if( luaL_dostring( L, luaScript ) != 0 )
|
||||||
|
{
|
||||||
|
const char* error = lua_tostring( L, -1 );
|
||||||
|
TracyLogString( tracy::MessageSeverity::Error, 0, TRACY_CALLSTACK, error );
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_close( L );
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaHookTest()
|
||||||
|
{
|
||||||
|
tracy::SetThreadName( "Lua hook test" );
|
||||||
|
|
||||||
|
lua_State* L = luaL_newstate();
|
||||||
|
luaL_openlibs( L );
|
||||||
|
tracy::LuaRegister( L );
|
||||||
|
|
||||||
|
// Enable Lua hook for automatic function profiling
|
||||||
|
lua_sethook( L, tracy::LuaHook, LUA_MASKCALL | LUA_MASKRET, 0 );
|
||||||
|
|
||||||
|
const char* luaScript = R"(
|
||||||
|
function fibonacci(n)
|
||||||
|
if n < 2 then
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
return fibonacci(n-1) + fibonacci(n-2)
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, 5 do
|
||||||
|
local result = fibonacci(10)
|
||||||
|
end
|
||||||
|
)";
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
|
||||||
|
ZoneScopedN( "Lua hook script execution" );
|
||||||
|
|
||||||
|
if( luaL_dostring( L, luaScript ) != 0 )
|
||||||
|
{
|
||||||
|
const char* error = lua_tostring( L, -1 );
|
||||||
|
TracyLogString( tracy::MessageSeverity::Error, 0, TRACY_CALLSTACK, error );
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_close( L );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@@ -382,6 +470,10 @@ int main()
|
|||||||
auto t21 = std::thread( DeadlockTest1 );
|
auto t21 = std::thread( DeadlockTest1 );
|
||||||
auto t22 = std::thread( DeadlockTest2 );
|
auto t22 = std::thread( DeadlockTest2 );
|
||||||
auto t23 = std::thread( ArenaAllocatorTest );
|
auto t23 = std::thread( ArenaAllocatorTest );
|
||||||
|
#ifdef TRACY_HAS_LUA
|
||||||
|
auto t24 = std::thread( LuaTest );
|
||||||
|
auto t25 = std::thread( LuaHookTest );
|
||||||
|
#endif
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
auto image = stbi_load( "image.jpg", &x, &y, nullptr, 4 );
|
auto image = stbi_load( "image.jpg", &x, &y, nullptr, 4 );
|
||||||
|
|||||||
Reference in New Issue
Block a user