core/systems/HandleSys.cpp
changeset 1766 d30c252089be
parent 1687 47cc645edce6
child 1947 e73a1e51833b
     1.1 --- a/core/systems/HandleSys.cpp	Wed Dec 05 15:38:45 2007 +0000
     1.2 +++ b/core/systems/HandleSys.cpp	Wed Dec 05 18:07:18 2007 +0000
     1.3 @@ -36,6 +36,7 @@
     1.4  #include "Logger.h"
     1.5  #include <assert.h>
     1.6  #include <string.h>
     1.7 +#include "sm_stringutil.h"
     1.8  
     1.9  HandleSystem g_HandleSys;
    1.10  
    1.11 @@ -996,8 +997,9 @@
    1.12  
    1.13  void HandleSystem::Dump(HANDLE_REPORTER rep)
    1.14  {
    1.15 -	rep("%-10.10s\t%-20.20s\t%-20.20s", "Handle", "Owner", "Type");
    1.16 -	rep("---------------------------------------------");
    1.17 +	unsigned int total_size = 0;
    1.18 +	rep("%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
    1.19 +	rep("--------------------------------------------------------------------------");
    1.20  	for (unsigned int i = 1; i <= m_HandleTail; i++)
    1.21  	{
    1.22  		if (m_Handles[i].set != HandleSet_Used)
    1.23 @@ -1042,11 +1044,24 @@
    1.24  		}
    1.25  		const char *type = "ANON";
    1.26  		QHandleType *pType = &m_Types[m_Handles[i].type];
    1.27 +		unsigned int size = 0;
    1.28  		if (pType->nameIdx != -1)
    1.29  		{
    1.30  			type = m_strtab->GetString(pType->nameIdx);
    1.31  		}
    1.32 -		rep("0x%08x\t%-20.20s\t%-20.20s", index, owner, type);
    1.33 +		if (pType->dispatch->GetDispatchVersion() < HANDLESYS_MEMUSAGE_MIN_VERSION
    1.34 +			|| !pType->dispatch->GetHandleApproxSize(m_Handles[i].type, m_Handles[i].object, &size))
    1.35 +		{
    1.36 +			rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
    1.37 +		}
    1.38 +		else
    1.39 +		{
    1.40 +			char buffer[32];
    1.41 +			UTIL_Format(buffer, sizeof(buffer), "%d", size);
    1.42 +			rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
    1.43 +			total_size += size;
    1.44 +		}
    1.45  	}
    1.46 +	rep("-- Approximately %d bytes of memory are in use by Handles.\n", total_size);
    1.47  }
    1.48