From b47c18518fdc7ce2b5be6d229cb250b0c33b26b8 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 20 Jul 2012 21:57:44 +0000 Subject: [PATCH] Lunatic: time every event and actor call and print summary at game exit. git-svn-id: https://svn.eduke32.com/eduke32@2842 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/baselayer.h | 1 + polymer/eduke32/source/game.c | 3 +++ polymer/eduke32/source/gameexec.c | 16 +++++++++++++++ polymer/eduke32/source/lunatic/defs.ilua | 5 +++-- polymer/eduke32/source/lunatic/lunatic.c | 25 +++++++++++++++++++++++ polymer/eduke32/source/lunatic/lunatic.h | 5 +++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index f908814a0..9d2ed091d 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -144,6 +144,7 @@ uint32_t getticks(void); int32_t gettimerfreq(void); uint64_t gethiticks(void); uint64_t gethitickspersec(void); +double gethitickms(void); // TODO: Windows void (*installusertimercallback(void (*callback)(void)))(void); int32_t checkvideomode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 95fb2130f..75b900ac2 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -2086,6 +2086,9 @@ extern int32_t g_doQuickSave; void G_GameExit(const char *msg) { +#ifdef LUNATIC + El_PrintTimes(); +#endif if (*msg != 0) g_player[myconnectindex].ps->palette = BASEPAL; if (ud.recstat == 1) G_CloseDemoWrite(); diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 4d4db0a9d..22f813656 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -97,6 +97,8 @@ void VM_ScriptInfo(void) int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) { #ifdef LUNATIC + const double t = gethitickms(); + if (El_IsInitialized(&g_ElState) && El_HaveEvent(iEventID)) El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist); #endif @@ -140,6 +142,10 @@ int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lD iReturn = aGameVars[g_iReturnVarID].val.lValue; aGameVars[g_iReturnVarID].val.lValue = backupReturnVar; +#ifdef LUNATIC + g_eventTotalMs[iEventID] += gethitickms()-t; + g_eventCalls[iEventID]++; +#endif return iReturn; } } @@ -5025,6 +5031,9 @@ void A_LoadActor(int32_t iActor) // NORECURSE void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) { +#ifdef LUNATIC + double t; +#endif vmstate_t tempvm = { iActor, iPlayer, lDist, &actor[iActor].t_data[0], &sprite[iActor], 0 }; @@ -5083,6 +5092,8 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) } #ifdef LUNATIC + t = gethitickms(); + if (El_IsInitialized(&g_ElState) && El_HaveActor(vm.g_sp->picnum)) El_CallActor(&g_ElState, vm.g_sp->picnum, iActor, iPlayer, lDist); #endif @@ -5091,6 +5102,11 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) VM_Execute(1); insptr = NULL; +#ifdef LUNATIC + g_actorTotalMs[vm.g_sp->picnum] += gethitickms()-t; + g_actorCalls[vm.g_sp->picnum]++; +#endif + if (vm.g_flags & VM_KILL) { // if player was set to squish, first stop that... diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 8aa82315a..97f126a98 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -90,7 +90,8 @@ local gv_ = { local dummy_empty_table = {} --- this is for declarations of arrays or pointers +-- This is for declarations of arrays or pointers which should not be +-- accessible through the gv global. -- NOTE: don't declare multiple pointers on one line (like int32_t *a, *b;)! local function decl(str) for varname in string.gmatch(str, "([%a_][%w_]*)[[(;]") do @@ -806,7 +807,7 @@ local tmpmt = { } oG.setmetatable(wall, tmpmt) --- create a safe indirection for a ffi.C array +-- create a safe indirection for an ffi.C array local function creategtab(ctab, maxidx, name) local tab = {} local tmpmt = { diff --git a/polymer/eduke32/source/lunatic/lunatic.c b/polymer/eduke32/source/lunatic/lunatic.c index 427395b5e..e6fa6e29f 100644 --- a/polymer/eduke32/source/lunatic/lunatic.c +++ b/polymer/eduke32/source/lunatic/lunatic.c @@ -23,6 +23,10 @@ uint8_t g_elActors[MAXTILES]; // Lua-registry key for debug.traceback static uint8_t debug_traceback_key; +// for timing events and actors +uint32_t g_eventCalls[MAXEVENTS], g_actorCalls[MAXTILES]; +double g_eventTotalMs[MAXEVENTS], g_actorTotalMs[MAXTILES]; + // forward-decls... static int32_t SetEvent_luacf(lua_State *L); @@ -31,6 +35,27 @@ static int32_t SetActor_luacf(lua_State *L); // in lpeg.o extern int luaopen_lpeg(lua_State *L); +void El_PrintTimes(void) +{ + int32_t i; + + OSD_Printf("{\n {\n"); + OSD_Printf(" -- event times, [event]={ total calls, total time in ms, time per call in us }\n"); + for (i=0; i