Updated Script profiler

This commit is contained in:
OusmBlueNinja 2025-04-19 17:22:14 -05:00
parent 84bce50ecb
commit d7a0ca53c8
7 changed files with 1281 additions and 81404 deletions

View File

@ -77,6 +77,8 @@
"fstream": "cpp", "fstream": "cpp",
"codecvt": "cpp", "codecvt": "cpp",
"*.inc": "cpp", "*.inc": "cpp",
"future": "cpp" "future": "cpp",
"any": "cpp",
"ranges": "cpp"
} }
} }

View File

@ -27,7 +27,7 @@ DockId=0x00000009,0
[Window][Viewport] [Window][Viewport]
Pos=387,19 Pos=387,19
Size=1533,597 Size=1533,442
Collapsed=0 Collapsed=0
DockId=0x00000007,0 DockId=0x00000007,0
@ -36,8 +36,8 @@ Size=1280,19
Collapsed=0 Collapsed=0
[Window][Performance Info] [Window][Performance Info]
Pos=1672,618 Pos=1672,463
Size=248,315 Size=248,470
Collapsed=0 Collapsed=0
DockId=0x00000003,0 DockId=0x00000003,0
@ -54,8 +54,8 @@ Collapsed=0
DockId=0x00000007,1 DockId=0x00000007,1
[Window][Profiler] [Window][Profiler]
Pos=387,618 Pos=387,463
Size=1283,306 Size=1283,461
Collapsed=0 Collapsed=0
DockId=0x0000000B,0 DockId=0x0000000B,0
@ -89,12 +89,12 @@ DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=
DockNode ID=0x00000009 Parent=0x00000001 SizeRef=385,623 HiddenTabBar=1 Selected=0x12EF0F59 DockNode ID=0x00000009 Parent=0x00000001 SizeRef=385,623 HiddenTabBar=1 Selected=0x12EF0F59
DockNode ID=0x0000000A Parent=0x00000001 SizeRef=385,533 HiddenTabBar=1 Selected=0x36DC96AB DockNode ID=0x0000000A Parent=0x00000001 SizeRef=385,533 HiddenTabBar=1 Selected=0x36DC96AB
DockNode ID=0x00000002 Parent=0x11111111 SizeRef=1533,701 Split=Y Selected=0xC450F867 DockNode ID=0x00000002 Parent=0x11111111 SizeRef=1533,701 Split=Y Selected=0xC450F867
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,597 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867 DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,442 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,559 Split=X Selected=0x9B5D3198 DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,714 Split=X Selected=0x9B5D3198
DockNode ID=0x00000005 Parent=0x00000008 SizeRef=1283,481 Split=Y Selected=0x9B5D3198 DockNode ID=0x00000005 Parent=0x00000008 SizeRef=1283,481 Split=Y Selected=0x9B5D3198
DockNode ID=0x0000000B Parent=0x00000005 SizeRef=1283,306 HiddenTabBar=1 Selected=0x9B5D3198 DockNode ID=0x0000000B Parent=0x00000005 SizeRef=1283,461 HiddenTabBar=1 Selected=0x9B5D3198
DockNode ID=0x0000000C Parent=0x00000005 SizeRef=1283,251 HiddenTabBar=1 Selected=0xEA83D666 DockNode ID=0x0000000C Parent=0x00000005 SizeRef=1283,251 HiddenTabBar=1 Selected=0xEA83D666
DockNode ID=0x00000006 Parent=0x00000008 SizeRef=248,481 Split=Y Selected=0x3FC1A724 DockNode ID=0x00000006 Parent=0x00000008 SizeRef=248,481 Split=Y Selected=0x3FC1A724
DockNode ID=0x00000003 Parent=0x00000006 SizeRef=226,315 HiddenTabBar=1 Selected=0x3FC1A724 DockNode ID=0x00000003 Parent=0x00000006 SizeRef=226,470 HiddenTabBar=1 Selected=0x3FC1A724
DockNode ID=0x00000004 Parent=0x00000006 SizeRef=226,242 HiddenTabBar=1 Selected=0xA873C17F DockNode ID=0x00000004 Parent=0x00000006 SizeRef=226,242 HiddenTabBar=1 Selected=0xA873C17F

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,3 @@
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\utils\Profiler.cpp -o src\build\utils\Profiler.o [COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -Isrc\vendor\imgui -IC:\msys64\mingw64\lib\libyaml-cpp.a -MMD -MP -c src\src\Components\ScriptComponent.cpp -o src\build\Components\ScriptComponent.o
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\Engine.cpp -o src\build\Engine.o
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\Entitys\Object.o src\build\utils\EngineConfig.o src\build\utils\ExceptionHandler.o src\build\utils\FileDialog.o src\build\utils\GameObjectsList.o src\build\utils\Logging.o src\build\utils\Profiler.o src\build\utils\Shader.o src\build\utils\UID.o src\build\utils\utils.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto [LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\Entitys\Object.o src\build\utils\EngineConfig.o src\build\utils\ExceptionHandler.o src\build\utils\FileDialog.o src\build\utils\GameObjectsList.o src\build\utils\Logging.o src\build\utils\Profiler.o src\build\utils\Shader.o src\build\utils\UID.o src\build\utils\utils.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto
[ERROR] Runtime crash [RUN] Executed app.exe successfully.
Command 'src\build\app.exe' returned non-zero exit status 3221225477.

View File

@ -1,6 +1,6 @@
engine_version: 0.1.0 engine_version: 0.1.0
scene_name: lighting_test_2 scene_name: lighting_test_2
scene_hash: c084720adfdfb7fefd6c0c6c1654d18bc2245da4d222165c332b57dcc8d78c12 scene_hash: f1652fd7fe4a93ec56d94e4c343609bbce35d5190f9badd04e281fa8404eeaed
format_version: 1 format_version: 1
objects: objects:
- name: Tiles - name: Tiles
@ -115,7 +115,7 @@ objects:
- name: Red - name: Red
uid: 6afde2dd47aa4557b6afb1a607c99dc8 uid: 6afde2dd47aa4557b6afb1a607c99dc8
id: 13 id: 13
position: [1079.61902, 527.103088] position: [702.594421, 1407.01233]
rotation: 0 rotation: 0
layer: 2 layer: 2
visable: true visable: true
@ -127,13 +127,13 @@ objects:
- 0 - 0
intensity: 2 intensity: 2
radius: 1000 radius: 1000
falloff: 0.100000001 falloff: 1
type: 0 type: 0
children: [] children: []
- name: Green - name: Green
uid: 0f950d76d24b4dc18f54cab2c3aaaf9a uid: 0f950d76d24b4dc18f54cab2c3aaaf9a
id: 14 id: 14
position: [1426.51587, 1320.61597] position: [853.004333, 554.148438]
rotation: 0 rotation: 0
layer: 2 layer: 2
visable: true visable: true
@ -151,7 +151,7 @@ objects:
- name: Blue - name: Blue
uid: 09f722f51c7c4b0f98de3a0a16d127c4 uid: 09f722f51c7c4b0f98de3a0a16d127c4
id: 15 id: 15
position: [565.865173, 1224.28101] position: [1516.40125, 1110.83923]
rotation: 0 rotation: 0
layer: 2 layer: 2
visable: true visable: true
@ -214,5 +214,5 @@ color_correction:
saturation: 2 saturation: 2
gamma: 1.05999994 gamma: 1.05999994
bloom: true bloom: true
intensity: 1.21000004 intensity: 1.40999997
threshold: 0.25 threshold: 0.300000012

View File

@ -11,6 +11,8 @@
#include "../Components/TilemapComponent.h" #include "../Components/TilemapComponent.h"
#include "../utils/Profiler.h" #include "../utils/Profiler.h"
#include "../utils/utils.h"
#include <lua.hpp> #include <lua.hpp>
#include <memory> #include <memory>
@ -45,30 +47,49 @@ void ScriptComponent::SetScriptPath(const std::string &path)
} }
const std::string &ScriptComponent::GetScriptPath() const { return scriptPath; } const std::string &ScriptComponent::GetScriptPath() const { return scriptPath; }
void ScriptComponent::Hook(lua_State* L, lua_Debug* ar) { void ScriptComponent::Hook(lua_State *L, lua_Debug *ar)
if (!g_engineConfig.settings.profile_deep) return; {
if (!g_engineConfig.settings.profile_deep)
return;
lua_getinfo(L, "nS", ar); // Quickly fetch component from Lua extraspace
ScriptComponent *self = *reinterpret_cast<ScriptComponent **>(lua_getextraspace(L));
if (!self || (ar->event != LUA_HOOKCALL && ar->event != LUA_HOOKRET))
return;
ScriptComponent* self = *reinterpret_cast<ScriptComponent**>(lua_getextraspace(L)); // Only fetch debug info if needed
if (!self) return; if (!lua_getinfo(L, "nS", ar))
return;
std::string name = ar->name ? ar->name : "unknown"; // Only build label if entering a function
std::string label = name + "()"; if (ar->event == LUA_HOOKCALL)
{
const char *name = ar->name;
std::string label;
if (ar->event == LUA_HOOKCALL) { if (name && *name)
self->luaCallStack.push_back(label); {
profiler.BeginDeepSection(label); label = name;
} else if (ar->event == LUA_HOOKRET) {
if (!self->luaCallStack.empty()) {
profiler.EndDeepSection();
self->luaCallStack.pop_back();
} }
else if (ar->short_src && *ar->short_src)
{
label = GetFilenameFromPath(ar->short_src);
}
else
{
label = "unknown";
}
self->luaCallStack.emplace_back(label);
profiler.BeginDeepSection(label);
}
else if (ar->event == LUA_HOOKRET && !self->luaCallStack.empty())
{
profiler.EndDeepSection();
self->luaCallStack.pop_back();
} }
} }
static int Lua_LogInfo(lua_State *L) static int Lua_LogInfo(lua_State *L)
{ {
PROFILE_DEEP_SCOPE("Lua_LogInfo"); PROFILE_DEEP_SCOPE("Lua_LogInfo");
@ -276,11 +297,10 @@ void ScriptComponent::ReloadScript()
lua_close(L); lua_close(L);
L = luaL_newstate(); L = luaL_newstate();
*(ScriptComponent**)lua_getextraspace(L) = this; *(ScriptComponent **)lua_getextraspace(L) = this;
luaL_openlibs(L); luaL_openlibs(L);
lua_sethook(L, Hook, LUA_MASKCALL | LUA_MASKRET, 0); lua_sethook(L, Hook, LUA_MASKCALL | LUA_MASKRET, 0);
RegisterObjectType(L); RegisterObjectType(L);
RegisterVector2Type(L); RegisterVector2Type(L);
RegisterEngineBindings(); RegisterEngineBindings();

View File

@ -7,13 +7,14 @@
static std::map<std::string, GLuint> textureCache; static std::map<std::string, GLuint> textureCache;
GLuint LoadTextureIfNeeded(const std::string& path) { GLuint LoadTextureIfNeeded(const std::string &path)
{
if (textureCache.count(path)) if (textureCache.count(path))
return textureCache[path]; return textureCache[path];
int w, h, channels; int w, h, channels;
stbi_set_flip_vertically_on_load(false); stbi_set_flip_vertically_on_load(false);
unsigned char* data = stbi_load(path.c_str(), &w, &h, &channels, 4); unsigned char *data = stbi_load(path.c_str(), &w, &h, &channels, 4);
if (!data) if (!data)
return 0; return 0;
@ -29,22 +30,30 @@ GLuint LoadTextureIfNeeded(const std::string& path) {
return id; return id;
} }
std::string GetFilenameFromPath(const std::string& path) #include <unordered_map>
#include <mutex>
std::string GetFilenameFromPath(const std::string &path)
{ {
size_t lastSlash = path.find_last_of("/\\"); static std::unordered_map<std::string, std::string> cache;
std::string filename = (lastSlash == std::string::npos) ? path : path.substr(lastSlash + 1); static std::mutex cacheMutex;
// Strip trailing slashes std::scoped_lock lock(cacheMutex);
while (!filename.empty() && (filename.back() == '/' || filename.back() == '\\'))
filename.pop_back();
auto it = cache.find(path);
if (it != cache.end())
return it->second;
// Extract filename
size_t pos1 = path.find_last_of("/\\");
std::string filename = (pos1 == std::string::npos) ? path : path.substr(pos1 + 1);
cache[path] = filename;
return filename; return filename;
} }
bool DeleteLatestLogFile()
{
bool DeleteLatestLogFile() {
// Get %USERPROFILE% // Get %USERPROFILE%
char userPath[MAX_PATH]; char userPath[MAX_PATH];
DWORD len = GetEnvironmentVariableA("USERPROFILE", userPath, MAX_PATH); DWORD len = GetEnvironmentVariableA("USERPROFILE", userPath, MAX_PATH);
@ -53,11 +62,12 @@ bool DeleteLatestLogFile() {
std::filesystem::path logPath = std::filesystem::path(userPath) / ".CreateEngine" / ".latest.log"; std::filesystem::path logPath = std::filesystem::path(userPath) / ".CreateEngine" / ".latest.log";
if (std::filesystem::exists(logPath)) { if (std::filesystem::exists(logPath))
{
std::error_code ec; std::error_code ec;
std::filesystem::remove(logPath, ec); std::filesystem::remove(logPath, ec);
return !ec; // true = success return !ec; // true = success
} }
return false; // File didn't exist return false; // File didn't exist
} }