added amb256 - (nice number), profiler complete with gui to show files
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401914
This commit is contained in:
@@ -61,6 +61,12 @@ BaseContext::BaseContext(sp_context_t *_ctx)
|
||||
ctx = _ctx;
|
||||
ctx->context = this;
|
||||
ctx->dbreak = GlobalDebugBreak;
|
||||
|
||||
if (ctx->prof_flags != 0)
|
||||
{
|
||||
ctx->profiler = sm_profiler;
|
||||
}
|
||||
|
||||
m_InExec = false;
|
||||
m_CustomMsg = false;
|
||||
m_funcsnum = ctx->vmbase->FunctionCount(ctx);
|
||||
@@ -150,7 +156,7 @@ void BaseContext::RefreshFunctionCache()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
m_pub_funcs[i]->Set(pub->code_offs, this, pub->funcid);
|
||||
m_pub_funcs[i]->Set(pub->code_offs, this, pub->funcid, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +192,16 @@ void BaseContext::SetContext(sp_context_t *_ctx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = _ctx;
|
||||
ctx->context = this;
|
||||
ctx->dbreak = GlobalDebugBreak;
|
||||
|
||||
if (ctx->prof_flags != 0)
|
||||
{
|
||||
ctx->profiler = sm_profiler;
|
||||
}
|
||||
|
||||
RefreshFunctionCache();
|
||||
}
|
||||
|
||||
@@ -992,10 +1005,18 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
|
||||
pFunc = m_pub_funcs[func_id];
|
||||
if (!pFunc)
|
||||
{
|
||||
m_pub_funcs[func_id] = new CFunction(ctx->publics[func_id].code_offs, this, ctx->publics[func_id].funcid);
|
||||
m_pub_funcs[func_id] = new CFunction(ctx->publics[func_id].code_offs,
|
||||
this,
|
||||
ctx->publics[func_id].funcid,
|
||||
func_id);
|
||||
pFunc = m_pub_funcs[func_id];
|
||||
} else if (pFunc->IsInvalidated()) {
|
||||
pFunc->Set(ctx->publics[func_id].code_offs, this, ctx->publics[func_id].funcid);
|
||||
}
|
||||
else if (pFunc->IsInvalidated())
|
||||
{
|
||||
pFunc->Set(ctx->publics[func_id].code_offs,
|
||||
this,
|
||||
ctx->publics[func_id].funcid,
|
||||
func_id);
|
||||
}
|
||||
} else {
|
||||
/* :TODO: currently not used */
|
||||
@@ -1034,16 +1055,20 @@ IPluginFunction *BaseContext::GetFunctionByName(const char *public_name)
|
||||
GetPublicByIndex(index, &pub);
|
||||
if (pub)
|
||||
{
|
||||
m_pub_funcs[index] = new CFunction(pub->code_offs, this, pub->funcid);
|
||||
m_pub_funcs[index] = new CFunction(pub->code_offs, this, pub->funcid, index);
|
||||
}
|
||||
pFunc = m_pub_funcs[index];
|
||||
} else if (pFunc->IsInvalidated()) {
|
||||
}
|
||||
else if (pFunc->IsInvalidated())
|
||||
{
|
||||
sp_public_t *pub = NULL;
|
||||
GetPublicByIndex(index, &pub);
|
||||
if (pub)
|
||||
{
|
||||
pFunc->Set(pub->code_offs, this, pub->funcid);
|
||||
} else {
|
||||
pFunc->Set(pub->code_offs, this, pub->funcid, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFunc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
* :TODO: Make functions allocate as a lump instead of individual allocations!
|
||||
*/
|
||||
|
||||
extern IProfiler *sm_profiler;
|
||||
|
||||
namespace SourcePawn
|
||||
{
|
||||
class BaseContext :
|
||||
|
||||
@@ -32,12 +32,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "sp_vm_function.h"
|
||||
#include "sm_stringutil.h"
|
||||
|
||||
/********************
|
||||
* FUNCTION CALLING *
|
||||
********************/
|
||||
|
||||
void CFunction::Set(uint32_t code_addr, IPluginContext *plugin, funcid_t id)
|
||||
void CFunction::Set(uint32_t code_addr, IPluginContext *plugin, funcid_t id, uint32_t pub_id)
|
||||
{
|
||||
m_codeaddr = code_addr;
|
||||
m_pContext = plugin;
|
||||
@@ -46,6 +47,8 @@ void CFunction::Set(uint32_t code_addr, IPluginContext *plugin, funcid_t id)
|
||||
m_Invalid = false;
|
||||
m_pCtx = plugin ? plugin->GetContext() : NULL;
|
||||
m_FnId = id;
|
||||
|
||||
m_pContext->GetPublicByIndex(pub_id, &m_pPublic);
|
||||
}
|
||||
|
||||
bool CFunction::IsRunnable()
|
||||
@@ -55,17 +58,33 @@ bool CFunction::IsRunnable()
|
||||
|
||||
int CFunction::CallFunction(const cell_t *params, unsigned int num_params, cell_t *result)
|
||||
{
|
||||
int ir, serial;
|
||||
|
||||
if (!IsRunnable())
|
||||
{
|
||||
return SP_ERROR_NOT_RUNNABLE;
|
||||
}
|
||||
|
||||
if ((m_pCtx->prof_flags & SP_PROF_CALLBACKS) == SP_PROF_CALLBACKS
|
||||
&& m_pPublic != NULL)
|
||||
{
|
||||
serial = m_pCtx->profiler->OnCallbackBegin(m_pContext, m_pPublic);
|
||||
}
|
||||
|
||||
while (num_params--)
|
||||
{
|
||||
m_pContext->PushCell(params[num_params]);
|
||||
}
|
||||
|
||||
return m_pContext->Execute(m_codeaddr, result);
|
||||
ir = m_pContext->Execute(m_codeaddr, result);
|
||||
|
||||
if ((m_pCtx->prof_flags & SP_PROF_CALLBACKS) == SP_PROF_CALLBACKS
|
||||
&& m_pPublic != NULL)
|
||||
{
|
||||
m_pCtx->profiler->OnCallbackEnd(serial);
|
||||
}
|
||||
|
||||
return ir;
|
||||
}
|
||||
|
||||
IPluginContext *CFunction::GetParentContext()
|
||||
@@ -73,7 +92,7 @@ IPluginContext *CFunction::GetParentContext()
|
||||
return m_pContext;
|
||||
}
|
||||
|
||||
CFunction::CFunction(uint32_t code_addr, IPluginContext *plugin, funcid_t id) :
|
||||
CFunction::CFunction(uint32_t code_addr, IPluginContext *plugin, funcid_t id, uint32_t pub_id) :
|
||||
m_codeaddr(code_addr), m_pContext(plugin), m_curparam(0),
|
||||
m_errorstate(SP_ERROR_NONE), m_FnId(id)
|
||||
{
|
||||
@@ -82,6 +101,7 @@ CFunction::CFunction(uint32_t code_addr, IPluginContext *plugin, funcid_t id) :
|
||||
{
|
||||
m_pCtx = plugin->GetContext();
|
||||
}
|
||||
m_pContext->GetPublicByIndex(pub_id, &m_pPublic);
|
||||
}
|
||||
|
||||
int CFunction::PushCell(cell_t cell)
|
||||
@@ -319,3 +339,4 @@ funcid_t CFunction::GetFunctionID()
|
||||
{
|
||||
return m_FnId;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,10 @@ class CFunction : public IPluginFunction
|
||||
{
|
||||
friend class SourcePawnEngine;
|
||||
public:
|
||||
CFunction(uint32_t code_addr, IPluginContext *pContext, funcid_t fnid);
|
||||
CFunction(uint32_t code_addr,
|
||||
IPluginContext *pContext,
|
||||
funcid_t fnid,
|
||||
uint32_t pub_id);
|
||||
public:
|
||||
virtual int PushCell(cell_t cell);
|
||||
virtual int PushCellByRef(cell_t *cell, int flags);
|
||||
@@ -79,7 +82,7 @@ public:
|
||||
bool IsRunnable();
|
||||
funcid_t GetFunctionID();
|
||||
public:
|
||||
void Set(uint32_t code_addr, IPluginContext *plugin, funcid_t fnid);
|
||||
void Set(uint32_t code_addr, IPluginContext *plugin, funcid_t fnid, uint32_t pub_id);
|
||||
private:
|
||||
int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
|
||||
inline int SetError(int err)
|
||||
@@ -98,6 +101,7 @@ private:
|
||||
CFunction *m_pNext;
|
||||
bool m_Invalid;
|
||||
funcid_t m_FnId;
|
||||
sp_public_t *m_pPublic;
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_
|
||||
|
||||
Reference in New Issue
Block a user