From a74b842e16a8e2fdcdea793a7528fd907d01f3ce Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 30 Sep 2022 01:46:43 +0200 Subject: [PATCH] Report used memory by Lua interpreter --- apps/openmw/engine.cpp | 4 +++- apps/openmw/mwbase/environment.cpp | 17 ----------------- apps/openmw/mwbase/environment.hpp | 7 ------- apps/openmw/mwlua/luamanagerimp.cpp | 9 +++++++++ apps/openmw/mwlua/luamanagerimp.hpp | 2 ++ components/resource/stats.cpp | 2 ++ 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 0bfe71c1e9..7be3cd8bf3 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -440,7 +440,9 @@ bool OMW::Engine::frame(float frametime) stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems()); stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads()); - mEnvironment.reportStats(frameNumber, *stats); + mMechanicsManager->reportStats(frameNumber, *stats); + mWorld->reportStats(frameNumber, *stats); + mLuaManager->reportStats(frameNumber, *stats); } } catch (const std::exception& e) diff --git a/apps/openmw/mwbase/environment.cpp b/apps/openmw/mwbase/environment.cpp index 927db90288..7b2e79b9e7 100644 --- a/apps/openmw/mwbase/environment.cpp +++ b/apps/openmw/mwbase/environment.cpp @@ -4,17 +4,6 @@ #include -#include "world.hpp" -#include "scriptmanager.hpp" -#include "dialoguemanager.hpp" -#include "journal.hpp" -#include "soundmanager.hpp" -#include "mechanicsmanager.hpp" -#include "inputmanager.hpp" -#include "windowmanager.hpp" -#include "statemanager.hpp" -#include "luamanager.hpp" - MWBase::Environment *MWBase::Environment::sThis = nullptr; MWBase::Environment::Environment() @@ -27,9 +16,3 @@ MWBase::Environment::~Environment() { sThis = nullptr; } - -void MWBase::Environment::reportStats(unsigned int frameNumber, osg::Stats& stats) const -{ - mMechanicsManager->reportStats(frameNumber, stats); - mWorld->reportStats(frameNumber, stats); -} diff --git a/apps/openmw/mwbase/environment.hpp b/apps/openmw/mwbase/environment.hpp index 0c5d39425b..b1ea13efa8 100644 --- a/apps/openmw/mwbase/environment.hpp +++ b/apps/openmw/mwbase/environment.hpp @@ -5,11 +5,6 @@ #include -namespace osg -{ - class Stats; -} - namespace Resource { class ResourceSystem; @@ -118,8 +113,6 @@ namespace MWBase assert(sThis != nullptr); return *sThis; } - - void reportStats(unsigned int frameNumber, osg::Stats& stats) const; }; } diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index dd21517669..1eb0352e3a 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -1,5 +1,9 @@ #include "luamanagerimp.hpp" +#include + +#include "sol/state_view.hpp" + #include #include @@ -598,4 +602,9 @@ namespace MWLua mActionQueue.push_back(std::make_unique(&mLua, std::move(action), name)); } + void LuaManager::reportStats(unsigned int frameNumber, osg::Stats& stats) + { + const sol::state_view state(mLua.sol()); + stats.setAttribute(frameNumber, "Lua UsedMemory", state.memory_used()); + } } diff --git a/apps/openmw/mwlua/luamanagerimp.hpp b/apps/openmw/mwlua/luamanagerimp.hpp index 3f3d8566a7..25c867e601 100644 --- a/apps/openmw/mwlua/luamanagerimp.hpp +++ b/apps/openmw/mwlua/luamanagerimp.hpp @@ -126,6 +126,8 @@ namespace MWLua bool isProcessingInputEvents() const { return mProcessingInputEvents; } + void reportStats(unsigned int frameNumber, osg::Stats& stats); + private: void initConfiguration(); LocalScripts* createLocalScripts(const MWWorld::Ptr& ptr, diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index c5229f491a..36a07be028 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -453,6 +453,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) "Physics Objects", "Physics Projectiles", "Physics HeightFields", + "", + "Lua UsedMemory", }); static const auto longest = std::max_element(statNames.begin(), statNames.end(),