Skip to content

Commit

Permalink
Added timing metric for plugin script execution times
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Nov 16, 2010
1 parent 623d7db commit 98b79bc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugins.cpp
Expand Up @@ -164,6 +164,7 @@ CPlugin::CPlugin (CMUSHclientDoc * pDoc)
m_bSendToScriptUsed = false;
m_bGlobal = false;
m_iLoadOrder = 0;
m_iScriptTimeTaken = 0;

} // end of constructor

Expand Down
1 change: 1 addition & 0 deletions plugins.h
Expand Up @@ -102,6 +102,7 @@ class CPlugin :public CObject
bool m_bSendToScriptUsed; // plugin sends to script
bool m_bGlobal; // true if plugin was loaded from global prefs
long m_iLoadOrder; // sequence in which plugins are processed
LONGLONG m_iScriptTimeTaken; // time taken to execute scripts

// Lua note - for Lua the DISPID is a flag indicating whether or not
// the routine exists. It is set to DISPID_UNKNOWN if the last call caused an error
Expand Down
6 changes: 6 additions & 0 deletions scripting/lua_scripting.cpp
Expand Up @@ -304,6 +304,8 @@ bool CScriptEngine::ParseLua (const CString & strCode, const CString & strWhat)
{
QueryPerformanceCounter (&finish);
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
if (m_pDoc->m_CurrentPlugin)
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
}

return false;
Expand Down Expand Up @@ -611,6 +613,8 @@ bool CScriptEngine::ExecuteLua (DISPID & dispid, // dispatch ID, will be set to
{
QueryPerformanceCounter (&finish);
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
if (m_pDoc->m_CurrentPlugin)
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
}

if (result)
Expand Down Expand Up @@ -702,6 +706,8 @@ bool CScriptEngine::ExecuteLua (DISPID & dispid, // dispatch ID, will b
{
QueryPerformanceCounter (&finish);
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
if (m_pDoc->m_CurrentPlugin)
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
}

if (lua_gettop (L) > 0 && lua_isstring (L, 1))
Expand Down
11 changes: 11 additions & 0 deletions scripting/methods/methods_plugins.cpp
Expand Up @@ -149,6 +149,17 @@ VARIANT CMUSHclientDoc::GetPluginInfo(LPCTSTR PluginID, short InfoType)
case 22: SetUpVariantDate (vaResult, COleDateTime (pPlugin->m_tDateInstalled.GetTime ())); break;
case 23: SetUpVariantString (vaResult, pPlugin->m_strCallingPluginID); break;

case 24:
{
double elapsed_time = 0.0;
if (App.m_iCounterFrequency > 0)
elapsed_time = ((double) pPlugin->m_iScriptTimeTaken) /
((double) App.m_iCounterFrequency);

SetUpVariantDouble (vaResult, elapsed_time);
break;
}

default:
vaResult.vt = VT_NULL;
break;
Expand Down
4 changes: 4 additions & 0 deletions scripting/scriptengine.cpp
Expand Up @@ -118,6 +118,8 @@ bool CScriptEngine::Execute (DISPID & dispid, // dispatch ID, will be set to DI
{
QueryPerformanceCounter (&finish);
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
if (m_pDoc->m_CurrentPlugin)
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
}

// put status line back
Expand Down Expand Up @@ -462,6 +464,8 @@ SCRIPTSTATE ss;
{
QueryPerformanceCounter (&finish);
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
if (m_pDoc->m_CurrentPlugin)
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
}

::SysFreeString (bstrCode);
Expand Down
9 changes: 7 additions & 2 deletions world_debug.cpp
Expand Up @@ -1292,8 +1292,13 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command)
else
strLanguage.SetAt (0, toupper (strLanguage [0]));

ColourTell (strColour, "", TFormat ("', (%s) %s",
(LPCSTR) strLanguage, pActive));
double elapsed_time = 0.0;
if (App.m_iCounterFrequency > 0)
elapsed_time = ((double) pPlugin->m_iScriptTimeTaken) /
((double) App.m_iCounterFrequency);

ColourTell (strColour, "", TFormat ("', (%s, %0.3f s) %s",
(LPCSTR) strLanguage, elapsed_time, pActive));

// no quick way of finding variables count
int nTotalVariables = 0;
Expand Down

0 comments on commit 98b79bc

Please sign in to comment.