diff --git a/include/openspace/util/performancemeasurement.h b/include/openspace/util/performancemeasurement.h new file mode 100644 index 0000000000..6682e71a4a --- /dev/null +++ b/include/openspace/util/performancemeasurement.h @@ -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 + +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__ diff --git a/include/openspace/util/screenlog.h b/include/openspace/util/screenlog.h index 01c9e9283e..afeaf2ecc2 100644 --- a/include/openspace/util/screenlog.h +++ b/include/openspace/util/screenlog.h @@ -22,6 +22,9 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#ifndef __SCREENLOG_H__ +#define __SCREENLOG_H__ + #include #include @@ -110,4 +113,6 @@ private: LogLevel _logLevel; }; -} // namespace openspace \ No newline at end of file +} // namespace openspace + +#endif // __SCREENLOG_H__ diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index 57bc4ab20b..c749cba218 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f6ad12718..8adbf333ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 5dc84a7710..70788f9787 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -58,6 +58,8 @@ #include #include +#include + #include #include @@ -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(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(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(); } diff --git a/src/util/performancemeasurement.cpp b/src/util/performancemeasurement.cpp new file mode 100644 index 0000000000..5210126428 --- /dev/null +++ b/src/util/performancemeasurement.cpp @@ -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 + +namespace openspace { +namespace performance { + +PerformanceLayout::PerformanceLayout(int32_t nEntries) + : nEntries(nEntries) +{ + +} + +} // namespace performance +} // namespace openspace