sm_dump_handles now shows memory usage
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401772
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include "Logger.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "sm_stringutil.h"
|
||||
|
||||
HandleSystem g_HandleSys;
|
||||
|
||||
@@ -996,8 +997,9 @@ bool HandleSystem::TryAndFreeSomeHandles()
|
||||
|
||||
void HandleSystem::Dump(HANDLE_REPORTER rep)
|
||||
{
|
||||
rep("%-10.10s\t%-20.20s\t%-20.20s", "Handle", "Owner", "Type");
|
||||
rep("---------------------------------------------");
|
||||
unsigned int total_size = 0;
|
||||
rep("%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
|
||||
rep("--------------------------------------------------------------------------");
|
||||
for (unsigned int i = 1; i <= m_HandleTail; i++)
|
||||
{
|
||||
if (m_Handles[i].set != HandleSet_Used)
|
||||
@@ -1042,11 +1044,24 @@ void HandleSystem::Dump(HANDLE_REPORTER rep)
|
||||
}
|
||||
const char *type = "ANON";
|
||||
QHandleType *pType = &m_Types[m_Handles[i].type];
|
||||
unsigned int size = 0;
|
||||
if (pType->nameIdx != -1)
|
||||
{
|
||||
type = m_strtab->GetString(pType->nameIdx);
|
||||
}
|
||||
rep("0x%08x\t%-20.20s\t%-20.20s", index, owner, type);
|
||||
if (pType->dispatch->GetDispatchVersion() < HANDLESYS_MEMUSAGE_MIN_VERSION
|
||||
|| !pType->dispatch->GetHandleApproxSize(m_Handles[i].type, m_Handles[i].object, &size))
|
||||
{
|
||||
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
|
||||
}
|
||||
else
|
||||
{
|
||||
char buffer[32];
|
||||
UTIL_Format(buffer, sizeof(buffer), "%d", size);
|
||||
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
|
||||
total_size += size;
|
||||
}
|
||||
}
|
||||
rep("-- Approximately %d bytes of memory are in use by Handles.\n", total_size);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@
|
||||
#define HANDLESYS_SERIAL_MASK 0xFFFF0000
|
||||
#define HANDLESYS_HANDLE_MASK 0x0000FFFF
|
||||
|
||||
#define HANDLESYS_MEMUSAGE_MIN_VERSION 3
|
||||
|
||||
/**
|
||||
* The QHandle is a nasty structure that compacts the handle system into a big vector.
|
||||
* The members of the vector each encapsulate one Handle, however, they also act as nodes
|
||||
|
||||
@@ -123,6 +123,80 @@ void CPlugin::InitIdentity()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int CPlugin::CalcMemUsage()
|
||||
{
|
||||
unsigned int base_size =
|
||||
sizeof(CPlugin)
|
||||
+ sizeof(IdentityToken_t)
|
||||
+ (m_PhraseFiles.size() * sizeof(unsigned int))
|
||||
+ (m_dependents.size() * sizeof(CPlugin *))
|
||||
+ (m_dependsOn.size() * sizeof(CPlugin *))
|
||||
+ (m_fakeNatives.size() * (sizeof(FakeNative *) + sizeof(FakeNative)))
|
||||
+ (m_WeakNatives.size() * sizeof(WeakNative))
|
||||
+ (m_configs.size() * (sizeof(AutoConfig *) + sizeof(AutoConfig)))
|
||||
+ sm_trie_mem_usage(m_pProps);
|
||||
|
||||
for (unsigned int i = 0; i < m_configs.size(); i++)
|
||||
{
|
||||
base_size += m_configs[i]->autocfg.size();
|
||||
base_size += m_configs[i]->folder.size();
|
||||
}
|
||||
|
||||
for (List<String>::iterator i = m_Libraries.begin();
|
||||
i != m_Libraries.end();
|
||||
i++)
|
||||
{
|
||||
base_size += (*i).size();
|
||||
}
|
||||
|
||||
for (List<String>::iterator i = m_RequiredLibs.begin();
|
||||
i != m_RequiredLibs.end();
|
||||
i++)
|
||||
{
|
||||
base_size += (*i).size();
|
||||
}
|
||||
|
||||
for (List<FakeNative *>::iterator i = m_fakeNatives.begin();
|
||||
i != m_fakeNatives.end();
|
||||
i++)
|
||||
{
|
||||
base_size += (*i)->name.size();
|
||||
}
|
||||
|
||||
if (m_plugin != NULL)
|
||||
{
|
||||
base_size += sizeof(sp_plugin_t);
|
||||
base_size += m_plugin->data_size;
|
||||
base_size += m_plugin->pcode_size;
|
||||
base_size += (m_plugin->info.natives_num * sizeof(sp_file_natives_t));
|
||||
base_size += (m_plugin->info.publics_num * sizeof(sp_file_publics_t));
|
||||
base_size += (m_plugin->info.pubvars_num * sizeof(sp_file_pubvars_t));
|
||||
base_size += (m_plugin->debug.files_num * sizeof(sp_fdbg_file_t));
|
||||
base_size += (m_plugin->debug.lines_num * sizeof(sp_fdbg_line_t));
|
||||
base_size += (m_plugin->debug.syms_num * sizeof(sp_fdbg_symbol_t));
|
||||
/* We can't get strtab size, oh well. */
|
||||
}
|
||||
|
||||
if (m_ctx.base != NULL)
|
||||
{
|
||||
base_size += sizeof(BaseContext);
|
||||
base_size += m_ctx.base->GetPublicsNum() * sizeof(CFunction);
|
||||
}
|
||||
if (m_ctx.ctx != NULL)
|
||||
{
|
||||
base_size += m_ctx.ctx->mem_size;
|
||||
base_size += (m_plugin->debug.files_num * sizeof(sp_debug_file_t));
|
||||
base_size += (m_plugin->debug.lines_num * sizeof(sp_debug_line_t));
|
||||
base_size += (m_plugin->debug.syms_num * sizeof(sp_debug_symbol_t));
|
||||
base_size += (m_plugin->info.pubvars_num * sizeof(sp_pubvar_t));
|
||||
base_size += (m_plugin->info.publics_num * sizeof(sp_public_t));
|
||||
base_size += (m_plugin->info.natives_num * sizeof(sp_native_t));
|
||||
/* We also don't know the JIT code size, oh well. */
|
||||
}
|
||||
|
||||
return base_size;
|
||||
}
|
||||
|
||||
Handle_t CPlugin::GetMyHandle()
|
||||
{
|
||||
return m_handle;
|
||||
@@ -1969,6 +2043,12 @@ void CPluginManager::OnHandleDestroy(HandleType_t type, void *object)
|
||||
/* We don't care about the internal object, actually */
|
||||
}
|
||||
|
||||
bool CPluginManager::GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
|
||||
{
|
||||
*pSize = ((CPlugin *)object)->CalcMemUsage();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPluginManager::RegisterNativesFromCore(sp_nativeinfo_t *natives)
|
||||
{
|
||||
for (unsigned int i = 0; natives[i].func != NULL; i++)
|
||||
|
||||
@@ -169,6 +169,7 @@ public:
|
||||
unsigned int GetSerial();
|
||||
const sp_plugin_t *GetPluginStructure();
|
||||
IdentityToken_t *GetIdentity();
|
||||
unsigned int CalcMemUsage();
|
||||
bool SetProperty(const char *prop, void *ptr);
|
||||
bool GetProperty(const char *prop, void **ptr, bool remove=false);
|
||||
public:
|
||||
@@ -355,6 +356,7 @@ public: //SMGlobalClass
|
||||
void OnSourceModShutdown();
|
||||
public: //IHandleTypeDispatch
|
||||
void OnHandleDestroy(HandleType_t type, void *object);
|
||||
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
||||
public: //IRootConsoleCommand
|
||||
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user