Added support for profiling LUA

This commit is contained in:
npwoods 2019-07-24 10:58:49 -04:00
parent aa2f9428dc
commit 65e26990d1
4 changed files with 24 additions and 6 deletions

View File

@ -159,6 +159,7 @@ void real_profiler_state::update_text(running_machine &machine)
{ PROFILER_INPUT, "Input Processing" },
{ PROFILER_MOVIE_REC, "Movie Recording" },
{ PROFILER_LOGERROR, "Error Logging" },
{ PROFILER_LUA, "LUA" },
{ PROFILER_EXTRA, "Unaccounted/Overhead" },
{ PROFILER_USER1, "User 1" },
{ PROFILER_USER2, "User 2" },

View File

@ -48,9 +48,10 @@ enum profile_type
PROFILER_BLIT,
PROFILER_SOUND,
PROFILER_TIMER_CALLBACK,
PROFILER_INPUT, // input.c and inptport.c
PROFILER_INPUT, // input.cpp and inptport.cpp
PROFILER_MOVIE_REC, // movie recording
PROFILER_LOGERROR, // logerror
PROFILER_LUA, // LUA
PROFILER_EXTRA, // everything else
// the USER types are available to driver writers to profile

View File

@ -592,7 +592,7 @@ sol::object lua_engine::call_plugin(const std::string &name, sol::object in)
sol::object obj = sol().registry()[field];
if(obj.is<sol::protected_function>())
{
auto res = (obj.as<sol::protected_function>())(in);
auto res = invoke(obj.as<sol::protected_function>(), in);
if(!res.valid())
{
sol::error err = res;
@ -610,7 +610,7 @@ void lua_engine::menu_populate(const std::string &menu, std::vector<std::tuple<s
sol::object obj = sol().registry()[field];
if(obj.is<sol::protected_function>())
{
auto res = (obj.as<sol::protected_function>())();
auto res = invoke(obj.as<sol::protected_function>());
if(!res.valid())
{
sol::error err = res;
@ -638,7 +638,7 @@ bool lua_engine::menu_callback(const std::string &menu, int index, const std::st
sol::object obj = sol().registry()[field];
if(obj.is<sol::protected_function>())
{
auto res = (obj.as<sol::protected_function>())(index, event);
auto res = invoke(obj.as<sol::protected_function>(), index, event);
if(!res.valid())
{
sol::error err = res;
@ -659,7 +659,7 @@ bool lua_engine::execute_function(const char *id)
{
if(func.second.is<sol::protected_function>())
{
auto ret = (func.second.as<sol::protected_function>())();
auto ret = invoke(func.second.as<sol::protected_function>());
if(!ret.valid())
{
sol::error err = ret;
@ -2554,7 +2554,7 @@ void lua_engine::run(sol::load_result res)
{
if(res.valid())
{
auto ret = (res.get<sol::protected_function>())();
auto ret = invoke(res.get<sol::protected_function>());
if(!ret.valid())
{
sol::error err = ret;
@ -2582,3 +2582,16 @@ void lua_engine::load_string(const char *value)
{
run(sol().load(value));
}
//-------------------------------------------------
// invoke - invokes a function, wrapping profiler
//-------------------------------------------------
template<typename TFunc, typename... TArgs>
sol::protected_function_result lua_engine::invoke(TFunc &&func, TArgs&&... args)
{
g_profiler.start(PROFILER_LUA);
sol::protected_function_result result = func(std::forward<TArgs>(args)...);
g_profiler.stop();
return result;
}

View File

@ -166,6 +166,9 @@ private:
bool busy;
bool yield;
};
template<typename TFunc, typename... TArgs>
sol::protected_function_result invoke(TFunc &&func, TArgs&&... args);
};
#endif // MAME_FRONTEND_MAME_LUAENGINE_H