mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 20:16:10 +08:00
Add VProfScopeHelper and update VPROF_* macros (#235)
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Real-Time Hierarchical Profiling
|
||||
//
|
||||
@ -14,11 +14,9 @@
|
||||
#include "tier0/threadtools.h"
|
||||
|
||||
// VProf is enabled by default in all configurations -except- X360 Retail.
|
||||
#ifndef _LINUX
|
||||
#if !( defined( _X360 ) && defined( _CERT ) )
|
||||
#define VPROF_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_X360) && defined(VPROF_ENABLED)
|
||||
#include "tier0/pmc360.h"
|
||||
@ -147,28 +145,28 @@
|
||||
#define VPROF_LEVEL 0
|
||||
#endif
|
||||
|
||||
#define VPROF_0(name,group,assertAccounted,budgetFlags) CVProfScope VProf_(name, 0, group, assertAccounted, budgetFlags);
|
||||
#define VPROF_0(name,group,assertAccounted,budgetFlags) VProfScopeHelper<0, assertAccounted> vprofHelper_(name, group, budgetFlags);
|
||||
|
||||
#if VPROF_LEVEL > 0
|
||||
#define VPROF_1(name,group,assertAccounted,budgetFlags) CVProfScope VProf_(name, 1, group, assertAccounted, budgetFlags);
|
||||
#define VPROF_1(name,group,assertAccounted,budgetFlags) VProfScopeHelper<1, assertAccounted> vprofHelper_(name, group, budgetFlags);
|
||||
#else
|
||||
#define VPROF_1(name,group,assertAccounted,budgetFlags) ((void)0)
|
||||
#endif
|
||||
|
||||
#if VPROF_LEVEL > 1
|
||||
#define VPROF_2(name,group,assertAccounted,budgetFlags) CVProfScope VProf_(name, 2, group, assertAccounted, budgetFlags);
|
||||
#define VPROF_2(name,group,assertAccounted,budgetFlags) VProfScopeHelper<2, assertAccounted> vprofHelper_(name, group, budgetFlags);
|
||||
#else
|
||||
#define VPROF_2(name,group,assertAccounted,budgetFlags) ((void)0)
|
||||
#endif
|
||||
|
||||
#if VPROF_LEVEL > 2
|
||||
#define VPROF_3(name,group,assertAccounted,budgetFlags) CVProfScope VProf_(name, 3, group, assertAccounted, budgetFlags);
|
||||
#define VPROF_3(name,group,assertAccounted,budgetFlags) VProfScopeHelper<3, assertAccounted> vprofHelper_(name, group, budgetFlags);
|
||||
#else
|
||||
#define VPROF_3(name,group,assertAccounted,budgetFlags) ((void)0)
|
||||
#endif
|
||||
|
||||
#if VPROF_LEVEL > 3
|
||||
#define VPROF_4(name,group,assertAccounted,budgetFlags) CVProfScope VProf_(name, 4, group, assertAccounted, budgetFlags);
|
||||
#define VPROF_4(name,group,assertAccounted,budgetFlags) VProfScopeHelper<4, assertAccounted> vprofHelper_(name, group, budgetFlags);
|
||||
#else
|
||||
#define VPROF_4(name,group,assertAccounted,budgetFlags) ((void)0)
|
||||
#endif
|
||||
@ -735,11 +733,60 @@ inline void CVProfile::PopGroup( void )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class CVProfScope
|
||||
typedef void (*VProfExitScopeCB)();
|
||||
|
||||
struct VProfBudgetGroupCallSite
|
||||
{
|
||||
VProfBudgetGroupCallSite( const char *group_name, int flags, int group_id = VPROF_BUDGET_GROUP_ID_UNACCOUNTED ) :
|
||||
m_pGroupName( group_name ), m_nFlags( flags ), m_nGroupId( group_id ) { }
|
||||
|
||||
const char *m_pGroupName;
|
||||
int m_nFlags;
|
||||
int m_nGroupId;
|
||||
};
|
||||
|
||||
template <int DETAIL_LEVEL, bool ASSERT_ACCOUNTED>
|
||||
class VProfScopeHelper
|
||||
{
|
||||
public:
|
||||
CVProfScope( const tchar * pszName, int detailLevel, const tchar *pBudgetGroupName, bool bAssertAccounted, int budgetFlags );
|
||||
~CVProfScope();
|
||||
VProfScopeHelper( const char *pszName )
|
||||
{
|
||||
m_pExitScope = EnterScopeInternal( pszName );
|
||||
}
|
||||
|
||||
VProfScopeHelper( const char *pszName, const char *pszGroupName, int nFlags )
|
||||
{
|
||||
VProfBudgetGroupCallSite budget_group( pszGroupName, nFlags );
|
||||
m_pExitScope = EnterScopeInternalBudgetFlags( pszName, budget_group );
|
||||
}
|
||||
|
||||
VProfScopeHelper( VProfScopeHelper &other )
|
||||
{
|
||||
m_pExitScope = other.m_pExitScope;
|
||||
}
|
||||
|
||||
~VProfScopeHelper()
|
||||
{
|
||||
ExitScope();
|
||||
}
|
||||
|
||||
void ExitScope()
|
||||
{
|
||||
if(!m_pExitScope)
|
||||
return;
|
||||
|
||||
m_pExitScope();
|
||||
m_pExitScope = nullptr;
|
||||
}
|
||||
|
||||
DLL_CLASS_IMPORT VProfScopeHelper &operator=( const VProfScopeHelper &other );
|
||||
DLL_CLASS_IMPORT VProfScopeHelper &operator=( VProfScopeHelper &&other );
|
||||
|
||||
static DLL_CLASS_IMPORT VProfExitScopeCB EnterScopeInternal( const char *pszName );
|
||||
static DLL_CLASS_IMPORT VProfExitScopeCB EnterScopeInternalBudgetFlags( const char *pszName, VProfBudgetGroupCallSite &budgetGroup );
|
||||
|
||||
private:
|
||||
VProfExitScopeCB m_pExitScope = nullptr;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1247,17 +1294,6 @@ inline unsigned int CVProfile::GetMultiTraceIndex()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline CVProfScope::CVProfScope( const tchar * pszName, int detailLevel, const tchar *pBudgetGroupName, bool bAssertAccounted, int budgetFlags )
|
||||
{
|
||||
g_VProfCurrentProfile.EnterScope( pszName, detailLevel, pBudgetGroupName, bAssertAccounted, budgetFlags );
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
inline CVProfScope::~CVProfScope()
|
||||
{
|
||||
g_VProfCurrentProfile.ExitScope();
|
||||
}
|
||||
|
||||
class CVProfCounter
|
||||
{
|
||||
|
Reference in New Issue
Block a user