Refactor PerformanceLayout into new file and reuse between RenderEngine and GuiPerformanceComponent

This commit is contained in:
Alexander Bock
2016-06-06 01:54:41 +02:00
parent a0e5fe34fe
commit 2c8e3fd7b9
6 changed files with 128 additions and 70 deletions

View File

@@ -0,0 +1,62 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __PERFORMANCEMEASUREMENT_H__
#define __PERFORMANCEMEASUREMENT_H__
#include <cstdint>
namespace openspace {
namespace performance {
struct PerformanceLayout {
static const int8_t Version = 0;
static const int LengthName = 256;
static const int NumberValues = 256;
static const int MaxValues = 256;
PerformanceLayout(int32_t nEntries);
int32_t nEntries;
struct PerformanceLayoutEntry {
char name[LengthName];
float renderTime[NumberValues];
float updateRenderable[NumberValues];
float updateEphemeris[NumberValues];
int32_t currentRenderTime;
int32_t currentUpdateRenderable;
int32_t currentUpdateEphemeris;
};
PerformanceLayoutEntry entries[MaxValues];
};
} // namespace performance
} // namespace openspace
#endif // __PERFORMANCEMEASUREMENT_H__

View File

@@ -22,6 +22,9 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SCREENLOG_H__
#define __SCREENLOG_H__
#include <ghoul/logging/log.h>
#include <chrono>
@@ -110,4 +113,6 @@ private:
LogLevel _logLevel;
};
} // namespace openspace
} // namespace openspace
#endif // __SCREENLOG_H__

View File

