Draw the profiler tree.

This commit is contained in:
Irlan 2019-04-03 19:12:17 -03:00
parent 7c15a8eaf8
commit 4407e31d8a
5 changed files with 60 additions and 0 deletions

View File

@ -124,6 +124,11 @@ static void Run()
g_profiler->EndScope();
if (g_settings->drawProfileTree)
{
g_view->InterfaceProfileTree();
}
g_profilerRecorder->BuildRecords();
if (g_settings->drawProfile)

View File

@ -58,6 +58,9 @@ public:
// End the top scope.
void EndScope();
// Get the root profiler node.
ProfilerNode* GetRoot() { return m_root; }
private:
friend class ProfilerRecorder;

View File

@ -19,6 +19,7 @@
#include <testbed/framework/view.h>
#include <testbed/framework/view_model.h>
#include <testbed/framework/test.h>
#include <testbed/framework/profiler.h>
#include <imgui/imgui.h>
#if defined (U_OPENGL_2)
@ -218,6 +219,7 @@ void View::Interface()
if (ImGui::BeginMenu("View"))
{
ImGui::MenuItem("Profile", "", &settings.drawProfile);
ImGui::MenuItem("Profile Tree", "", &settings.drawProfileTree);
ImGui::MenuItem("Statistics", "", &settings.drawStats);
ImGui::Separator();
@ -400,6 +402,53 @@ void View::Interface()
ImGui::End();
}
static void TreeNode(ProfilerNode* node, u32& index)
{
ImGui::PushID(index);
++index;
if (ImGui::TreeNode(node->name))
{
float64 elapsedTime = node->t1 - node->t0;
ImGui::Text("%.4f [ms]", elapsedTime);
for (u32 i = 0; i < node->children.Count(); ++i)
{
TreeNode(node->children[i], index);
}
ImGui::TreePop();
}
ImGui::PopID();
}
void View::InterfaceProfileTree()
{
ImGui::Begin("Overlay", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
ImVec2 ws = ImGui::GetWindowSize();
ImVec2 wp = ImGui::GetWindowPos();
ImGui::End();
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::SetNextWindowBgAlpha(0.0f);
ImGui::SetNextWindowPos(ImVec2(0.0f, wp.y + ws.y));
ImGui::SetNextWindowSize(ImVec2(g_camera->m_width - 250.0f, 0.0f));
ImGui::Begin("##ProfileTree", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize);
ProfilerNode* root = g_profiler->GetRoot();
if (root)
{
u32 index = 0;
TreeNode(root, index);
}
ImGui::End();
ImGui::PopStyleVar();
}
void View::EndInterface()
{
ImGui::PopStyleVar();

View File

@ -41,6 +41,7 @@ public:
void BeginInterface();
void Interface();
void InterfaceProfileTree();
void EndInterface();
private:
friend class ViewModel;

View File

@ -33,6 +33,7 @@ struct Settings
drawTriangles = true;
drawGrid = true;
drawProfile = false;
drawProfileTree = false;
drawStats = false;
}
@ -43,6 +44,7 @@ struct Settings
bool drawTriangles;
bool drawGrid;
bool drawProfile;
bool drawProfileTree;
bool drawStats;
};