From 2c8e3fd7b9ef8861c2478ddfb93c3740c11f5c83 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 01:54:41 +0200 Subject: [PATCH 01/14] Refactor PerformanceLayout into new file and reuse between RenderEngine and GuiPerformanceComponent --- .../openspace/util/performancemeasurement.h | 62 +++++++++++++++++++ include/openspace/util/screenlog.h | 7 ++- .../src/guiperformancecomponent.cpp | 39 +++--------- src/CMakeLists.txt | 2 + src/rendering/renderengine.cpp | 51 ++++----------- src/util/performancemeasurement.cpp | 37 +++++++++++ 6 files changed, 128 insertions(+), 70 deletions(-) create mode 100644 include/openspace/util/performancemeasurement.h create mode 100644 src/util/performancemeasurement.cpp 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 From f8f89e6fd1fbf7735c0de00e9c98c23d1c73182d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 02:12:46 +0200 Subject: [PATCH 02/14] Moving more code into performance files --- include/openspace/rendering/renderengine.h | 3 +++ .../openspace/util/performancemeasurement.h | 19 +++++++++++++++---- src/rendering/renderengine.cpp | 11 +++-------- src/util/performancemeasurement.cpp | 12 ++++++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 913ccd9c82..d56e5c09a1 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -97,9 +97,12 @@ public: void takeScreenshot(); void toggleInfoText(bool b); + // Performance measurements void setPerformanceMeasurements(bool performanceMeasurements); bool doesPerformanceMeasurements() const; + + void serialize(SyncBuffer* syncBuffer); void deserialize(SyncBuffer* syncBuffer); diff --git a/include/openspace/util/performancemeasurement.h b/include/openspace/util/performancemeasurement.h index 6682e71a4a..83cc649a72 100644 --- a/include/openspace/util/performancemeasurement.h +++ b/include/openspace/util/performancemeasurement.h @@ -30,8 +30,6 @@ namespace openspace { namespace performance { - - struct PerformanceLayout { static const int8_t Version = 0; static const int LengthName = 256; @@ -42,7 +40,7 @@ struct PerformanceLayout { int32_t nEntries; - struct PerformanceLayoutEntry { + struct SceneGraphPerformanceLayout { char name[LengthName]; float renderTime[NumberValues]; float updateRenderable[NumberValues]; @@ -52,8 +50,21 @@ struct PerformanceLayout { int32_t currentUpdateRenderable; int32_t currentUpdateEphemeris; }; + SceneGraphPerformanceLayout sceneGraphEntries[MaxValues]; + + struct FunctionPerformanceLayout { + char name[LengthName]; + float time[NumberValues]; + int32_t currentTime; + }; + FunctionPerformanceLayout functionEntries[MaxValues]; +}; + +struct FunctionPerformanceHelper { + FunctionPerformanceHelper(); + ~FunctionPerformanceHelper(); + - PerformanceLayoutEntry entries[MaxValues]; }; } // namespace performance diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 70788f9787..11e914f142 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -726,13 +726,10 @@ bool RenderEngine::doesPerformanceMeasurements() const { void RenderEngine::storePerformanceMeasurements() { using namespace performance; - - const int nNodes = static_cast(scene()->allSceneGraphNodes().size()); + int nNodes = static_cast(scene()->allSceneGraphNodes().size()); if (!_performanceMemory) { - // Compute the total size - const int totalSize = sizeof(int8_t) + 4 * sizeof(int32_t) + - PerformanceLayout::MaxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry); + const int totalSize = sizeof(PerformanceLayout); LINFO("Create shared memory of " << totalSize << " bytes"); try { @@ -746,11 +743,9 @@ void RenderEngine::storePerformanceMeasurements() { _performanceMemory = new ghoul::SharedMemory(PerformanceMeasurementSharedData); void* ptr = _performanceMemory->memory(); + // Using the placement-new to create a PerformanceLayout in the shared memory 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]; diff --git a/src/util/performancemeasurement.cpp b/src/util/performancemeasurement.cpp index 5210126428..6239714b42 100644 --- a/src/util/performancemeasurement.cpp +++ b/src/util/performancemeasurement.cpp @@ -24,13 +24,25 @@ #include +#include + namespace openspace { namespace performance { PerformanceLayout::PerformanceLayout(int32_t nEntries) : nEntries(nEntries) { + std::memset( + sceneGraphEntries, + 0, + MaxValues * sizeof(SceneGraphPerformanceLayout) + ); + std::memset( + functionEntries, + 0, + MaxValues * sizeof(FunctionPerformanceLayout) + ); } } // namespace performance From 55d484205a9bec72abf57f42ab56a73419315a4b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 02:14:42 +0200 Subject: [PATCH 03/14] Rename performance file --- .../performancelayout.h} | 0 src/CMakeLists.txt | 4 ++-- .../performancelayout.cpp} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename include/openspace/{util/performancemeasurement.h => performance/performancelayout.h} (100%) rename src/{util/performancemeasurement.cpp => performance/performancelayout.cpp} (100%) diff --git a/include/openspace/util/performancemeasurement.h b/include/openspace/performance/performancelayout.h similarity index 100% rename from include/openspace/util/performancemeasurement.h rename to include/openspace/performance/performancelayout.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8adbf333ce..7ec574b652 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/network/networkengine.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection_lua.inl + ${OPENSPACE_BASE_DIR}/src/performance/performancelayout.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrixproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/optionproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/property.cpp @@ -81,7 +82,6 @@ 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 @@ -120,6 +120,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/network/networkengine.h ${OPENSPACE_BASE_DIR}/include/openspace/network/parallelconnection.h ${OPENSPACE_BASE_DIR}/include/openspace/network/messagestructures.h + ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancelayout.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrixproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.inl @@ -161,7 +162,6 @@ 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/util/performancemeasurement.cpp b/src/performance/performancelayout.cpp similarity index 100% rename from src/util/performancemeasurement.cpp rename to src/performance/performancelayout.cpp From 53c35c7531d8d964135e37d2da851b5ef2611e76 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 03:19:44 +0200 Subject: [PATCH 04/14] Moving performance-related collection code from RenderEngine into new PerformanceManager code --- .../openspace/performance/performancelayout.h | 13 +- .../performance/performancemanager.h | 58 +++++++++ include/openspace/rendering/renderengine.h | 13 +- .../src/guiperformancecomponent.cpp | 23 ++-- src/CMakeLists.txt | 2 + src/performance/performancelayout.cpp | 2 +- src/performance/performancemanager.cpp | 118 ++++++++++++++++++ src/rendering/renderengine.cpp | 89 +++---------- 8 files changed, 211 insertions(+), 107 deletions(-) create mode 100644 include/openspace/performance/performancemanager.h create mode 100644 src/performance/performancemanager.cpp diff --git a/include/openspace/performance/performancelayout.h b/include/openspace/performance/performancelayout.h index 83cc649a72..06104144db 100644 --- a/include/openspace/performance/performancelayout.h +++ b/include/openspace/performance/performancelayout.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __PERFORMANCEMEASUREMENT_H__ -#define __PERFORMANCEMEASUREMENT_H__ +#ifndef __PERFORMANCELAYOUT_H__ +#define __PERFORMANCELAYOUT_H__ #include @@ -60,14 +60,7 @@ struct PerformanceLayout { FunctionPerformanceLayout functionEntries[MaxValues]; }; -struct FunctionPerformanceHelper { - FunctionPerformanceHelper(); - ~FunctionPerformanceHelper(); - - -}; - } // namespace performance } // namespace openspace -#endif // __PERFORMANCEMEASUREMENT_H__ +#endif // __PERFORMANCELAYOUT_H__ diff --git a/include/openspace/performance/performancemanager.h b/include/openspace/performance/performancemanager.h new file mode 100644 index 0000000000..cce46761c6 --- /dev/null +++ b/include/openspace/performance/performancemanager.h @@ -0,0 +1,58 @@ +/***************************************************************************************** + * * + * 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 __PERFORMANCEMANAGER_H__ +#define __PERFORMANCEMANAGER_H__ + +#include + +namespace ghoul { + class SharedMemory; +} + +namespace openspace { + +class SceneGraphNode; + +namespace performance { + +class PerformanceManager { +public: + static const std::string PerformanceMeasurementSharedData; + + PerformanceManager(); + ~PerformanceManager(); + + bool isMeasuringPerformance() const; + void storeScenePerformanceMeasurements(const std::vector& sceneNodes); + +private: + bool _doPerformanceMeasurements; + ghoul::SharedMemory* _performanceMemory; +}; + +} // namespace performance +} // namespace openspace + +#endif // __PERFORMANCEMANAGER_H__ diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index d56e5c09a1..5ff6bfadd6 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -31,6 +31,7 @@ #include #include +#include namespace ghoul { namespace fontrendering { @@ -67,9 +68,6 @@ public: Post }; - - static const std::string PerformanceMeasurementSharedData; - static const std::string KeyFontMono; static const std::string KeyFontLight; @@ -101,8 +99,6 @@ public: void setPerformanceMeasurements(bool performanceMeasurements); bool doesPerformanceMeasurements() const; - - void serialize(SyncBuffer* syncBuffer); void deserialize(SyncBuffer* syncBuffer); @@ -181,7 +177,7 @@ public: private: void setRenderer(std::unique_ptr renderer); RendererImplementation rendererFromString(const std::string& method); - void storePerformanceMeasurements(); + void renderInformation(); void renderScreenLog(); @@ -189,6 +185,8 @@ private: Scene* _sceneGraph; RaycasterManager* _raycasterManager; + std::unique_ptr _performanceManager; + std::unique_ptr _renderer; RendererImplementation _rendererImplementation; ghoul::Dictionary _rendererData; @@ -199,9 +197,6 @@ private: bool _showLog; bool _takeScreenshot; - bool _doPerformanceMeasurements; - ghoul::SharedMemory* _performanceMemory; - float _globalBlackOutFactor; float _fadeDuration; float _currentFadeTime; diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index c749cba218..d1be505f64 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -25,8 +25,9 @@ #include #include +#include +#include #include -#include #include @@ -59,7 +60,7 @@ void GuiPerformanceComponent::render() { ImGui::Begin("Performance", &_isEnabled); if (OsEng.renderEngine().doesPerformanceMeasurements() && - ghoul::SharedMemory::exists(RenderEngine::PerformanceMeasurementSharedData)) + ghoul::SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData)) { ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 10000.f); _minMaxValues[1] = fmaxf(_minMaxValues[0], _minMaxValues[1]); @@ -72,24 +73,23 @@ void GuiPerformanceComponent::render() { ImGui::RadioButton("RenderTime", &_sortingSelection, 2); if (!_performanceMemory) - _performanceMemory = new ghoul::SharedMemory(RenderEngine::PerformanceMeasurementSharedData); - + _performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData); void* ptr = _performanceMemory->memory(); - PerformanceLayout layout = *reinterpret_cast(ptr); + PerformanceLayout* layout = reinterpret_cast(ptr); - std::vector indices(layout.nEntries); + std::vector indices(layout->nEntries); std::iota(indices.begin(), indices.end(), 0); // Ordering: // updateEphemeris // UpdateRender // RenderTime - std::vector> averages(layout.nEntries, { 0.f, 0.f, 0.f }); + std::vector> averages(layout->nEntries, { 0.f, 0.f, 0.f }); - for (int i = 0; i < layout.nEntries; ++i) { - const PerformanceLayout::PerformanceLayoutEntry& entry = layout.entries[i]; + for (int i = 0; i < layout->nEntries; ++i) { + const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; int v[3] = { 0, 0, 0 }; @@ -126,8 +126,8 @@ void GuiPerformanceComponent::render() { } - for (int i = 0; i < layout.nEntries; ++i) { - const PerformanceLayout::PerformanceLayoutEntry& entry = layout.entries[indices[i]]; + for (int i = 0; i < layout->nEntries; ++i) { + const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]]; if (ImGui::CollapsingHeader(entry.name)) { std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us"; @@ -136,7 +136,6 @@ void GuiPerformanceComponent::render() { fmt::format("UpdateEphemeris\nAverage: {}us", averages[i][0]).c_str(), &entry.updateEphemeris[0], PerformanceLayout::NumberValues, - //layout.nValuesPerEntry, 0, updateEphemerisTime.c_str(), _minMaxValues[0], diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7ec574b652..b0169dc3c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/network/parallelconnection.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection_lua.inl ${OPENSPACE_BASE_DIR}/src/performance/performancelayout.cpp + ${OPENSPACE_BASE_DIR}/src/performance/performancemanager.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrixproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/optionproperty.cpp ${OPENSPACE_BASE_DIR}/src/properties/property.cpp @@ -121,6 +122,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/network/parallelconnection.h ${OPENSPACE_BASE_DIR}/include/openspace/network/messagestructures.h ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancelayout.h + ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancemanager.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrixproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.inl diff --git a/src/performance/performancelayout.cpp b/src/performance/performancelayout.cpp index 6239714b42..803a577443 100644 --- a/src/performance/performancelayout.cpp +++ b/src/performance/performancelayout.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include diff --git a/src/performance/performancemanager.cpp b/src/performance/performancemanager.cpp new file mode 100644 index 0000000000..46f89ebec8 --- /dev/null +++ b/src/performance/performancemanager.cpp @@ -0,0 +1,118 @@ +/***************************************************************************************** + * * + * 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 + +#include +#include + +#include +#include + +namespace { + const std::string _loggerCat = "PerformanceManager"; +} + +namespace openspace { +namespace performance { + +const std::string PerformanceManager::PerformanceMeasurementSharedData = + "OpenSpacePerformanceMeasurementSharedData"; + +PerformanceManager::PerformanceManager() + : _performanceMemory(nullptr) +{ +} + +PerformanceManager::~PerformanceManager() { + if (ghoul::SharedMemory::exists(PerformanceMeasurementSharedData)) + ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); +} + +bool PerformanceManager::isMeasuringPerformance() const { + return _doPerformanceMeasurements; +} + +void PerformanceManager::storeScenePerformanceMeasurements( + const std::vector& sceneNodes) +{ + using namespace performance; + + int nNodes = static_cast(sceneNodes.size()); + if (!_performanceMemory) { + // Compute the total size + const int totalSize = sizeof(PerformanceLayout); + LINFO("Create shared memory of " << totalSize << " bytes"); + + try { + ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); + } + 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(); + + // Using the placement-new to create a PerformanceLayout in the shared memory + PerformanceLayout* layout = new (ptr) PerformanceLayout(nNodes); + + for (int i = 0; i < nNodes; ++i) { + SceneGraphNode* node = sceneNodes[i]; + + memset(layout->sceneGraphEntries[i].name, 0, PerformanceLayout::LengthName); +#ifdef _MSC_VER + strcpy_s(layout->sceneGraphEntries[i].name, node->name().length() + 1, node->name().c_str()); +#else + strcpy(layout->entries[i].name, node->name().c_str()); +#endif + + layout->sceneGraphEntries[i].currentRenderTime = 0; + layout->sceneGraphEntries[i].currentUpdateRenderable = 0; + layout->sceneGraphEntries[i].currentUpdateEphemeris = 0; + } + } + + void* ptr = _performanceMemory->memory(); + PerformanceLayout* layout = reinterpret_cast(ptr); + _performanceMemory->acquireLock(); + for (int i = 0; i < nNodes; ++i) { + SceneGraphNode* node = sceneNodes[i]; + SceneGraphNode::PerformanceRecord r = node->performanceRecord(); + PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; + + entry.renderTime[entry.currentRenderTime] = r.renderTime / 1000.f; + entry.updateEphemeris[entry.currentUpdateEphemeris] = r.updateTimeEphemeris / 1000.f; + entry.updateRenderable[entry.currentUpdateRenderable] = r.updateTimeRenderable / 1000.f; + + entry.currentRenderTime = (entry.currentRenderTime + 1) % PerformanceLayout::NumberValues; + entry.currentUpdateEphemeris = (entry.currentUpdateEphemeris + 1) % PerformanceLayout::NumberValues; + entry.currentUpdateRenderable = (entry.currentUpdateRenderable + 1) % PerformanceLayout::NumberValues; + } + _performanceMemory->releaseLock(); +} + +} // namespace performance +} // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 11e914f142..fad8d2131e 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -36,6 +36,8 @@ #include #include +#include + #include #include #include @@ -58,9 +60,6 @@ #include #include -#include - - #include #include #ifdef GHOUL_USE_DEVIL @@ -104,9 +103,6 @@ namespace { namespace openspace { -const std::string RenderEngine::PerformanceMeasurementSharedData = - "OpenSpacePerformanceMeasurementSharedData"; - const std::string RenderEngine::KeyFontMono = "Mono"; const std::string RenderEngine::KeyFontLight = "Light"; @@ -115,12 +111,11 @@ RenderEngine::RenderEngine() , _sceneGraph(nullptr) , _renderer(nullptr) , _rendererImplementation(RendererImplementation::Invalid) + , _performanceManager(nullptr) , _log(nullptr) , _showInfo(true) , _showLog(true) , _takeScreenshot(false) - , _doPerformanceMeasurements(false) - , _performanceMemory(nullptr) , _globalBlackOutFactor(1.f) , _fadeDuration(2.f) , _currentFadeTime(0.f) @@ -139,11 +134,8 @@ RenderEngine::~RenderEngine() { _sceneGraph = nullptr; delete _mainCamera; - delete _performanceMemory; delete _raycasterManager; - if (ghoul::SharedMemory::exists(PerformanceMeasurementSharedData)) - ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); } bool RenderEngine::deinitialize() { @@ -367,7 +359,7 @@ void RenderEngine::postSynchronizationPreDraw() { Time::ref().currentTime(), Time::ref().timeJumped(), Time::ref().deltaTime(), - _doPerformanceMeasurements + _performanceManager != nullptr }); _sceneGraph->evaluate(_mainCamera); @@ -401,7 +393,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi if (!(OsEng.isMaster() && _disableMasterRendering)) { - _renderer->render(_globalBlackOutFactor, _doPerformanceMeasurements); + _renderer->render(_globalBlackOutFactor, _performanceManager != nullptr); } // Print some useful information on the master viewport @@ -428,8 +420,8 @@ void RenderEngine::postDraw() { _takeScreenshot = false; } - if (_doPerformanceMeasurements) - storePerformanceMeasurements(); + if (_performanceManager) + _performanceManager->storeScenePerformanceMeasurements(scene()->allSceneGraphNodes()); } void RenderEngine::takeScreenshot() { @@ -716,69 +708,16 @@ scripting::ScriptEngine::LuaLibrary RenderEngine::luaLibrary() { } void RenderEngine::setPerformanceMeasurements(bool performanceMeasurements) { - _doPerformanceMeasurements = performanceMeasurements; + if (performanceMeasurements) { + if (!_performanceManager) + _performanceManager = std::make_unique(); + } + else + _performanceManager = nullptr; } bool RenderEngine::doesPerformanceMeasurements() const { - return _doPerformanceMeasurements; -} - -void RenderEngine::storePerformanceMeasurements() { - using namespace performance; - - int nNodes = static_cast(scene()->allSceneGraphNodes().size()); - if (!_performanceMemory) { - // Compute the total size - const int totalSize = sizeof(PerformanceLayout); - LINFO("Create shared memory of " << totalSize << " bytes"); - - try { - ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); - } - 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(); - - // Using the placement-new to create a PerformanceLayout in the shared memory - PerformanceLayout* layout = new (ptr) PerformanceLayout(nNodes); - - for (int i = 0; i < nNodes; ++i) { - SceneGraphNode* node = scene()->allSceneGraphNodes()[i]; - - 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 - strcpy(layout->entries[i].name, node->name().c_str()); -#endif - - layout->entries[i].currentRenderTime = 0; - layout->entries[i].currentUpdateRenderable = 0; - layout->entries[i].currentUpdateEphemeris = 0; - } - } - - void* ptr = _performanceMemory->memory(); - PerformanceLayout* layout = reinterpret_cast(ptr); - _performanceMemory->acquireLock(); - for (int i = 0; i < nNodes; ++i) { - SceneGraphNode* node = scene()->allSceneGraphNodes()[i]; - SceneGraphNode::PerformanceRecord r = node->performanceRecord(); - PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i]; - - entry.renderTime[entry.currentRenderTime] = r.renderTime / 1000.f; - entry.updateEphemeris[entry.currentUpdateEphemeris] = r.updateTimeEphemeris / 1000.f; - entry.updateRenderable[entry.currentUpdateRenderable] = r.updateTimeRenderable / 1000.f; - - entry.currentRenderTime = (entry.currentRenderTime + 1) % PerformanceLayout::NumberValues; - entry.currentUpdateEphemeris = (entry.currentUpdateEphemeris + 1) % PerformanceLayout::NumberValues; - entry.currentUpdateRenderable = (entry.currentUpdateRenderable + 1) % PerformanceLayout::NumberValues; - } - _performanceMemory->releaseLock(); + return _performanceManager != nullptr; } // This method is temporary and will be removed once the scalegraph is in effect ---abock From 14ee3af94d4a68c810ac2c705bbd47fd3bd4942e Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 03:30:10 +0200 Subject: [PATCH 05/14] Make PerformanceManager available Add empty PerformanceHelper file --- .../openspace/performance/performancehelper.h | 32 +++++++++++++++++++ include/openspace/rendering/renderengine.h | 1 + src/CMakeLists.txt | 2 ++ src/performance/performancehelper.cpp | 32 +++++++++++++++++++ src/rendering/renderengine.cpp | 4 +++ 5 files changed, 71 insertions(+) create mode 100644 include/openspace/performance/performancehelper.h create mode 100644 src/performance/performancehelper.cpp diff --git a/include/openspace/performance/performancehelper.h b/include/openspace/performance/performancehelper.h new file mode 100644 index 0000000000..a97f35b049 --- /dev/null +++ b/include/openspace/performance/performancehelper.h @@ -0,0 +1,32 @@ +/***************************************************************************************** + * * + * 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 __PERFORMANCEHELPER_H__ +#define __PERFORMANCEHELPER_H__ + + +} // namespace performance +} // namespace openspace + +#endif // __PERFORMANCEHELPER_H__ diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 5ff6bfadd6..14c666eda7 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -98,6 +98,7 @@ public: // Performance measurements void setPerformanceMeasurements(bool performanceMeasurements); bool doesPerformanceMeasurements() const; + performance::PerformanceManager* performanceManager(); void serialize(SyncBuffer* syncBuffer); void deserialize(SyncBuffer* syncBuffer); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0169dc3c7..a9d1bf1732 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/network/networkengine.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection_lua.inl + ${OPENSPACE_BASE_DIR}/src/performance/performancehelper.cpp ${OPENSPACE_BASE_DIR}/src/performance/performancelayout.cpp ${OPENSPACE_BASE_DIR}/src/performance/performancemanager.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrixproperty.cpp @@ -121,6 +122,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/network/networkengine.h ${OPENSPACE_BASE_DIR}/include/openspace/network/parallelconnection.h ${OPENSPACE_BASE_DIR}/include/openspace/network/messagestructures.h + ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancehelper.h ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancelayout.h ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancemanager.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrixproperty.h diff --git a/src/performance/performancehelper.cpp b/src/performance/performancehelper.cpp new file mode 100644 index 0000000000..dad5936285 --- /dev/null +++ b/src/performance/performancehelper.cpp @@ -0,0 +1,32 @@ +/***************************************************************************************** + * * + * 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 { + + +} // namespace performance +} // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index fad8d2131e..6fe69e311e 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -720,6 +720,10 @@ bool RenderEngine::doesPerformanceMeasurements() const { return _performanceManager != nullptr; } +performance::PerformanceManager* RenderEngine::performanceManager() { + return _performanceManager.get(); +} + // This method is temporary and will be removed once the scalegraph is in effect ---abock void RenderEngine::changeViewPoint(std::string origin) { SceneGraphNode* solarSystemBarycenterNode = scene()->sceneGraphNode("SolarSystemBarycenter"); From 1430f6b9c2db97f4b1bc09eb01205bb9478642a3 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 03:34:56 +0200 Subject: [PATCH 06/14] Clang compile fix --- include/openspace/performance/performancehelper.h | 2 ++ src/performance/performancemanager.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/openspace/performance/performancehelper.h b/include/openspace/performance/performancehelper.h index a97f35b049..f7c9429fe2 100644 --- a/include/openspace/performance/performancehelper.h +++ b/include/openspace/performance/performancehelper.h @@ -25,6 +25,8 @@ #ifndef __PERFORMANCEHELPER_H__ #define __PERFORMANCEHELPER_H__ +namespace openspace { +namespace performance { } // namespace performance } // namespace openspace diff --git a/src/performance/performancemanager.cpp b/src/performance/performancemanager.cpp index 46f89ebec8..0caf8d2f0a 100644 --- a/src/performance/performancemanager.cpp +++ b/src/performance/performancemanager.cpp @@ -86,7 +86,7 @@ void PerformanceManager::storeScenePerformanceMeasurements( #ifdef _MSC_VER strcpy_s(layout->sceneGraphEntries[i].name, node->name().length() + 1, node->name().c_str()); #else - strcpy(layout->entries[i].name, node->name().c_str()); + strcpy(layout->sceneGraphEntries[i].name, node->name().c_str()); #endif layout->sceneGraphEntries[i].currentRenderTime = 0; From ff0b916b90f6513d64f364e2a30cbd93cf05b9f2 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 03:53:42 +0200 Subject: [PATCH 07/14] Started implementing PerformanceHelper class --- .../openspace/performance/performancehelper.h | 17 ++++++++++++++ .../performance/performancemanager.h | 3 +++ src/performance/performancehelper.cpp | 22 +++++++++++++++++++ src/performance/performancemanager.cpp | 4 ++++ 4 files changed, 46 insertions(+) diff --git a/include/openspace/performance/performancehelper.h b/include/openspace/performance/performancehelper.h index f7c9429fe2..758be2d19a 100644 --- a/include/openspace/performance/performancehelper.h +++ b/include/openspace/performance/performancehelper.h @@ -25,9 +25,26 @@ #ifndef __PERFORMANCEHELPER_H__ #define __PERFORMANCEHELPER_H__ +#include +#include + namespace openspace { namespace performance { +class PerformanceManager; + +class PerformanceHelper { +public: + PerformanceHelper(std::string identifier, performance::PerformanceManager* manager); + ~PerformanceHelper(); + +private: + std::string _identifier; + performance::PerformanceManager* _manager; + + std::chrono::high_resolution_clock::time_point _startTime; +}; + } // namespace performance } // namespace openspace diff --git a/include/openspace/performance/performancemanager.h b/include/openspace/performance/performancemanager.h index cce46761c6..d8e17aa4c6 100644 --- a/include/openspace/performance/performancemanager.h +++ b/include/openspace/performance/performancemanager.h @@ -25,6 +25,7 @@ #ifndef __PERFORMANCEMANAGER_H__ #define __PERFORMANCEMANAGER_H__ +#include #include namespace ghoul { @@ -45,6 +46,8 @@ public: ~PerformanceManager(); bool isMeasuringPerformance() const; + + void storeIndividualPerformanceMeasurement(std::string identifier, long long us); void storeScenePerformanceMeasurements(const std::vector& sceneNodes); private: diff --git a/src/performance/performancehelper.cpp b/src/performance/performancehelper.cpp index dad5936285..2858b3a91c 100644 --- a/src/performance/performancehelper.cpp +++ b/src/performance/performancehelper.cpp @@ -24,9 +24,31 @@ #include +#include + +#include + namespace openspace { namespace performance { +PerformanceHelper::PerformanceHelper(std::string identifier, + performance::PerformanceManager* manager) + : _identifier(std::move(identifier)) + , _manager(manager) +{ + glFinish(); + + _startTime = std::chrono::high_resolution_clock::now(); +} + +PerformanceHelper::~PerformanceHelper() { + auto endTime = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast( + endTime - _startTime).count(); + + _manager->storeIndividualPerformanceMeasurement(std::move(_identifier), duration); +} + } // namespace performance } // namespace openspace diff --git a/src/performance/performancemanager.cpp b/src/performance/performancemanager.cpp index 0caf8d2f0a..bb27fdc626 100644 --- a/src/performance/performancemanager.cpp +++ b/src/performance/performancemanager.cpp @@ -54,6 +54,10 @@ bool PerformanceManager::isMeasuringPerformance() const { return _doPerformanceMeasurements; } +void PerformanceManager::storeIndividualPerformanceMeasurement(std::string identifier, long long us) { + +} + void PerformanceManager::storeScenePerformanceMeasurements( const std::vector& sceneNodes) { From 55bd1341e64a5b5b7ef4c111581f31422f9ea970 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 07:00:36 +0200 Subject: [PATCH 08/14] More work on PerformanceHelper Getting first version to run and produce output --- .../openspace/performance/performancelayout.h | 6 +- .../performance/performancemanager.h | 8 +- .../src/guiperformancecomponent.cpp | 197 +++++++++++------- src/performance/performancehelper.cpp | 10 +- src/performance/performancelayout.cpp | 5 +- src/performance/performancemanager.cpp | 101 +++++---- 6 files changed, 203 insertions(+), 124 deletions(-) diff --git a/include/openspace/performance/performancelayout.h b/include/openspace/performance/performancelayout.h index 06104144db..2348d765b8 100644 --- a/include/openspace/performance/performancelayout.h +++ b/include/openspace/performance/performancelayout.h @@ -36,9 +36,7 @@ struct PerformanceLayout { static const int NumberValues = 256; static const int MaxValues = 256; - PerformanceLayout(int32_t nEntries); - - int32_t nEntries; + PerformanceLayout(); struct SceneGraphPerformanceLayout { char name[LengthName]; @@ -51,6 +49,7 @@ struct PerformanceLayout { int32_t currentUpdateEphemeris; }; SceneGraphPerformanceLayout sceneGraphEntries[MaxValues]; + int16_t nScaleGraphEntries; struct FunctionPerformanceLayout { char name[LengthName]; @@ -58,6 +57,7 @@ struct PerformanceLayout { int32_t currentTime; }; FunctionPerformanceLayout functionEntries[MaxValues]; + int16_t nFunctionEntries; }; } // namespace performance diff --git a/include/openspace/performance/performancemanager.h b/include/openspace/performance/performancemanager.h index d8e17aa4c6..c99538358b 100644 --- a/include/openspace/performance/performancemanager.h +++ b/include/openspace/performance/performancemanager.h @@ -26,6 +26,7 @@ #define __PERFORMANCEMANAGER_H__ #include +#include #include namespace ghoul { @@ -45,13 +46,18 @@ public: PerformanceManager(); ~PerformanceManager(); + void resetPerformanceMeasurements(); + bool isMeasuringPerformance() const; - void storeIndividualPerformanceMeasurement(std::string identifier, long long us); + void storeIndividualPerformanceMeasurement(std::string identifier, long long nanoseconds); void storeScenePerformanceMeasurements(const std::vector& sceneNodes); private: bool _doPerformanceMeasurements; + + std::map individualPerformanceLocations; + ghoul::SharedMemory* _performanceMemory; }; diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index d1be505f64..8193ec9657 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -65,100 +65,140 @@ 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 (ImGui::CollapsingHeader("SceneGraph")) { + // 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); + if (!_performanceMemory) + _performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData); - void* ptr = _performanceMemory->memory(); + void* ptr = _performanceMemory->memory(); - PerformanceLayout* layout = reinterpret_cast(ptr); + PerformanceLayout* layout = reinterpret_cast(ptr); - std::vector indices(layout->nEntries); - std::iota(indices.begin(), indices.end(), 0); + std::vector indices(layout->nScaleGraphEntries); + std::iota(indices.begin(), indices.end(), 0); - // Ordering: - // updateEphemeris - // UpdateRender - // RenderTime - std::vector> averages(layout->nEntries, { 0.f, 0.f, 0.f }); + // Ordering: + // updateEphemeris + // UpdateRender + // RenderTime + std::vector> averages(layout->nScaleGraphEntries, { 0.f, 0.f, 0.f }); - for (int i = 0; i < layout->nEntries; ++i) { - const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; + for (int i = 0; i < layout->nScaleGraphEntries; ++i) { + const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; - int v[3] = { 0, 0, 0 }; + int v[3] = { 0, 0, 0 }; - for (int j = 0; j < PerformanceLayout::NumberValues; ++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]; + for (int j = 0; j < PerformanceLayout::NumberValues; ++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(v[0]); + if (v[1] != 0) + averages[i][1] /= static_cast(v[1]); + if (v[2] != 0) + averages[i][2] /= static_cast(v[2]); } - if (v[0] != 0) - averages[i][0] /= static_cast(v[0]); - if (v[1] != 0) - averages[i][1] /= static_cast(v[1]); - if (v[2] != 0) - averages[i][2] /= static_cast(v[2]); - } + if (_sortingSelection != -1) { + int sortIndex = _sortingSelection; - if (_sortingSelection != -1) { - int sortIndex = _sortingSelection; + std::sort( + indices.begin(), + indices.end(), + [sortIndex, &averages](size_t a, size_t b) { + return averages[a][sortIndex] > averages[b][sortIndex]; + } + ); - std::sort( - indices.begin(), - indices.end(), - [sortIndex, &averages](size_t a, size_t b) { - return averages[a][sortIndex] > averages[b][sortIndex]; + } + + for (int i = 0; i < layout->nScaleGraphEntries; ++i) { + const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]]; + + if (ImGui::CollapsingHeader(entry.name)) { + std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us"; + ; + ImGui::PlotLines( + fmt::format("UpdateEphemeris\nAverage: {}us", averages[i][0]).c_str(), + &entry.updateEphemeris[0], + PerformanceLayout::NumberValues, + 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( + fmt::format("UpdateRender\nAverage: {}us", averages[i][1]).c_str(), + &entry.updateRenderable[0], + PerformanceLayout::NumberValues, + 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( + fmt::format("RenderTime\nAverage: {}us", averages[i][2]).c_str(), + &entry.renderTime[0], + PerformanceLayout::NumberValues, + 0, + renderTime.c_str(), + _minMaxValues[0], + _minMaxValues[1], + ImVec2(0, 40) + ); } - ); - + } } + + if (ImGui::CollapsingHeader("Functions")) { + using namespace performance; + + if (!_performanceMemory) + _performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData); + + void* ptr = _performanceMemory->memory(); + + PerformanceLayout* layout = reinterpret_cast(ptr); - for (int i = 0; i < layout->nEntries; ++i) { - const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]]; - - if (ImGui::CollapsingHeader(entry.name)) { - std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us"; - ; + for (int i = 0; i < layout->nFunctionEntries; ++i) { + const PerformanceLayout::FunctionPerformanceLayout& entry = layout->functionEntries[i]; + + float avg = 0.f; + int count = 0; + for (int j = 0; j < PerformanceLayout::NumberValues; ++j) { + avg += layout->functionEntries[i].time[j]; + if (layout->functionEntries[i].time[j] != 0.f) + ++count; + } + avg /= count; + + const PerformanceLayout::FunctionPerformanceLayout& f = layout->functionEntries[i]; + + std::string renderTime = std::to_string(entry.time[entry.currentTime - 1]) + "us"; ImGui::PlotLines( - fmt::format("UpdateEphemeris\nAverage: {}us", averages[i][0]).c_str(), - &entry.updateEphemeris[0], - PerformanceLayout::NumberValues, - 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( - fmt::format("UpdateRender\nAverage: {}us", averages[i][1]).c_str(), - &entry.updateRenderable[0], - PerformanceLayout::NumberValues, - 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( - fmt::format("RenderTime\nAverage: {}us", averages[i][2]).c_str(), - &entry.renderTime[0], + fmt::format("{}\nAverage: {}us", entry.name, avg).c_str(), + &entry.time[0], PerformanceLayout::NumberValues, 0, renderTime.c_str(), @@ -167,6 +207,7 @@ void GuiPerformanceComponent::render() { ImVec2(0, 40) ); } + } } else { diff --git a/src/performance/performancehelper.cpp b/src/performance/performancehelper.cpp index 2858b3a91c..5bf6593912 100644 --- a/src/performance/performancehelper.cpp +++ b/src/performance/performancehelper.cpp @@ -36,9 +36,11 @@ PerformanceHelper::PerformanceHelper(std::string identifier, : _identifier(std::move(identifier)) , _manager(manager) { - glFinish(); + if (_manager) { + glFinish(); - _startTime = std::chrono::high_resolution_clock::now(); + _startTime = std::chrono::high_resolution_clock::now(); + } } PerformanceHelper::~PerformanceHelper() { @@ -46,7 +48,9 @@ PerformanceHelper::~PerformanceHelper() { auto duration = std::chrono::duration_cast( endTime - _startTime).count(); - _manager->storeIndividualPerformanceMeasurement(std::move(_identifier), duration); + if (_manager) { + _manager->storeIndividualPerformanceMeasurement(std::move(_identifier), duration); + } } diff --git a/src/performance/performancelayout.cpp b/src/performance/performancelayout.cpp index 803a577443..5856f9f7e4 100644 --- a/src/performance/performancelayout.cpp +++ b/src/performance/performancelayout.cpp @@ -29,8 +29,9 @@ namespace openspace { namespace performance { -PerformanceLayout::PerformanceLayout(int32_t nEntries) - : nEntries(nEntries) +PerformanceLayout::PerformanceLayout() + : nScaleGraphEntries(0) + , nFunctionEntries(0) { std::memset( sceneGraphEntries, diff --git a/src/performance/performancemanager.cpp b/src/performance/performancemanager.cpp index bb27fdc626..c7e7c2645b 100644 --- a/src/performance/performancemanager.cpp +++ b/src/performance/performancemanager.cpp @@ -43,6 +43,23 @@ const std::string PerformanceManager::PerformanceMeasurementSharedData = PerformanceManager::PerformanceManager() : _performanceMemory(nullptr) { + // Compute the total size + const int totalSize = sizeof(PerformanceLayout); + LINFO("Create shared memory of " << totalSize << " bytes"); + + try { + ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); + } + 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(); + + // Using the placement-new to create a PerformanceLayout in the shared memory + PerformanceLayout* layout = new (ptr) PerformanceLayout; } PerformanceManager::~PerformanceManager() { @@ -50,12 +67,47 @@ PerformanceManager::~PerformanceManager() { ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); } +void PerformanceManager::resetPerformanceMeasurements() { + // Using the placement-new to create a PerformanceLayout in the shared memory + _performanceMemory->acquireLock(); + void* ptr = _performanceMemory->memory(); + new (ptr) PerformanceLayout; + _performanceMemory->releaseLock(); + + individualPerformanceLocations.clear(); +} + bool PerformanceManager::isMeasuringPerformance() const { return _doPerformanceMeasurements; } -void PerformanceManager::storeIndividualPerformanceMeasurement(std::string identifier, long long us) { +void PerformanceManager::storeIndividualPerformanceMeasurement + (std::string identifier, long long microseconds) +{ + void* ptr = _performanceMemory->memory(); + PerformanceLayout* layout = reinterpret_cast(ptr); + _performanceMemory->acquireLock(); + auto it = individualPerformanceLocations.find(identifier); + PerformanceLayout::FunctionPerformanceLayout* p = nullptr; + if (it == individualPerformanceLocations.end()) { + p = &(layout->functionEntries[layout->nFunctionEntries]); + individualPerformanceLocations[identifier] = layout->nFunctionEntries; + ++(layout->nFunctionEntries); + } + else { + p = &(layout->functionEntries[it->second]); + } +#ifdef _MSC_VER + strcpy_s(p->name, identifier.length() + 1, identifier.c_str()); +#else + strcpy(p->name, identifier.c_str()); +#endif + + p->time[p->currentTime] = static_cast(microseconds); + p->currentTime = (p->currentTime + 1) % PerformanceLayout::NumberValues; + + _performanceMemory->releaseLock(); } void PerformanceManager::storeScenePerformanceMeasurements( @@ -63,47 +115,22 @@ void PerformanceManager::storeScenePerformanceMeasurements( { using namespace performance; - int nNodes = static_cast(sceneNodes.size()); - if (!_performanceMemory) { - // Compute the total size - const int totalSize = sizeof(PerformanceLayout); - LINFO("Create shared memory of " << totalSize << " bytes"); - - try { - ghoul::SharedMemory::remove(PerformanceMeasurementSharedData); - } - 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(); - - // Using the placement-new to create a PerformanceLayout in the shared memory - PerformanceLayout* layout = new (ptr) PerformanceLayout(nNodes); - - for (int i = 0; i < nNodes; ++i) { - SceneGraphNode* node = sceneNodes[i]; - - memset(layout->sceneGraphEntries[i].name, 0, PerformanceLayout::LengthName); -#ifdef _MSC_VER - strcpy_s(layout->sceneGraphEntries[i].name, node->name().length() + 1, node->name().c_str()); -#else - strcpy(layout->sceneGraphEntries[i].name, node->name().c_str()); -#endif - - layout->sceneGraphEntries[i].currentRenderTime = 0; - layout->sceneGraphEntries[i].currentUpdateRenderable = 0; - layout->sceneGraphEntries[i].currentUpdateEphemeris = 0; - } - } - void* ptr = _performanceMemory->memory(); PerformanceLayout* layout = reinterpret_cast(ptr); _performanceMemory->acquireLock(); + + int nNodes = static_cast(sceneNodes.size()); + layout->nScaleGraphEntries = nNodes; for (int i = 0; i < nNodes; ++i) { SceneGraphNode* node = sceneNodes[i]; + + memset(layout->sceneGraphEntries[i].name, 0, PerformanceLayout::LengthName); +#ifdef _MSC_VER + strcpy_s(layout->sceneGraphEntries[i].name, node->name().length() + 1, node->name().c_str()); +#else + strcpy(layout->sceneGraphEntries[i].name, node->name().c_str()); +#endif + SceneGraphNode::PerformanceRecord r = node->performanceRecord(); PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; From 6af96c4ef34ad1bf0de18fca846dd5ae365d9253 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 07:09:54 +0200 Subject: [PATCH 09/14] Add macro for easy generation of PerformanceHelper --- include/openspace/performance/performancehelper.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/openspace/performance/performancehelper.h b/include/openspace/performance/performancehelper.h index 758be2d19a..79ff6e97c5 100644 --- a/include/openspace/performance/performancehelper.h +++ b/include/openspace/performance/performancehelper.h @@ -44,7 +44,13 @@ private: std::chrono::high_resolution_clock::time_point _startTime; }; + +#define __MERGE(a,b) a##b +#define __LABEL(a) __MERGE(unique_name_, a) +/// Declare a new variable for measuring the performance of the current block +#define PerformanceMeasurement(name) auto __LABEL(__LINE__) = openspace::performance::PerformanceHelper((name), OsEng.renderEngine().performanceManager()) + } // namespace performance } // namespace openspace From 5a81b1089a53cce58bba411ac9f14b9e26349d9c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 08:48:44 +0200 Subject: [PATCH 10/14] Rename PerformanceHelper to PerformanceMeasurement Add performance measurements to FramebufferRenderer --- ...erformancehelper.h => performancemeasurement.h} | 14 +++++++------- src/CMakeLists.txt | 4 ++-- ...rmancehelper.cpp => performancemeasurement.cpp} | 8 +++++--- src/rendering/framebufferrenderer.cpp | 12 ++++++++++++ src/rendering/renderengine.cpp | 1 - 5 files changed, 26 insertions(+), 13 deletions(-) rename include/openspace/performance/{performancehelper.h => performancemeasurement.h} (85%) rename src/performance/{performancehelper.cpp => performancemeasurement.cpp} (93%) diff --git a/include/openspace/performance/performancehelper.h b/include/openspace/performance/performancemeasurement.h similarity index 85% rename from include/openspace/performance/performancehelper.h rename to include/openspace/performance/performancemeasurement.h index 79ff6e97c5..f08dbb94b2 100644 --- a/include/openspace/performance/performancehelper.h +++ b/include/openspace/performance/performancemeasurement.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __PERFORMANCEHELPER_H__ -#define __PERFORMANCEHELPER_H__ +#ifndef __PERFORMANCEMEASUREMENT_H__ +#define __PERFORMANCEMEASUREMENT_H__ #include #include @@ -33,10 +33,10 @@ namespace performance { class PerformanceManager; -class PerformanceHelper { +class PerformanceMeasurement { public: - PerformanceHelper(std::string identifier, performance::PerformanceManager* manager); - ~PerformanceHelper(); + PerformanceMeasurement(std::string identifier, performance::PerformanceManager* manager); + ~PerformanceMeasurement(); private: std::string _identifier; @@ -49,9 +49,9 @@ private: #define __LABEL(a) __MERGE(unique_name_, a) /// Declare a new variable for measuring the performance of the current block -#define PerformanceMeasurement(name) auto __LABEL(__LINE__) = openspace::performance::PerformanceHelper((name), OsEng.renderEngine().performanceManager()) +#define PerfMeasure(name) auto __LABEL(__LINE__) = openspace::performance::PerformanceMeasurement((name), OsEng.renderEngine().performanceManager()) } // namespace performance } // namespace openspace -#endif // __PERFORMANCEHELPER_H__ +#endif // __PERFORMANCEMEASUREMENTHELPER_H__ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a9d1bf1732..1d7d1a7670 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,7 +50,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/network/networkengine.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection.cpp ${OPENSPACE_BASE_DIR}/src/network/parallelconnection_lua.inl - ${OPENSPACE_BASE_DIR}/src/performance/performancehelper.cpp + ${OPENSPACE_BASE_DIR}/src/performance/performancemeasurement.cpp ${OPENSPACE_BASE_DIR}/src/performance/performancelayout.cpp ${OPENSPACE_BASE_DIR}/src/performance/performancemanager.cpp ${OPENSPACE_BASE_DIR}/src/properties/matrixproperty.cpp @@ -122,7 +122,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/network/networkengine.h ${OPENSPACE_BASE_DIR}/include/openspace/network/parallelconnection.h ${OPENSPACE_BASE_DIR}/include/openspace/network/messagestructures.h - ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancehelper.h + ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancemeasurement.h ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancelayout.h ${OPENSPACE_BASE_DIR}/include/openspace/performance/performancemanager.h ${OPENSPACE_BASE_DIR}/include/openspace/properties/matrixproperty.h diff --git a/src/performance/performancehelper.cpp b/src/performance/performancemeasurement.cpp similarity index 93% rename from src/performance/performancehelper.cpp rename to src/performance/performancemeasurement.cpp index 5bf6593912..a62a6d5d4e 100644 --- a/src/performance/performancehelper.cpp +++ b/src/performance/performancemeasurement.cpp @@ -22,16 +22,18 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include +#include + namespace openspace { namespace performance { -PerformanceHelper::PerformanceHelper(std::string identifier, +PerformanceMeasurement::PerformanceMeasurement(std::string identifier, performance::PerformanceManager* manager) : _identifier(std::move(identifier)) , _manager(manager) @@ -43,7 +45,7 @@ PerformanceHelper::PerformanceHelper(std::string identifier, } } -PerformanceHelper::~PerformanceHelper() { +PerformanceMeasurement::~PerformanceMeasurement() { auto endTime = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast( endTime - _startTime).count(); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 6d407d1646..103aac13a9 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -33,6 +33,8 @@ #include #include +#include + #include #include #include @@ -157,6 +159,8 @@ void FramebufferRenderer::raycastersChanged(VolumeRaycaster& raycaster, bool att } void FramebufferRenderer::update() { + PerfMeasure("FramebufferRenderer::update"); + if (_dirtyResolution) { updateResolution(); } @@ -197,6 +201,8 @@ void FramebufferRenderer::update() { } void FramebufferRenderer::updateResolution() { + PerfMeasure("FramebufferRenderer::updateResolution"); + int nSamples = OsEng.windowWrapper().currentNumberOfAaSamples(); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainColorTexture); @@ -252,6 +258,8 @@ void FramebufferRenderer::updateResolution() { } void FramebufferRenderer::updateRaycastData() { + PerfMeasure("FramebufferRenderer::updateRaycastData"); + _raycastData.clear(); _exitPrograms.clear(); _raycastPrograms.clear(); @@ -296,6 +304,8 @@ void FramebufferRenderer::updateRaycastData() { } void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurements) { + PerfMeasure("FramebufferRenderer::render"); + if (!_scene) return; if (!_camera) @@ -398,6 +408,8 @@ void FramebufferRenderer::setResolution(glm::ivec2 res) { } void FramebufferRenderer::updateRendererData() { + PerfMeasure("FramebufferRenderer::updateRendererData"); + ghoul::Dictionary dict; dict.setValue("fragmentRendererPath", std::string(RenderFragmentShaderPath)); dict.setValue("postFragmentRendererPath", std::string(PostRenderFragmentShaderPath)); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 6fe69e311e..54b4fcdf04 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -223,7 +223,6 @@ bool RenderEngine::initializeGL() { // development OsEng.windowWrapper().setNearFarClippingPlane(0.001f, 1000.f); - try { const float fontSizeTime = 15.f; _fontDate = OsEng.fontManager().font(KeyFontMono, fontSizeTime); From 16559231bdceb1773c0d4da65d15bfa305574317 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 09:01:15 +0200 Subject: [PATCH 11/14] Move Performance ImGui components into separate windows --- .../include/guiperformancecomponent.h | 3 +++ .../src/guiperformancecomponent.cpp | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/onscreengui/include/guiperformancecomponent.h b/modules/onscreengui/include/guiperformancecomponent.h index f7fde598ac..21577e7f61 100644 --- a/modules/onscreengui/include/guiperformancecomponent.h +++ b/modules/onscreengui/include/guiperformancecomponent.h @@ -45,6 +45,9 @@ protected: ghoul::SharedMemory* _performanceMemory = nullptr; float _minMaxValues[2]; int _sortingSelection; + + bool _sceneGraphIsEnabled; + bool _functionsIsEnabled; }; } // namespace gui diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index 8193ec9657..d5c6223731 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -48,6 +48,9 @@ void GuiPerformanceComponent::initialize() { _minMaxValues[0] = 100.f; _minMaxValues[1] = 250.f; _sortingSelection = -1; + + _sceneGraphIsEnabled = false; + _functionsIsEnabled = false; } void GuiPerformanceComponent::deinitialize() { @@ -62,10 +65,15 @@ void GuiPerformanceComponent::render() { if (OsEng.renderEngine().doesPerformanceMeasurements() && ghoul::SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData)) { - ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 10000.f); + ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 250000.f); _minMaxValues[1] = fmaxf(_minMaxValues[0], _minMaxValues[1]); - if (ImGui::CollapsingHeader("SceneGraph")) { + ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled); + ImGui::Checkbox("Functions", &_functionsIsEnabled); + + if (_sceneGraphIsEnabled) { + ImGui::Begin("SceneGraph", &_sceneGraphIsEnabled); + // The indices correspond to the index into the average array further below ImGui::Text("Sorting"); ImGui::RadioButton("No Sorting", &_sortingSelection, -1); @@ -169,9 +177,11 @@ void GuiPerformanceComponent::render() { ); } } + ImGui::End(); } - if (ImGui::CollapsingHeader("Functions")) { + if (_functionsIsEnabled) { + ImGui::Begin("Functions", &_functionsIsEnabled); using namespace performance; if (!_performanceMemory) @@ -207,7 +217,7 @@ void GuiPerformanceComponent::render() { ImVec2(0, 40) ); } - + ImGui::End(); } } else { From 742bfcfe86094e0cbc0568afd82854d02739f026 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 09:52:47 +0200 Subject: [PATCH 12/14] Remove static min/max values and compute scaling factors directly from data --- .../include/guiperformancecomponent.h | 1 - .../src/guiperformancecomponent.cpp | 75 ++++++++++++++----- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/modules/onscreengui/include/guiperformancecomponent.h b/modules/onscreengui/include/guiperformancecomponent.h index 21577e7f61..882c277fe4 100644 --- a/modules/onscreengui/include/guiperformancecomponent.h +++ b/modules/onscreengui/include/guiperformancecomponent.h @@ -43,7 +43,6 @@ public: protected: ghoul::SharedMemory* _performanceMemory = nullptr; - float _minMaxValues[2]; int _sortingSelection; bool _sceneGraphIsEnabled; diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index d5c6223731..a81e8c6b85 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -45,8 +45,6 @@ namespace openspace { namespace gui { void GuiPerformanceComponent::initialize() { - _minMaxValues[0] = 100.f; - _minMaxValues[1] = 250.f; _sortingSelection = -1; _sceneGraphIsEnabled = false; @@ -65,9 +63,6 @@ void GuiPerformanceComponent::render() { if (OsEng.renderEngine().doesPerformanceMeasurements() && ghoul::SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData)) { - ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 250000.f); - _minMaxValues[1] = fmaxf(_minMaxValues[0], _minMaxValues[1]); - ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled); ImGui::Checkbox("Functions", &_functionsIsEnabled); @@ -96,7 +91,11 @@ void GuiPerformanceComponent::render() { // UpdateRender // RenderTime std::vector> averages(layout->nScaleGraphEntries, { 0.f, 0.f, 0.f }); - + + std::vector, 3>> minMax( + layout->nScaleGraphEntries + ); + for (int i = 0; i < layout->nScaleGraphEntries; ++i) { const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; @@ -105,13 +104,13 @@ void GuiPerformanceComponent::render() { for (int j = 0; j < PerformanceLayout::NumberValues; ++j) { averages[i][0] += entry.updateEphemeris[j]; if (entry.updateEphemeris[j] != 0.f) - ++v[0]; + ++(v[0]); averages[i][1] += entry.updateRenderable[j]; if (entry.updateRenderable[j] != 0.f) - ++v[1]; + ++(v[1]); averages[i][2] += entry.renderTime[j]; if (entry.renderTime[j] != 0.f) - ++v[2]; + ++(v[2]); } if (v[0] != 0) @@ -120,6 +119,37 @@ void GuiPerformanceComponent::render() { averages[i][1] /= static_cast(v[1]); if (v[2] != 0) averages[i][2] /= static_cast(v[2]); + + auto minmaxEphemeris = std::minmax_element( + std::begin(entry.updateEphemeris), + std::end(entry.updateEphemeris) + ); + minMax[i][0] = std::make_pair( + *(minmaxEphemeris.first), + *(minmaxEphemeris.second) + ); + + + auto minmaxUpdateRenderable = std::minmax_element( + std::begin(entry.updateRenderable), + std::end(entry.updateRenderable) + ); + minMax[i][1] = std::make_pair( + *(minmaxUpdateRenderable.first), + *(minmaxUpdateRenderable.second) + ); + + + auto minmaxRendering = std::minmax_element( + std::begin(entry.renderTime), + std::end(entry.renderTime) + ); + minMax[i][2] = std::make_pair( + *(minmaxRendering.first), + *(minmaxRendering.second) + ); + + } if (_sortingSelection != -1) { @@ -142,37 +172,37 @@ void GuiPerformanceComponent::render() { std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us"; ; ImGui::PlotLines( - fmt::format("UpdateEphemeris\nAverage: {}us", averages[i][0]).c_str(), + fmt::format("UpdateEphemeris\nAverage: {}us", averages[indices[i]][0]).c_str(), &entry.updateEphemeris[0], PerformanceLayout::NumberValues, 0, updateEphemerisTime.c_str(), - _minMaxValues[0], - _minMaxValues[1], + minMax[indices[i]][0].first, + minMax[indices[i]][0].second, ImVec2(0, 40) ); std::string updateRenderableTime = std::to_string(entry.updateRenderable[entry.currentUpdateRenderable - 1]) + "us"; ImGui::PlotLines( - fmt::format("UpdateRender\nAverage: {}us", averages[i][1]).c_str(), + fmt::format("UpdateRender\nAverage: {}us", averages[indices[i]][1]).c_str(), &entry.updateRenderable[0], PerformanceLayout::NumberValues, 0, updateRenderableTime.c_str(), - _minMaxValues[0], - _minMaxValues[1], + minMax[indices[i]][1].first, + minMax[indices[i]][1].second, ImVec2(0, 40) ); std::string renderTime = std::to_string(entry.renderTime[entry.currentRenderTime - 1]) + "us"; ImGui::PlotLines( - fmt::format("RenderTime\nAverage: {}us", averages[i][2]).c_str(), + fmt::format("RenderTime\nAverage: {}us", averages[indices[i]][2]).c_str(), &entry.renderTime[0], PerformanceLayout::NumberValues, 0, renderTime.c_str(), - _minMaxValues[0], - _minMaxValues[1], + minMax[indices[i]][2].first, + minMax[indices[i]][2].second, ImVec2(0, 40) ); } @@ -203,6 +233,11 @@ void GuiPerformanceComponent::render() { } avg /= count; + auto minmax = std::minmax_element( + std::begin(layout->functionEntries[i].time), + std::end(layout->functionEntries[i].time) + ); + const PerformanceLayout::FunctionPerformanceLayout& f = layout->functionEntries[i]; std::string renderTime = std::to_string(entry.time[entry.currentTime - 1]) + "us"; @@ -212,8 +247,8 @@ void GuiPerformanceComponent::render() { PerformanceLayout::NumberValues, 0, renderTime.c_str(), - _minMaxValues[0], - _minMaxValues[1], + *(minmax.first), + *(minmax.second), ImVec2(0, 40) ); } From 55456ae2728d2a9ca81829aad155ffe8af45daa2 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Jun 2016 10:23:28 +0200 Subject: [PATCH 13/14] Add button to reset performance measurements Clang compile fix --- ext/ghoul | 2 +- include/openspace/util/transformationmanager.h | 5 ++++- modules/onscreengui/src/guiperformancecomponent.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 735ed53cd2..3034cb3d3e 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 735ed53cd236a7a7cca36d6289ce95909e6a0c92 +Subproject commit 3034cb3d3ebe8474e21fe2bb8e4e6cc275213b63 diff --git a/include/openspace/util/transformationmanager.h b/include/openspace/util/transformationmanager.h index 2443004852..0bbe37c459 100644 --- a/include/openspace/util/transformationmanager.h +++ b/include/openspace/util/transformationmanager.h @@ -33,9 +33,12 @@ #include +namespace ccmc { + class Kameleon; +} // namespace ccmc + namespace openspace { #ifdef OPENSPACE_MODULE_KAMELEON_ENABLED -class ccmc::Kameleon; #endif class TransformationManager : public ghoul::Singleton { friend class ghoul::Singleton; diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index a81e8c6b85..78f875a91b 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -66,6 +66,12 @@ void GuiPerformanceComponent::render() { ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled); ImGui::Checkbox("Functions", &_functionsIsEnabled); + ImGui::Spacing(); + + if (ImGui::Button("Reset measurements")) { + OsEng.renderEngine().performanceManager()->resetPerformanceMeasurements(); + } + if (_sceneGraphIsEnabled) { ImGui::Begin("SceneGraph", &_sceneGraphIsEnabled); From 146b71e1295e0303a570fa5b1975faecde20bce5 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 7 Jun 2016 11:16:27 +0200 Subject: [PATCH 14/14] Make performance widget graphs fill from right to left instead of circular --- ext/ghoul | 2 +- .../openspace/performance/performancelayout.h | 5 --- .../src/guiperformancecomponent.cpp | 8 ++--- src/performance/performancemanager.cpp | 36 ++++++++++++++----- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 3034cb3d3e..111c53c94c 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 3034cb3d3ebe8474e21fe2bb8e4e6cc275213b63 +Subproject commit 111c53c94cfe514122a71225bb9e903f0a367278 diff --git a/include/openspace/performance/performancelayout.h b/include/openspace/performance/performancelayout.h index 2348d765b8..70568e67e5 100644 --- a/include/openspace/performance/performancelayout.h +++ b/include/openspace/performance/performancelayout.h @@ -43,10 +43,6 @@ struct PerformanceLayout { float renderTime[NumberValues]; float updateRenderable[NumberValues]; float updateEphemeris[NumberValues]; - - int32_t currentRenderTime; - int32_t currentUpdateRenderable; - int32_t currentUpdateEphemeris; }; SceneGraphPerformanceLayout sceneGraphEntries[MaxValues]; int16_t nScaleGraphEntries; @@ -54,7 +50,6 @@ struct PerformanceLayout { struct FunctionPerformanceLayout { char name[LengthName]; float time[NumberValues]; - int32_t currentTime; }; FunctionPerformanceLayout functionEntries[MaxValues]; int16_t nFunctionEntries; diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index 78f875a91b..0bd4511ab3 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -175,7 +175,7 @@ void GuiPerformanceComponent::render() { const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]]; if (ImGui::CollapsingHeader(entry.name)) { - std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 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(), @@ -188,7 +188,7 @@ void GuiPerformanceComponent::render() { ImVec2(0, 40) ); - std::string updateRenderableTime = std::to_string(entry.updateRenderable[entry.currentUpdateRenderable - 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(), &entry.updateRenderable[0], @@ -200,7 +200,7 @@ void GuiPerformanceComponent::render() { ImVec2(0, 40) ); - std::string renderTime = std::to_string(entry.renderTime[entry.currentRenderTime - 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(), &entry.renderTime[0], @@ -246,7 +246,7 @@ void GuiPerformanceComponent::render() { const PerformanceLayout::FunctionPerformanceLayout& f = layout->functionEntries[i]; - std::string renderTime = std::to_string(entry.time[entry.currentTime - 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], diff --git a/src/performance/performancemanager.cpp b/src/performance/performancemanager.cpp index c7e7c2645b..91731768a0 100644 --- a/src/performance/performancemanager.cpp +++ b/src/performance/performancemanager.cpp @@ -104,8 +104,13 @@ void PerformanceManager::storeIndividualPerformanceMeasurement strcpy(p->name, identifier.c_str()); #endif - p->time[p->currentTime] = static_cast(microseconds); - p->currentTime = (p->currentTime + 1) % PerformanceLayout::NumberValues; + std::rotate( + std::begin(p->time), + std::next(std::begin(p->time)), + std::end(p->time) + ); + p->time[PerformanceLayout::NumberValues - 1] = + static_cast(microseconds); _performanceMemory->releaseLock(); } @@ -134,13 +139,26 @@ void PerformanceManager::storeScenePerformanceMeasurements( SceneGraphNode::PerformanceRecord r = node->performanceRecord(); PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; - entry.renderTime[entry.currentRenderTime] = r.renderTime / 1000.f; - entry.updateEphemeris[entry.currentUpdateEphemeris] = r.updateTimeEphemeris / 1000.f; - entry.updateRenderable[entry.currentUpdateRenderable] = r.updateTimeRenderable / 1000.f; - - entry.currentRenderTime = (entry.currentRenderTime + 1) % PerformanceLayout::NumberValues; - entry.currentUpdateEphemeris = (entry.currentUpdateEphemeris + 1) % PerformanceLayout::NumberValues; - entry.currentUpdateRenderable = (entry.currentUpdateRenderable + 1) % PerformanceLayout::NumberValues; + std::rotate( + std::begin(entry.renderTime), + std::next(std::begin(entry.renderTime)), + std::end(entry.renderTime) + ); + entry.renderTime[PerformanceLayout::NumberValues - 1] = r.renderTime / 1000.f; + + std::rotate( + std::begin(entry.updateEphemeris), + std::next(std::begin(entry.updateEphemeris)), + std::end(entry.updateEphemeris) + ); + entry.updateEphemeris[PerformanceLayout::NumberValues - 1] = r.updateTimeEphemeris / 1000.f; + + std::rotate( + std::begin(entry.updateRenderable), + std::next(std::begin(entry.updateRenderable)), + std::end(entry.updateRenderable) + ); + entry.updateRenderable[PerformanceLayout::NumberValues - 1] = r.updateTimeRenderable / 1000.f; } _performanceMemory->releaseLock(); }