More cleanup of Gui code

Added IswaGroup properties to the iSWA properties list
Enable sorting the performance measurements by total time
This commit is contained in:
Alexander Bock
2016-06-28 19:22:50 +02:00
parent 3417f45805
commit cf80788067
17 changed files with 339 additions and 525 deletions

View File

@@ -39,30 +39,39 @@
namespace {
const std::string _loggerCat = "GuiPerformanceComponent";
enum class Sorting {
NoSorting = -1,
UpdateEphemeris = 0,
UpdateRender = 1,
Render = 2,
Total = 3
};
}
namespace openspace {
namespace gui {
void GuiPerformanceComponent::initialize() {
_sortingSelection = -1;
_sceneGraphIsEnabled = false;
_functionsIsEnabled = false;
}
void GuiPerformanceComponent::deinitialize() {
delete _performanceMemory;
_performanceMemory = nullptr;
}
void GuiPerformanceComponent::render() {
using ghoul::SharedMemory;
using namespace performance;
ImGui::Begin("Performance", &_isEnabled);
if (OsEng.renderEngine().doesPerformanceMeasurements() &&
ghoul::SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData))
{
if (OsEng.renderEngine().doesPerformanceMeasurements()) {
ghoul_assert(
SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData),
"Shared Memory block was not allocated"
);
if (!_performanceMemory) {
_performanceMemory = std::make_unique<ghoul::SharedMemory>(
PerformanceManager::PerformanceMeasurementSharedData
);
}
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(
_performanceMemory->memory()
);
ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled);
ImGui::Checkbox("Functions", &_functionsIsEnabled);
@@ -77,18 +86,34 @@ void GuiPerformanceComponent::render() {
// 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(PerformanceManager::PerformanceMeasurementSharedData);
void* ptr = _performanceMemory->memory();
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
ImGui::RadioButton(
"No Sorting",
&_sortingSelection,
static_cast<int>(Sorting::NoSorting)
);
ImGui::RadioButton(
"UpdateEphemeris",
&_sortingSelection,
static_cast<int>(Sorting::UpdateEphemeris)
);
ImGui::RadioButton(
"UpdateRender",
&_sortingSelection,
static_cast<int>(Sorting::UpdateRender)
);
ImGui::RadioButton(
"RenderTime",
&_sortingSelection,
static_cast<int>(Sorting::Render)
);
ImGui::RadioButton(
"TotalTime",
&_sortingSelection,
static_cast<int>(Sorting::Total)
);
// Later, we will sort this indices list instead of the real values for
// performance reasons
std::vector<size_t> indices(layout->nScaleGraphEntries);
std::iota(indices.begin(), indices.end(), 0);
@@ -96,36 +121,44 @@ void GuiPerformanceComponent::render() {
// updateEphemeris
// UpdateRender
// RenderTime
std::vector<std::array<float, 3>> averages(layout->nScaleGraphEntries, { 0.f, 0.f, 0.f });
std::vector<std::array<float, 3>> averages(
layout->nScaleGraphEntries,
{ 0.f, 0.f, 0.f }
);
std::vector<std::array<std::pair<float, float>, 3>> minMax(
layout->nScaleGraphEntries
);
for (int i = 0; i < layout->nScaleGraphEntries; ++i) {
const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i];
int v[3] = { 0, 0, 0 };
const PerformanceLayout::SceneGraphPerformanceLayout& entry =
layout->sceneGraphEntries[i];
int nValues[3] = { 0, 0, 0 };
// Compute the averages and count the number of values so we don't divide
// by 0 later
for (int j = 0; j < PerformanceLayout::NumberValues; ++j) {
averages[i][0] += entry.updateEphemeris[j];
if (entry.updateEphemeris[j] != 0.f)
++(v[0]);
++(nValues[0]);
averages[i][1] += entry.updateRenderable[j];
if (entry.updateRenderable[j] != 0.f)
++(v[1]);
++(nValues[1]);
averages[i][2] += entry.renderTime[j];
if (entry.renderTime[j] != 0.f)
++(v[2]);
++(nValues[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 (nValues[0] != 0)
averages[i][0] /= static_cast<float>(nValues[0]);
if (nValues[1] != 0)
averages[i][1] /= static_cast<float>(nValues[1]);
if (nValues[2] != 0)
averages[i][2] /= static_cast<float>(nValues[2]);
// Get the minimum/maximum values for each of the components so that we
// can scale the plot by these numbers
auto minmaxEphemeris = std::minmax_element(
std::begin(entry.updateEphemeris),
std::end(entry.updateEphemeris)
@@ -135,7 +168,6 @@ void GuiPerformanceComponent::render() {
*(minmaxEphemeris.second)
);
auto minmaxUpdateRenderable = std::minmax_element(
std::begin(entry.updateRenderable),
std::end(entry.updateRenderable)
@@ -145,7 +177,6 @@ void GuiPerformanceComponent::render() {
*(minmaxUpdateRenderable.second)
);
auto minmaxRendering = std::minmax_element(
std::begin(entry.renderTime),
std::end(entry.renderTime)
@@ -157,28 +188,66 @@ void GuiPerformanceComponent::render() {
}
// If we don't want to sort, we will leave the indices list alone, thus
// leaving them in the regular ordering
Sorting selection = Sorting(_sortingSelection);
if (selection != Sorting::NoSorting) {
std::function<bool(size_t, size_t)> sortFunc;
if (_sortingSelection != -1) {
int sortIndex = _sortingSelection;
if (selection == Sorting::Total) {
// If we do want to sort totally, we need to sum all the averages and
// use that as the criterion
sortFunc = [&averages](size_t a, size_t b) {
float sumA = std::accumulate(
std::begin(averages[a]),
std::end(averages[a]),
0.f
);
float sumB = std::accumulate(
std::begin(averages[b]),
std::end(averages[b]),
0.f
);
return sumA > sumB;
};
}
else {
// otherwise we use the sorting index
int sel = _sortingSelection;
sortFunc = [sel, &averages](size_t a, size_t b) {
return averages[a][sel] > averages[b][sel];
};
}
std::sort(
indices.begin(),
indices.end(),
[sortIndex, &averages](size_t a, size_t b) {
return averages[a][sortIndex] > averages[b][sortIndex];
}
sortFunc
);
}
for (int i = 0; i < layout->nScaleGraphEntries; ++i) {
const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]];
// We are using the indices list as an additional level of indirection
// into the respective values so that the list will be sorted by whatever
// criterion we selected previously
const PerformanceLayout::SceneGraphPerformanceLayout& entry =
layout->sceneGraphEntries[indices[i]];
if (ImGui::CollapsingHeader(entry.name)) {
std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[PerformanceLayout::NumberValues - 1]) + "us";
;
std::string updateEphemerisTime = std::to_string(
entry.updateEphemeris[PerformanceLayout::NumberValues - 1]
) + "us";
ImGui::PlotLines(
fmt::format("UpdateEphemeris\nAverage: {}us", averages[indices[i]][0]).c_str(),
fmt::format(
"UpdateEphemeris\nAverage: {}us",
averages[indices[i]][0]
).c_str(),
&entry.updateEphemeris[0],
PerformanceLayout::NumberValues,
0,
@@ -188,9 +257,15 @@ void GuiPerformanceComponent::render() {
ImVec2(0, 40)
);
std::string updateRenderableTime = std::to_string(entry.updateRenderable[PerformanceLayout::NumberValues - 1]) + "us";
std::string updateRenderableTime = std::to_string(
entry.updateRenderable[PerformanceLayout::NumberValues - 1]
) + "us";
ImGui::PlotLines(
fmt::format("UpdateRender\nAverage: {}us", averages[indices[i]][1]).c_str(),
fmt::format(
"UpdateRender\nAverage: {}us",
averages[indices[i]][1]
).c_str(),
&entry.updateRenderable[0],
PerformanceLayout::NumberValues,
0,
@@ -200,9 +275,15 @@ void GuiPerformanceComponent::render() {
ImVec2(0, 40)
);
std::string renderTime = std::to_string(entry.renderTime[PerformanceLayout::NumberValues - 1]) + "us";
std::string renderTime = std::to_string(
entry.renderTime[PerformanceLayout::NumberValues - 1]
) + "us";
ImGui::PlotLines(
fmt::format("RenderTime\nAverage: {}us", averages[indices[i]][2]).c_str(),
fmt::format(
"RenderTime\nAverage: {}us",
averages[indices[i]][2]
).c_str(),
&entry.renderTime[0],
PerformanceLayout::NumberValues,
0,
@@ -220,15 +301,9 @@ void GuiPerformanceComponent::render() {
ImGui::Begin("Functions", &_functionsIsEnabled);
using namespace performance;
if (!_performanceMemory)
_performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData);
void* ptr = _performanceMemory->memory();
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
for (int i = 0; i < layout->nFunctionEntries; ++i) {
const PerformanceLayout::FunctionPerformanceLayout& entry = layout->functionEntries[i];
const PerformanceLayout::FunctionPerformanceLayout& entry =
layout->functionEntries[i];
float avg = 0.f;
int count = 0;
@@ -244,9 +319,12 @@ void GuiPerformanceComponent::render() {
std::end(layout->functionEntries[i].time)
);
const PerformanceLayout::FunctionPerformanceLayout& f = layout->functionEntries[i];
const PerformanceLayout::FunctionPerformanceLayout& f =
layout->functionEntries[i];
std::string renderTime = std::to_string(entry.time[PerformanceLayout::NumberValues - 1]) + "us";
std::string renderTime = std::to_string(
entry.time[PerformanceLayout::NumberValues - 1]
) + "us";
ImGui::PlotLines(
fmt::format("{}\nAverage: {}us", entry.name, avg).c_str(),
&entry.time[0],