Skip to content

Commit 98b79bc

Browse files
committed
Added timing metric for plugin script execution times
1 parent 623d7db commit 98b79bc

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

plugins.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ CPlugin::CPlugin (CMUSHclientDoc * pDoc)
164164
m_bSendToScriptUsed = false;
165165
m_bGlobal = false;
166166
m_iLoadOrder = 0;
167+
m_iScriptTimeTaken = 0;
167168

168169
} // end of constructor
169170

plugins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class CPlugin :public CObject
102102
bool m_bSendToScriptUsed; // plugin sends to script
103103
bool m_bGlobal; // true if plugin was loaded from global prefs
104104
long m_iLoadOrder; // sequence in which plugins are processed
105+
LONGLONG m_iScriptTimeTaken; // time taken to execute scripts
105106

106107
// Lua note - for Lua the DISPID is a flag indicating whether or not
107108
// the routine exists. It is set to DISPID_UNKNOWN if the last call caused an error

scripting/lua_scripting.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ bool CScriptEngine::ParseLua (const CString & strCode, const CString & strWhat)
304304
{
305305
QueryPerformanceCounter (&finish);
306306
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
307+
if (m_pDoc->m_CurrentPlugin)
308+
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
307309
}
308310

309311
return false;
@@ -611,6 +613,8 @@ bool CScriptEngine::ExecuteLua (DISPID & dispid, // dispatch ID, will be set to
611613
{
612614
QueryPerformanceCounter (&finish);
613615
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
616+
if (m_pDoc->m_CurrentPlugin)
617+
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
614618
}
615619

616620
if (result)
@@ -702,6 +706,8 @@ bool CScriptEngine::ExecuteLua (DISPID & dispid, // dispatch ID, will b
702706
{
703707
QueryPerformanceCounter (&finish);
704708
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
709+
if (m_pDoc->m_CurrentPlugin)
710+
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
705711
}
706712

707713
if (lua_gettop (L) > 0 && lua_isstring (L, 1))

scripting/methods/methods_plugins.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ VARIANT CMUSHclientDoc::GetPluginInfo(LPCTSTR PluginID, short InfoType)
149149
case 22: SetUpVariantDate (vaResult, COleDateTime (pPlugin->m_tDateInstalled.GetTime ())); break;
150150
case 23: SetUpVariantString (vaResult, pPlugin->m_strCallingPluginID); break;
151151

152+
case 24:
153+
{
154+
double elapsed_time = 0.0;
155+
if (App.m_iCounterFrequency > 0)
156+
elapsed_time = ((double) pPlugin->m_iScriptTimeTaken) /
157+
((double) App.m_iCounterFrequency);
158+
159+
SetUpVariantDouble (vaResult, elapsed_time);
160+
break;
161+
}
162+
152163
default:
153164
vaResult.vt = VT_NULL;
154165
break;

scripting/scriptengine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ bool CScriptEngine::Execute (DISPID & dispid, // dispatch ID, will be set to DI
118118
{
119119
QueryPerformanceCounter (&finish);
120120
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
121+
if (m_pDoc->m_CurrentPlugin)
122+
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
121123
}
122124

123125
// put status line back
@@ -462,6 +464,8 @@ SCRIPTSTATE ss;
462464
{
463465
QueryPerformanceCounter (&finish);
464466
m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
467+
if (m_pDoc->m_CurrentPlugin)
468+
m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart;
465469
}
466470

467471
::SysFreeString (bstrCode);

world_debug.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,13 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command)
12921292
else
12931293
strLanguage.SetAt (0, toupper (strLanguage [0]));
12941294

1295-
ColourTell (strColour, "", TFormat ("', (%s) %s",
1296-
(LPCSTR) strLanguage, pActive));
1295+
double elapsed_time = 0.0;
1296+
if (App.m_iCounterFrequency > 0)
1297+
elapsed_time = ((double) pPlugin->m_iScriptTimeTaken) /
1298+
((double) App.m_iCounterFrequency);
1299+
1300+
ColourTell (strColour, "", TFormat ("', (%s, %0.3f s) %s",
1301+
(LPCSTR) strLanguage, elapsed_time, pActive));
12971302

12981303
// no quick way of finding variables count
12991304
int nTotalVariables = 0;

0 commit comments

Comments
 (0)