From 61f73accfbe2ea1ffdd8569fece6a27c36c03539 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 12 Feb 2024 21:02:41 -0500 Subject: [PATCH] Lua runtime stats --- firmware/controllers/lua/lua.cpp | 17 +++++++++++++++-- firmware/controllers/lua/lua_can_rx.cpp | 8 ++++++-- firmware/controllers/lua/rusefi_lua.h | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index f8a7fb0277..023066b754 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -30,6 +30,10 @@ LUA_HEAD_RAM_SECTION #endif ; +static int recentRxCount = 0; +static int totalRxCount = 0; +static int rxTime; + class Heap { public: memory_heap_t m_heap; @@ -324,7 +328,9 @@ static bool runOneLua(lua_Alloc alloc, const char* script) { efitick_t beforeNt = getTimeNowNt(); #if EFI_CAN_SUPPORT // First, process any pending can RX messages - doLuaCanRx(ls); + totalRxCount += recentRxCount; + recentRxCount = doLuaCanRx(ls); + rxTime = getTimeNowNt() - beforeNt; #endif // EFI_CAN_SUPPORT // Next, check if there is a pending interactive command entered by the user @@ -411,7 +417,14 @@ void startLua() { needsReset = true; }); - addConsoleAction("luamemory", printLuaMemoryInfo); + addConsoleAction("luamemory", [](){ + efiPrintf("rx total/recent %d %d", totalRxCount, + recentRxCount); + efiPrintf("luaCycle %dus including luaRxTime %dus", NT2US(engine->outputChannels.luaLastCycleDuration), + NT2US(rxTime)); + + printLuaMemoryInfo(); + }); #endif } diff --git a/firmware/controllers/lua/lua_can_rx.cpp b/firmware/controllers/lua/lua_can_rx.cpp index 4a89fe02bd..3993e507b2 100644 --- a/firmware/controllers/lua/lua_can_rx.cpp +++ b/firmware/controllers/lua/lua_can_rx.cpp @@ -128,9 +128,13 @@ bool doOneLuaCanRx(LuaHandle& ls) { return true; } -void doLuaCanRx(LuaHandle& ls) { +int doLuaCanRx(LuaHandle& ls) { + int counter = 0; // While it processed a frame, continue checking - while (doOneLuaCanRx(ls)) ; + while (doOneLuaCanRx(ls)) { + counter++; + } + return counter; } void initLuaCanRx() { diff --git a/firmware/controllers/lua/rusefi_lua.h b/firmware/controllers/lua/rusefi_lua.h index 322b1655b2..6dc649abcd 100644 --- a/firmware/controllers/lua/rusefi_lua.h +++ b/firmware/controllers/lua/rusefi_lua.h @@ -60,7 +60,7 @@ void testLuaExecString(const char* script); void initLuaCanRx(); // Called from the Lua loop to process any pending CAN frames -void doLuaCanRx(LuaHandle& ls); +int doLuaCanRx(LuaHandle& ls); // Called from the CAN RX thread to queue a frame for Lua consumption void processLuaCan(const size_t busIndex, const CANRxFrame& frame); #endif // not EFI_CAN_SUPPORT