Added Profiler Exporting

This commit is contained in:
OusmBlueNinja 2025-04-19 11:35:04 -05:00
parent 9fc6c6f599
commit 84bce50ecb
7 changed files with 107159 additions and 24 deletions

81525
profile_export.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,5 @@
[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\Renderer.cpp -o src\build\Renderer.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\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 -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
[RUN] Executed app.exe successfully. [ERROR] Runtime crash
Command 'src\build\app.exe' returned non-zero exit status 3221225477.

View File

@ -39,6 +39,9 @@
#include <windows.h> #include <windows.h>
#include <commdlg.h> #include <commdlg.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <fstream>
#include <json.hpp>
using json = nlohmann::json;
static std::shared_ptr<Object> selected = nullptr; static std::shared_ptr<Object> selected = nullptr;
static bool playing = false; static bool playing = false;
@ -182,7 +185,6 @@ static ProfileNode GetAveragedFrameCopy(const ProfileNode &src)
void ShowProfilerTimeline() void ShowProfilerTimeline()
{ {
static ProfileNode cachedAveragedFrame; static ProfileNode cachedAveragedFrame;
static double lastUpdateTime = 0.0; static double lastUpdateTime = 0.0;
static double updateInterval = 0.25; static double updateInterval = 0.25;
@ -196,7 +198,6 @@ void ShowProfilerTimeline()
// --- Controls --- // --- Controls ---
if (g_engineConfig.settings.profile_enabled) if (g_engineConfig.settings.profile_enabled)
{ {
ImGui::Checkbox("Freeze View", &freezeView); ImGui::Checkbox("Freeze View", &freezeView);
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(100); ImGui::SetNextItemWidth(100);
@ -206,6 +207,24 @@ void ShowProfilerTimeline()
updateInterval = std::clamp(updateInterval, 0.05, 5.0); updateInterval = std::clamp(updateInterval, 0.05, 5.0);
// Export JSON button
ImGui::SameLine();
if (ImGui::Button("Export"))
{
json root = SerializeProfileNode(cachedAveragedFrame);
std::ofstream out("profile_export.json");
if (out.is_open())
{
out << root.dump(4);
out.close();
Logger::LogInfo("Profiler exported to profile_export.json");
}
else
{
Logger::LogError("Failed to write profiler export.");
}
}
if (!freezeView && latest && (now - lastUpdateTime) >= updateInterval) if (!freezeView && latest && (now - lastUpdateTime) >= updateInterval)
{ {
cachedAveragedFrame = GetAveragedFrameCopy(*latest); cachedAveragedFrame = GetAveragedFrameCopy(*latest);
@ -238,6 +257,7 @@ void ShowProfilerTimeline()
{ {
ImGui::Text("Profiling Disabled."); ImGui::Text("Profiling Disabled.");
} }
ImGui::End(); ImGui::End();
} }
@ -309,7 +329,6 @@ void ShowColorCorrectionWindow()
ImGui::SeparatorText("Bloom"); ImGui::SeparatorText("Bloom");
changed |= ImGui::Checkbox("Enable Bloom", &cc->bloom); changed |= ImGui::Checkbox("Enable Bloom", &cc->bloom);
changed |= ImGui::SliderFloat("Threshold", &cc->threshold, 0.0f, 2.0f, "%.2f"); changed |= ImGui::SliderFloat("Threshold", &cc->threshold, 0.0f, 2.0f, "%.2f");
changed |= ImGui::SliderFloat("Intensity", &cc->intensity, 0.0f, 4.0f, "%.2f"); changed |= ImGui::SliderFloat("Intensity", &cc->intensity, 0.0f, 4.0f, "%.2f");
@ -323,7 +342,6 @@ void ShowColorCorrectionWindow()
ImGui::End(); ImGui::End();
} }
void Engine::Init() void Engine::Init()
{ {

View File

@ -50,6 +50,31 @@ int Renderer::s_ClusterRows = 0;
GLuint Renderer::bloomFBO = 0; GLuint Renderer::bloomFBO = 0;
GLuint Renderer::bloomTexture = 0; GLuint Renderer::bloomTexture = 0;
struct CachedLightUniforms {
std::string posName;
std::string colorName;
std::string intensityName;
std::string radiusName;
};
std::vector<CachedLightUniforms> s_LightUniforms;
void InitLightUniforms(int maxLights) {
s_LightUniforms.clear();
s_LightUniforms.reserve(maxLights);
for (int i = 0; i < maxLights; ++i) {
s_LightUniforms.push_back({
"uLightPos[" + std::to_string(i) + "]",
"uLightColor[" + std::to_string(i) + "]",
"uLightIntensity[" + std::to_string(i) + "]",
"uLightRadius[" + std::to_string(i) + "]"
});
}
}
void Renderer::InitQuad() void Renderer::InitQuad()
{ {
float vertices[] = { float vertices[] = {
@ -112,6 +137,11 @@ void Renderer::Init()
SetColorCorrection(std::make_unique<ColorCorrection>()); SetColorCorrection(std::make_unique<ColorCorrection>());
{
Logger::LogVerbose("Renderer::InitLightUniforms(%d)", g_engineConfig.gl_maxLight);
InitLightUniforms(g_engineConfig.gl_maxLight);
}
glGenBuffers(1, &s_ClusterSSBO); glGenBuffers(1, &s_ClusterSSBO);
// Bloom textures and framebuffers // Bloom textures and framebuffers
@ -405,23 +435,28 @@ void Renderer::DrawSprite(SpriteComponent *sprite, const glm::vec2 &pos, float z
PROFILE_DEEP_SCOPE("ColorCorrection"); PROFILE_DEEP_SCOPE("ColorCorrection");
s_ColorCorrection->Upload(*shader); s_ColorCorrection->Upload(*shader);
} }
{
PROFILE_DEEP_SCOPE("SetLightParams");
shader->SetInt("uLightCount", static_cast<int>(s_Lights.size())); shader->SetInt("uLightCount", static_cast<int>(s_Lights.size()));
shader->SetInt("uClusterWidth", CLUSTER_SIZE); shader->SetInt("uClusterWidth", CLUSTER_SIZE);
shader->SetInt("uClusterHeight", CLUSTER_SIZE); shader->SetInt("uClusterHeight", CLUSTER_SIZE);
shader->SetInt("uClusterCols", s_ClusterCols); shader->SetInt("uClusterCols", s_ClusterCols);
shader->SetInt("uMaxLightsPerCluster", MAX_LIGHTS_PER_CLUSTER); shader->SetInt("uMaxLightsPerCluster", MAX_LIGHTS_PER_CLUSTER);
}
for (size_t i = 0; i < s_Lights.size(); ++i)
{ for (int i = 0; i < s_Lights.size(); ++i) {
PROFILE_DEEP_SCOPE(("L" + std::to_string(i)).c_str()); PROFILE_DEEP_SCOPE(("L" + std::to_string(i)).c_str());
shader->SetVec2(("uLightPos[" + std::to_string(i) + "]").c_str(), s_Lights[i].screenPos); const auto& u = s_LightUniforms[i];
shader->SetVec3(("uLightColor[" + std::to_string(i) + "]").c_str(), s_Lights[i].color); shader->SetVec2(u.posName.c_str(), s_Lights[i].screenPos);
shader->SetFloat(("uLightIntensity[" + std::to_string(i) + "]").c_str(), s_Lights[i].intensity); shader->SetVec3(u.colorName.c_str(), s_Lights[i].color);
shader->SetFloat(("uLightRadius[" + std::to_string(i) + "]").c_str(), s_Lights[i].radius); shader->SetFloat(u.intensityName.c_str(), s_Lights[i].intensity);
shader->SetFloat(u.radiusName.c_str(), s_Lights[i].radius);
} }
{ {
PROFILE_DEEP_SCOPE("BindNorm"); PROFILE_DEEP_SCOPE("BindNorm");
shader->SetInt("uNormalMap", 1); shader->SetInt("uNormalMap", 1);
@ -563,12 +598,9 @@ void Renderer::DrawGizmoCircle(
glEnd(); glEnd();
} }
GLuint Renderer::GetFinalTexture() GLuint Renderer::GetFinalTexture()
{ {
PROFILE_SCOPE("Renderer::GetFinalTexture"); PROFILE_ENGINE_SCOPE("Renderer::GetFinalTexture");
GLuint sceneTex = GetRenderTexture(); GLuint sceneTex = GetRenderTexture();
@ -630,8 +662,6 @@ GLuint Renderer::GetFinalTexture()
return bloomTexture; return bloomTexture;
} }
GLuint Renderer::GetRenderTexture() GLuint Renderer::GetRenderTexture()
{ {
return textureColorBuffer; return textureColorBuffer;

View File

@ -1,6 +1,12 @@
#include "Profiler.h" #include "Profiler.h"
#include <cmath> #include <cmath>
#include <fstream>
#include <json.hpp>
using json = nlohmann::json;
extern float g_fps; extern float g_fps;
extern EngineConfig g_engineConfig; extern EngineConfig g_engineConfig;
@ -115,4 +121,21 @@ const ProfileNode* HierarchicalProfiler::GetLatestFrame() const {
return frameHistory.empty() ? nullptr : &frameHistory.back(); return frameHistory.empty() ? nullptr : &frameHistory.back();
} }
json SerializeProfileNode(const ProfileNode& node) {
json j;
j["name"] = node.name;
j["startMs"] = node.startMs;
j["durationMs"] = node.durationMs;
j["visualStartMs"] = node.visualStartMs;
j["visualDurationMs"] = node.visualDurationMs;
for (const auto& child : node.children) {
j["children"].push_back(SerializeProfileNode(child));
}
return j;
}
HierarchicalProfiler profiler; HierarchicalProfiler profiler;

View File

@ -4,6 +4,11 @@
#include <chrono> #include <chrono>
#include "EngineConfig.h" #include "EngineConfig.h"
#include <json.hpp>
using json = nlohmann::json;
struct ProfileNode { struct ProfileNode {
std::string name; std::string name;
double startMs = 0.0; double startMs = 0.0;
@ -48,6 +53,8 @@ private:
size_t ProfilesLastFrame = 128; size_t ProfilesLastFrame = 128;
}; };
json SerializeProfileNode(const ProfileNode& node);
extern HierarchicalProfiler profiler; extern HierarchicalProfiler profiler;
struct ScopedProfile { struct ScopedProfile {

25530
src/vendor/json.hpp vendored Normal file

File diff suppressed because it is too large Load Diff