mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-01 08:09:46 +00:00
Additional information in Lua profiler
This commit is contained in:
parent
203eb80afd
commit
d9e9db0983
7 changed files with 38 additions and 7 deletions
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <components/lua/utilpackage.hpp>
|
#include <components/lua/utilpackage.hpp>
|
||||||
|
|
||||||
|
#include <components/lua_ui/content.hpp>
|
||||||
#include <components/lua_ui/util.hpp>
|
#include <components/lua_ui/util.hpp>
|
||||||
|
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
@ -639,6 +640,9 @@ namespace MWLua
|
||||||
out << "Total memory usage:";
|
out << "Total memory usage:";
|
||||||
outMemSize(mLua.getTotalMemoryUsage());
|
outMemSize(mLua.getTotalMemoryUsage());
|
||||||
out << "\n";
|
out << "\n";
|
||||||
|
out << "LuaUtil::ScriptsContainer count: " << LuaUtil::ScriptsContainer::getInstanceCount() << "\n";
|
||||||
|
out << "LuaUi::Content count: " << LuaUi::Content::getInstanceCount() << "\n";
|
||||||
|
out << "\n";
|
||||||
out << "small alloc max size = " << smallAllocSize << " (section [Lua] in settings.cfg)\n";
|
out << "small alloc max size = " << smallAllocSize << " (section [Lua] in settings.cfg)\n";
|
||||||
out << "Smaller values give more information for the profiler, but increase performance overhead.\n";
|
out << "Smaller values give more information for the profiler, but increase performance overhead.\n";
|
||||||
out << " Memory allocations <= " << smallAllocSize << " bytes:";
|
out << " Memory allocations <= " << smallAllocSize << " bytes:";
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace MWLua
|
||||||
};
|
};
|
||||||
uiContent["add"]
|
uiContent["add"]
|
||||||
= [](LuaUi::Content& content, const sol::table& table) { content.insert(content.size(), table); };
|
= [](LuaUi::Content& content, const sol::table& table) { content.insert(content.size(), table); };
|
||||||
uiContent["indexOf"] = [](LuaUi::Content& content, const sol::table& table) -> sol::optional<size_t> {
|
uiContent["indexOf"] = [](const LuaUi::Content& content, const sol::table& table) -> sol::optional<size_t> {
|
||||||
size_t index = content.indexOf(table);
|
size_t index = content.indexOf(table);
|
||||||
if (index < content.size())
|
if (index < content.size())
|
||||||
return toLuaIndex(index);
|
return toLuaIndex(index);
|
||||||
|
@ -123,8 +123,9 @@ namespace MWLua
|
||||||
return sol::nullopt;
|
return sol::nullopt;
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
auto pairs = [](LuaUi::Content& content) {
|
auto pairs = [](const LuaUi::Content& content) {
|
||||||
auto next = [](LuaUi::Content& content, size_t i) -> sol::optional<std::tuple<size_t, sol::table>> {
|
auto next
|
||||||
|
= [](const LuaUi::Content& content, size_t i) -> sol::optional<std::tuple<size_t, sol::table>> {
|
||||||
if (i < content.size())
|
if (i < content.size())
|
||||||
return std::make_tuple(i + 1, content.at(i));
|
return std::make_tuple(i + 1, content.at(i));
|
||||||
else
|
else
|
||||||
|
|
|
@ -15,11 +15,14 @@ namespace LuaUtil
|
||||||
static constexpr std::string_view HANDLER_LOAD = "onLoad";
|
static constexpr std::string_view HANDLER_LOAD = "onLoad";
|
||||||
static constexpr std::string_view HANDLER_INTERFACE_OVERRIDE = "onInterfaceOverride";
|
static constexpr std::string_view HANDLER_INTERFACE_OVERRIDE = "onInterfaceOverride";
|
||||||
|
|
||||||
|
int64_t ScriptsContainer::sInstanceCount = 0;
|
||||||
|
|
||||||
ScriptsContainer::ScriptsContainer(LuaUtil::LuaState* lua, std::string_view namePrefix)
|
ScriptsContainer::ScriptsContainer(LuaUtil::LuaState* lua, std::string_view namePrefix)
|
||||||
: mNamePrefix(namePrefix)
|
: mNamePrefix(namePrefix)
|
||||||
, mLua(*lua)
|
, mLua(*lua)
|
||||||
, mThis(std::make_shared<ScriptsContainer*>(this))
|
, mThis(std::make_shared<ScriptsContainer*>(this))
|
||||||
{
|
{
|
||||||
|
sInstanceCount++;
|
||||||
registerEngineHandlers({ &mUpdateHandlers });
|
registerEngineHandlers({ &mUpdateHandlers });
|
||||||
mPublicInterfaces = sol::table(lua->sol(), sol::create);
|
mPublicInterfaces = sol::table(lua->sol(), sol::create);
|
||||||
addPackage("openmw.interfaces", mPublicInterfaces);
|
addPackage("openmw.interfaces", mPublicInterfaces);
|
||||||
|
@ -476,6 +479,7 @@ namespace LuaUtil
|
||||||
|
|
||||||
ScriptsContainer::~ScriptsContainer()
|
ScriptsContainer::~ScriptsContainer()
|
||||||
{
|
{
|
||||||
|
sInstanceCount--;
|
||||||
for (auto& [_, script] : mScripts)
|
for (auto& [_, script] : mScripts)
|
||||||
script.mHiddenData[sScriptIdKey] = sol::nil;
|
script.mHiddenData[sScriptIdKey] = sol::nil;
|
||||||
*mThis = nullptr;
|
*mThis = nullptr;
|
||||||
|
|
|
@ -155,6 +155,7 @@ namespace LuaUtil
|
||||||
int64_t mMemoryUsage = 0; // bytes
|
int64_t mMemoryUsage = 0; // bytes
|
||||||
};
|
};
|
||||||
void collectStats(std::vector<ScriptStats>& stats) const;
|
void collectStats(std::vector<ScriptStats>& stats) const;
|
||||||
|
static int64_t getInstanceCount() { return sInstanceCount; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct Handler
|
struct Handler
|
||||||
|
@ -265,6 +266,8 @@ namespace LuaUtil
|
||||||
|
|
||||||
std::map<int, int64_t> mRemovedScriptsMemoryUsage;
|
std::map<int, int64_t> mRemovedScriptsMemoryUsage;
|
||||||
std::shared_ptr<ScriptsContainer*> mThis; // used by LuaState to track ownership of memory allocations
|
std::shared_ptr<ScriptsContainer*> mThis; // used by LuaState to track ownership of memory allocations
|
||||||
|
|
||||||
|
static int64_t sInstanceCount; // debug information, shown in Lua profiler
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wrapper for a Lua function.
|
// Wrapper for a Lua function.
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
|
|
||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
|
int64_t Content::sInstanceCount = 0;
|
||||||
|
|
||||||
Content::Content(const sol::table& table)
|
Content::Content(const sol::table& table)
|
||||||
{
|
{
|
||||||
|
sInstanceCount++;
|
||||||
size_t size = table.size();
|
size_t size = table.size();
|
||||||
for (size_t index = 0; index < size; ++index)
|
for (size_t index = 0; index < size; ++index)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +97,7 @@ namespace LuaUi
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Content::indexOf(const sol::table& table)
|
size_t Content::indexOf(const sol::table& table) const
|
||||||
{
|
{
|
||||||
auto it = std::find(mOrdered.begin(), mOrdered.end(), table);
|
auto it = std::find(mOrdered.begin(), mOrdered.end(), table);
|
||||||
if (it == mOrdered.end())
|
if (it == mOrdered.end())
|
||||||
|
|
|
@ -13,7 +13,20 @@ namespace LuaUi
|
||||||
public:
|
public:
|
||||||
using iterator = std::vector<sol::table>::iterator;
|
using iterator = std::vector<sol::table>::iterator;
|
||||||
|
|
||||||
Content() {}
|
Content() { sInstanceCount++; }
|
||||||
|
~Content() { sInstanceCount--; }
|
||||||
|
Content(const Content& c)
|
||||||
|
{
|
||||||
|
this->mNamed = c.mNamed;
|
||||||
|
this->mOrdered = c.mOrdered;
|
||||||
|
sInstanceCount++;
|
||||||
|
}
|
||||||
|
Content(Content&& c)
|
||||||
|
{
|
||||||
|
this->mNamed = std::move(c.mNamed);
|
||||||
|
this->mOrdered = std::move(c.mOrdered);
|
||||||
|
sInstanceCount++;
|
||||||
|
}
|
||||||
|
|
||||||
// expects a Lua array - a table with keys from 1 to n without any nil values in between
|
// expects a Lua array - a table with keys from 1 to n without any nil values in between
|
||||||
// any other keys are ignored
|
// any other keys are ignored
|
||||||
|
@ -29,11 +42,14 @@ namespace LuaUi
|
||||||
sol::table at(std::string_view name) const;
|
sol::table at(std::string_view name) const;
|
||||||
size_t remove(size_t index);
|
size_t remove(size_t index);
|
||||||
size_t remove(std::string_view name);
|
size_t remove(std::string_view name);
|
||||||
size_t indexOf(const sol::table& table);
|
size_t indexOf(const sol::table& table) const;
|
||||||
|
|
||||||
|
static int64_t getInstanceCount() { return sInstanceCount; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, size_t, std::less<>> mNamed;
|
std::map<std::string, size_t, std::less<>> mNamed;
|
||||||
std::vector<sol::table> mOrdered;
|
std::vector<sol::table> mOrdered;
|
||||||
|
static int64_t sInstanceCount; // debug information, shown in Lua profiler
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace LuaUi
|
||||||
}
|
}
|
||||||
if (!contentObj.is<Content>())
|
if (!contentObj.is<Content>())
|
||||||
throw std::logic_error("Layout content field must be a openmw.ui.content");
|
throw std::logic_error("Layout content field must be a openmw.ui.content");
|
||||||
Content content = contentObj.as<Content>();
|
const Content& content = contentObj.as<Content>();
|
||||||
result.resize(content.size());
|
result.resize(content.size());
|
||||||
size_t minSize = std::min(children.size(), content.size());
|
size_t minSize = std::min(children.size(), content.size());
|
||||||
for (size_t i = 0; i < minSize; i++)
|
for (size_t i = 0; i < minSize; i++)
|
||||||
|
|
Loading…
Reference in a new issue