@@ -26,6 +26,8 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/performancemeasurement.h>
#include <ghoul/misc/sharedmemory.h>
#include <imgui.h>
@@ -53,32 +55,7 @@ void GuiPerformanceComponent::deinitialize() {
}
void GuiPerformanceComponent::render() {
// Copy and paste from renderengine.cpp::storePerformanceMeasurements method
// const int8_t Version = 0;
const int nValues = 250;
const int lengthName = 256;
const int maxValues = 256;
struct PerformanceLayout {
int8_t version;
int32_t nValuesPerEntry;
int32_t nEntries;
int32_t maxNameLength;
int32_t maxEntries;
struct PerformanceLayoutEntry {
char name[lengthName];
float renderTime[nValues];
float updateRenderable[nValues];
float updateEphemeris[nValues];
int32_t currentRenderTime;
int32_t currentUpdateRenderable;
int32_t currentUpdateEphemeris;
};
PerformanceLayoutEntry entries[maxValues];
};
using namespace performance;
ImGui::Begin("Performance", &_isEnabled);
if (OsEng.renderEngine().doesPerformanceMeasurements() &&
@@ -116,7 +93,7 @@ void GuiPerformanceComponent::render() {
int v[3] = { 0, 0, 0 };
for (int j = 0; j < nValues; ++j) {
for (int j = 0; j < PerformanceLayout::NumberValues; ++j) {
averages[i][0] += entry.updateEphemeris[j];
if (entry.updateEphemeris[j] != 0.f)
++v[0];
@@ -158,7 +135,8 @@ void GuiPerformanceComponent::render() {
ImGui::PlotLines(
fmt::format("UpdateEphemeris\nAverage: {}us", averages[i][0]).c_str(),
&entry.updateEphemeris[0],
layout.nValuesPerEntry,
PerformanceLayout::NumberValues,
//layout.nValuesPerEntry,
0,
updateEphemerisTime.c_str(),
_minMaxValues[0],
@@ -170,7 +148,7 @@ void GuiPerformanceComponent::render() {
ImGui::PlotLines(
fmt::format("UpdateRender\nAverage: {}us", averages[i][1]).c_str(),
&entry.updateRenderable[0],
layout.nValuesPerEntry,
PerformanceLayout::NumberValues,
0,
updateRenderableTime.c_str(),
_minMaxValues[0],
@@ -182,7 +160,7 @@ void GuiPerformanceComponent::render() {
ImGui::PlotLines(
fmt::format("RenderTime\nAverage: {}us", averages[i][2]).c_str(),
&entry.renderTime[0],
layout.nValuesPerEntry,
PerformanceLayout::NumberValues,
0,
renderTime.c_str(),
_minMaxValues[0],
@@ -200,6 +178,5 @@ void GuiPerformanceComponent::render() {
ImGui::End();
}
} // namespace gui
} // namespace openspace

View File

@@ -81,6 +81,7 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/util/factorymanager.cpp
${OPENSPACE_BASE_DIR}/src/util/keys.cpp
${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp
${OPENSPACE_BASE_DIR}/src/util/performancemeasurement.cpp
${OPENSPACE_BASE_DIR}/src/util/powerscaledcoordinate.cpp
${OPENSPACE_BASE_DIR}/src/util/powerscaledscalar.cpp
${OPENSPACE_BASE_DIR}/src/util/powerscaledsphere.cpp
@@ -160,6 +161,7 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/util/keys.h
${OPENSPACE_BASE_DIR}/include/openspace/util/mouse.h
${OPENSPACE_BASE_DIR}/include/openspace/util/openspacemodule.h
${OPENSPACE_BASE_DIR}/include/openspace/util/performancemeasurement.h
${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledcoordinate.h
${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledscalar.h
${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledsphere.h

View File

@@ -58,6 +58,8 @@
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/rendering/screenspacerenderable.h>
#include <openspace/util/performancemeasurement.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/io/texture/texturewriter.h>
@@ -722,38 +724,15 @@ bool RenderEngine::doesPerformanceMeasurements() const {
}
void RenderEngine::storePerformanceMeasurements() {
const int8_t Version = 0;
const int nValues = 250;
const int lengthName = 256;
const int maxValues = 256;
using namespace performance;
struct PerformanceLayout {
int8_t version;
int32_t nValuesPerEntry;
int32_t nEntries;
int32_t maxNameLength;
int32_t maxEntries;
struct PerformanceLayoutEntry {
char name[lengthName];
float renderTime[nValues];
float updateRenderable[nValues];
float updateEphemeris[nValues];
int32_t currentRenderTime;
int32_t currentUpdateRenderable;
int32_t currentUpdateEphemeris;
};
PerformanceLayoutEntry entries[maxValues];
};
const int nNodes = static_cast<int>(scene()->allSceneGraphNodes().size());
if (!_performanceMemory) {
// Compute the total size
const int totalSize = sizeof(int8_t) + 4 * sizeof(int32_t) +
maxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry);
PerformanceLayout::MaxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry);
LINFO("Create shared memory of " << totalSize << " bytes");
try {
@@ -762,24 +741,20 @@ void RenderEngine::storePerformanceMeasurements() {
catch (const ghoul::SharedMemory::SharedMemoryError& e) {
LINFOC(e.component, e.what());
}
ghoul::SharedMemory::create(PerformanceMeasurementSharedData, totalSize);
_performanceMemory = new ghoul::SharedMemory(PerformanceMeasurementSharedData);
void* ptr = _performanceMemory->memory();
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
layout->version = Version;
layout->nValuesPerEntry = nValues;
layout->nEntries = nNodes;
layout->maxNameLength = lengthName;
layout->maxEntries = maxValues;
memset(layout->entries, 0, maxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry));
PerformanceLayout* layout = new (ptr) PerformanceLayout(nNodes);
memset(layout->entries, 0, PerformanceLayout::MaxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry));
for (int i = 0; i < nNodes; ++i) {
SceneGraphNode* node = scene()->allSceneGraphNodes()[i];
memset(layout->entries[i].name, 0, lengthName);
memset(layout->entries[i].name, 0, PerformanceLayout::LengthName);
#ifdef _MSC_VER
strcpy_s(layout->entries[i].name, node->name().length() + 1, node->name().c_str());
#else
@@ -804,9 +779,9 @@ void RenderEngine::storePerformanceMeasurements() {
entry.updateEphemeris[entry.currentUpdateEphemeris] = r.updateTimeEphemeris / 1000.f;
entry.updateRenderable[entry.currentUpdateRenderable] = r.updateTimeRenderable / 1000.f;
entry.currentRenderTime = (entry.currentRenderTime + 1) % nValues;
entry.currentUpdateEphemeris = (entry.currentUpdateEphemeris + 1) % nValues;
entry.currentUpdateRenderable = (entry.currentUpdateRenderable + 1) % nValues;
entry.currentRenderTime = (entry.currentRenderTime + 1) % PerformanceLayout::NumberValues;
entry.currentUpdateEphemeris = (entry.currentUpdateEphemeris + 1) % PerformanceLayout::NumberValues;
entry.currentUpdateRenderable = (entry.currentUpdateRenderable + 1) % PerformanceLayout::NumberValues;
}
_performanceMemory->releaseLock();
}

View File

@@ -0,0 +1,37 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/performancemeasurement.h>
namespace openspace {
namespace performance {
PerformanceLayout::PerformanceLayout(int32_t nEntries)
: nEntries(nEntries)
{
}
} // namespace performance
} // namespace openspace