Files
Client/GameTools/CaldronBase/ProfileMgr.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 20:17:20 +09:00

253 lines
8.7 KiB
C++

/* *********************************************************************
* CProfileMgr
* 파일 : ProfileMgr.cpp
* 기능 :
* 작성일 : 2003.11.05
* history :
wizardbug ( 2003.11.05) :: Gem3의 Profile System을 Caldron에 맞게 변형
********************************************************************** */
#include "./ProfileMgr.h"
/***************************************************************************************************
**
** CProfileObj
**
***************************************************************************************************/
/***********************************************************************************************
* INPUT: *
* name - pointer to a static string which is the name of this profile node *
* parent - parent pointer *
* *
* WARNINGS: *
* The name is assumed to be a static pointer, only the pointer is stored and compared for *
* efficiency reasons. *
*=============================================================================================*/
Caldron::Base::CProfileObj::CProfileObj( const char * strName, CProfileObj * pParent ) :
m_strName( strName ),
m_iTotalCalls( 0 ),
m_fTotalTime( 0 ),
m_iStartTime( 0 ),
m_iRecursionCounter( 0 ),
m_pParent( pParent ),
m_pChild( NULL ),
m_pSibling( NULL )
{
Reset();
}
Caldron::Base::CProfileObj::~CProfileObj( void )
{
delete m_pChild;
delete m_pSibling;
}
/***********************************************************************************************
* INPUT: *
* name - static string pointer to the name of the node we are searching for *
* *
* WARNINGS: *
* All profile names are assumed to be static strings so this function uses pointer compares *
* to find the named node. *
*=============================================================================================*/
Caldron::Base::CProfileObj *Caldron::Base::CProfileObj::Get_Sub_Node( const char * strName )
{
// Try to find this sub node
CProfileObj * child = m_pChild;
while ( child ) {
if ( child->m_strName == strName ) {
return child;
}
child = child->m_pSibling;
}
// We didn't find it, so add it
CProfileObj * node = new CProfileObj( strName, this );
node->m_pSibling = m_pChild;
m_pChild = node;
return node;
}
void Caldron::Base::CProfileObj::Reset()
{
m_iTotalCalls = 0;
m_fTotalTime = 0.0f;
if ( m_pChild ) {
m_pChild->Reset();
}
if ( m_pSibling ) {
m_pSibling->Reset();
}
}
void Caldron::Base::CProfileObj::Call()
{
m_iTotalCalls++;
if (m_iRecursionCounter++ == 0) {
Caldron::ProfileGetTicks(&m_iStartTime);
}
}
bool Caldron::Base::CProfileObj::Return()
{
if ( --m_iRecursionCounter == 0 && m_iTotalCalls != 0 ) {
__int64 time;
Caldron::ProfileGetTicks(&time);
time -= m_iStartTime;
m_fTotalTime += (float)time / Caldron::ProfileGetTickRate();
}
return ( m_iRecursionCounter == 0 );
}
/***************************************************************************************************
**
** CProfileChecker
**
***************************************************************************************************/
Caldron::Base::CProfileChecker::CProfileChecker( CProfileObj * pStart )
{
m_pCurrentParent = pStart;
m_pCurrentChild = m_pCurrentParent->Get_Child();
}
void Caldron::Base::CProfileChecker::First(void)
{
m_pCurrentChild = m_pCurrentParent->Get_Child();
}
void Caldron::Base::CProfileChecker::Next(void)
{
m_pCurrentChild = m_pCurrentChild->Get_Sibling();
}
bool Caldron::Base::CProfileChecker::Is_Done(void)
{
return m_pCurrentChild == NULL;
}
void Caldron::Base::CProfileChecker::Enter_Child( int iIndex )
{
m_pCurrentChild = m_pCurrentParent->Get_Child();
while ( (m_pCurrentChild != NULL) && (iIndex != 0) ) {
iIndex--;
m_pCurrentChild = m_pCurrentChild->Get_Sibling();
}
if ( m_pCurrentChild != NULL ) {
m_pCurrentParent = m_pCurrentChild;
m_pCurrentChild = m_pCurrentParent->Get_Child();
}
}
void Caldron::Base::CProfileChecker::Enter_Parent( void )
{
if ( m_pCurrentParent->Get_Parent() != NULL ) {
m_pCurrentParent = m_pCurrentParent->Get_Parent();
}
m_pCurrentChild = m_pCurrentParent->Get_Child();
}
/***************************************************************************************************
**
** CProfileMgr
**
***************************************************************************************************/
Caldron::Base::CProfileObj Caldron::Base::CProfileMgr::m_Root( "Root", NULL );
Caldron::Base::CProfileObj *Caldron::Base::CProfileMgr::m_pCurrentNode = &CProfileMgr::m_Root;
int Caldron::Base::CProfileMgr::m_iFrameCounter = 0;
__int64 Caldron::Base::CProfileMgr::m_iResetTime = 0;
/***********************************************************************************************
* CProfileManager::Start_Profile -- Begin a named profile *
* *
* Steps one level deeper into the tree, if a child already exists with the specified name *
* then it accumulates the profiling; otherwise a new child node is added to the profile tree. *
* *
* INPUT: *
* name - name of this profiling record *
* *
* WARNINGS: *
* The string used is assumed to be a static string; pointer compares are used throughout *
* the profiling code for efficiency. *
*=============================================================================================*/
void Caldron::Base::CProfileMgr::StartProfile( const char * strName )
{
if (strName != m_pCurrentNode->Get_Name()) {
m_pCurrentNode = m_pCurrentNode->Get_Sub_Node( strName );
}
m_pCurrentNode->Call();
}
/***********************************************************************************************
* CProfileManager::Stop_Profile -- Stop timing and record the results. *
*=============================================================================================*/
void Caldron::Base::CProfileMgr::StopProfile( void )
{
// Return will indicate whether we should back up to our parent (we may
// be profiling a recursive function)
if (m_pCurrentNode->Return()) {
m_pCurrentNode = m_pCurrentNode->Get_Parent();
}
}
/***********************************************************************************************
* CProfileManager::Reset -- Reset the contents of the profiling system *
* *
* This resets everything except for the tree structure. All of the timing data is reset. *
*=============================================================================================*/
void Caldron::Base::CProfileMgr::Reset( void )
{
m_Root.Reset();
m_iFrameCounter = 0;
Caldron::ProfileGetTicks(&m_iResetTime);
}
/***********************************************************************************************
* CProfileManager::Increment_Frame_Counter -- Increment the frame counter *
*=============================================================================================*/
void Caldron::Base::CProfileMgr::Increment_Frame_Counter( void )
{
m_iFrameCounter++;
}
/***********************************************************************************************
* CProfileManager::Get_Time_Since_Reset -- returns the elapsed time since last reset *
*=============================================================================================*/
float Caldron::Base::CProfileMgr::Get_Time_Since_Reset( void )
{
__int64 time;
Caldron::ProfileGetTicks(&time);
time -= m_iResetTime;
return (float)time / Caldron::ProfileGetTickRate();
}