mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-08 04:29:48 -06:00
Enable the sorting of performance measurement values
This commit is contained in:
@@ -27,8 +27,12 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/misc/sharedmemory.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <cppformat/format.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "GuiPerformanceComponent";
|
||||
@@ -40,6 +44,7 @@ namespace gui {
|
||||
void GuiPerformanceComponent::initialize() {
|
||||
_minMaxValues[0] = 100.f;
|
||||
_minMaxValues[1] = 250.f;
|
||||
_sortingSelection = -1;
|
||||
}
|
||||
|
||||
void GuiPerformanceComponent::deinitialize() {
|
||||
@@ -82,26 +87,108 @@ void GuiPerformanceComponent::render() {
|
||||
ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 10000.f);
|
||||
_minMaxValues[1] = fmaxf(_minMaxValues[0], _minMaxValues[1]);
|
||||
|
||||
// The indices correspond to the index into the average array further below
|
||||
ImGui::Text("Sorting");
|
||||
ImGui::RadioButton("No Sorting", &_sortingSelection, -1);
|
||||
ImGui::RadioButton("UpdateEphemeris", &_sortingSelection, 0);
|
||||
ImGui::RadioButton("UpdateRender", &_sortingSelection, 1);
|
||||
ImGui::RadioButton("RenderTime", &_sortingSelection, 2);
|
||||
|
||||
if (!_performanceMemory)
|
||||
_performanceMemory = new ghoul::SharedMemory(RenderEngine::PerformanceMeasurementSharedData);
|
||||
|
||||
|
||||
void* ptr = _performanceMemory->memory();
|
||||
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
|
||||
|
||||
for (int i = 0; i < layout->nEntries; ++i) {
|
||||
const PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i];
|
||||
PerformanceLayout layout = *reinterpret_cast<PerformanceLayout*>(ptr);
|
||||
|
||||
std::vector<size_t> indices(layout.nEntries);
|
||||
std::iota(indices.begin(), indices.end(), 0);
|
||||
|
||||
// Ordering:
|
||||
// updateEphemeris
|
||||
// UpdateRender
|
||||
// RenderTime
|
||||
std::vector<std::array<float, 3>> averages(layout.nEntries, { 0.f, 0.f, 0.f });
|
||||
|
||||
for (int i = 0; i < layout.nEntries; ++i) {
|
||||
const PerformanceLayout::PerformanceLayoutEntry& entry = layout.entries[i];
|
||||
|
||||
int v[3] = { 0, 0, 0 };
|
||||
|
||||
for (int j = 0; j < nValues; ++j) {
|
||||
averages[i][0] += entry.updateEphemeris[j];
|
||||
if (entry.updateEphemeris[j] != 0.f)
|
||||
++v[0];
|
||||
averages[i][1] += entry.updateRenderable[j];
|
||||
if (entry.updateRenderable[j] != 0.f)
|
||||
++v[1];
|
||||
averages[i][2] += entry.renderTime[j];
|
||||
if (entry.renderTime[j] != 0.f)
|
||||
++v[2];
|
||||
}
|
||||
|
||||
if (v[0] != 0)
|
||||
averages[i][0] /= static_cast<float>(v[0]);
|
||||
if (v[1] != 0)
|
||||
averages[i][1] /= static_cast<float>(v[1]);
|
||||
if (v[2] != 0)
|
||||
averages[i][2] /= static_cast<float>(v[2]);
|
||||
}
|
||||
|
||||
if (_sortingSelection != -1) {
|
||||
int sortIndex = _sortingSelection;
|
||||
|
||||
std::sort(
|
||||
indices.begin(),
|
||||
indices.end(),
|
||||
[sortIndex, &averages](int a, int b) {
|
||||
return averages[a][sortIndex] > averages[b][sortIndex];
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < layout.nEntries; ++i) {
|
||||
const PerformanceLayout::PerformanceLayoutEntry& entry = layout.entries[indices[i]];
|
||||
|
||||
if (ImGui::CollapsingHeader(entry.name)) {
|
||||
std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us";
|
||||
ImGui::PlotLines("UpdateEphemeris", &entry.updateEphemeris[0], layout->nValuesPerEntry, 0, updateEphemerisTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
;
|
||||
ImGui::PlotLines(
|
||||
fmt::format("UpdateEphemeris\nAverage: {}us", averages[i][0]).c_str(),
|
||||
&entry.updateEphemeris[0],
|
||||
layout.nValuesPerEntry,
|
||||
0,
|
||||
updateEphemerisTime.c_str(),
|
||||
_minMaxValues[0],
|
||||
_minMaxValues[1],
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
|
||||
std::string updateRenderableTime = std::to_string(entry.updateRenderable[entry.currentUpdateRenderable - 1]) + "us";
|
||||
ImGui::PlotLines("UpdateRender", &entry.updateRenderable[0], layout->nValuesPerEntry, 0, updateRenderableTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
ImGui::PlotLines(
|
||||
fmt::format("UpdateRender\nAverage: {}us", averages[i][1]).c_str(),
|
||||
&entry.updateRenderable[0],
|
||||
layout.nValuesPerEntry,
|
||||
0,
|
||||
updateRenderableTime.c_str(),
|
||||
_minMaxValues[0],
|
||||
_minMaxValues[1],
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
|
||||
std::string renderTime = std::to_string(entry.renderTime[entry.currentRenderTime - 1]) + "us";
|
||||
ImGui::PlotLines("RenderTime", &entry.renderTime[0], layout->nValuesPerEntry, 0, renderTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
ImGui::PlotLines(
|
||||
fmt::format("RenderTime\nAverage: {}us", averages[i][2]).c_str(),
|
||||
&entry.renderTime[0],
|
||||
layout.nValuesPerEntry,
|
||||
0,
|
||||
renderTime.c_str(),
|
||||
_minMaxValues[0],
|
||||
_minMaxValues[1],
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user