📄 vmhighperfcounter.cpp
字号:
}
/* End of function "VMGetHighPerfCounterTickCount"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetHighPerfCounterTicksPerSecond
DESCRIPTION: Get the number of processor ticks per second.
Note: On the first call, this function can execute for up
to 100 milliseconds
INPUT: void
OUTPUT: none
RETURNS: LARGE_INTEGER for the number of ticks per second
*/
LARGE_INTEGER VMGetHighPerfCounterTicksPerSecond( void )
{
LARGE_INTEGER xQuotientOne;
LARGE_INTEGER xQuotientTwo;
LARGE_INTEGER xRemainderOne;
LARGE_INTEGER xRemainderTwo;
LARGE_INTEGER xFrequency;
LARGE_INTEGER xQuotientTotal;
LARGE_INTEGER xQuotientDifference;
LARGE_INTEGER xRemainderTotal;
LARGE_INTEGER xRemainderDifference;
LARGE_INTEGER xValue;
if ( m_VMHPCTicksPerSecond.LowPart != 0 || m_VMHPCTicksPerSecond.HighPart != 0 )
{
return( m_VMHPCTicksPerSecond );
}
HANDLE hThreadID = GetCurrentThread();
int iPriority = GetThreadPriority( hThreadID );
SetThreadPriority( hThreadID, THREAD_PRIORITY_TIME_CRITICAL );
QueryPerformanceCounter( &xQuotientOne );
xRemainderOne = VMGetHighPerfCounterTickCount();
Sleep( 100 );
xRemainderTwo = VMGetHighPerfCounterTickCount();
QueryPerformanceCounter( &xQuotientTwo );
SetThreadPriority( hThreadID, iPriority );
xQuotientTotal = VMLargeIntSubtract( xQuotientTwo, xQuotientOne );
xRemainderTotal = VMLargeIntSubtract( xRemainderTwo, xRemainderOne );
QueryPerformanceCounter( &xQuotientOne );
xRemainderOne = VMGetHighPerfCounterTickCount();
xRemainderTwo = VMGetHighPerfCounterTickCount();
QueryPerformanceCounter( &xQuotientTwo );
xQuotientDifference = VMLargeIntSubtract( xQuotientTwo, xQuotientOne );
xRemainderDifference = VMLargeIntSubtract( xRemainderTwo, xRemainderOne );
xQuotientTotal = VMLargeIntSubtract( xQuotientTotal, xQuotientDifference );
xRemainderTotal = VMLargeIntSubtract( xRemainderTotal, xRemainderDifference );
QueryPerformanceFrequency( &xFrequency );
xValue = VMLargeIntMultiply( xRemainderTotal.LowPart, xFrequency.LowPart );
m_VMHPCTicksPerSecond = VMLargeIntDivide( xValue, xQuotientTotal );
return( m_VMHPCTicksPerSecond );
}
/* End of function "VMGetHighPerfCounterTicksPerSecond"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetHighPerfCounterTimer
DESCRIPTION: Get a processor timeup timer for the given time
(HPC time constant).
INPUT: eHPCTime - the time constant to add to now
OUTPUT: none
RETURNS: LARGE_INTEGER - a value that represents an offset from now
for the given constant time
*/
LARGE_INTEGER VMGetHighPerfCounterTimer( VMHPCTIME eHPCTime )
{
if ( !m_VMHPCInited )
{
VMHighPerfCounterInit();
}
return( VMLargeIntAdd( VMGetHighPerfCounterTickCount(), m_VMHPCTime[ eHPCTime ] ) );
}
/* End of function "GetHighPerfCounterTimer"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetTickCountByOffset
DESCRIPTION: gets the tick count associated with the given offset
INPUT: eHPCTime - the index to use to look up in the ticks table
OUTPUT: none
RETURNS: LARGE_INTEGER - tick count for the given index
*/
LARGE_INTEGER VMGetTickCountByOffset( VMHPCTIME eHPCTime )
{
return( m_VMHPCTime[ eHPCTime ] );
}
/* End of function "VMGetTickCountByOffset"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIsHighPerfCounterTimerUp
DESCRIPTION:
INPUT: xTimer - the timer to evaluate
OUTPUT: none
RETURNS: true if the timer is expired
*/
BOOL VMIsHighPerfCounterTimerUp( LARGE_INTEGER xTimer )
{
return( VMLargeIntGreaterThanOrEqualTo( VMGetHighPerfCounterTickCount(), xTimer ) );
}
/* End of function "VMIsHighPerfCounterTimerUp"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetHighPerfCounterMillis
DESCRIPTION: convert a processor tick count to milliseconds
INPUT: xTicks - the tick count to convert
OUTPUT: none
RETURNS: ULONG for milliseconds in the tick count
*/
ULONG VMGetHighPerfCounterMillis( LARGE_INTEGER xTicks )
{
if ( !m_VMHPCInited )
{
VMHighPerfCounterInit();
}
return( VMLargeIntDivide( xTicks, m_VMHPCTime[ VMHPC1MSEC ] ).LowPart );
}
/* End of function "VMGetHighPerfCounterMillis"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetHighPerfCounterMicros
DESCRIPTION: convert a processor tick count to microseconds
INPUT: xTicks - the tick count to convert
OUTPUT: none
RETURNS: ULONG for microseconds in the tick count
*/
ULONG VMGetHighPerfCounterMicros( LARGE_INTEGER xTicks )
{
if ( !m_VMHPCInited )
{
VMHighPerfCounterInit();
}
return( VMLargeIntDivide( xTicks, m_VMHPCTime[ VMHPC1USEC ] ).LowPart );
}
/* End of function "VMGetHighPerfCounterMicros"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetHighPerfCounterElapsedMillis
DESCRIPTION: Get the number of milliseconds that have elapsed since
the given processor tick.
INPUT: xTicks - the tick to compare from
OUTPUT: none
RETURNS: ULONG for the total number of millies elapsed
*/
ULONG VMGetHighPerfCounterElapsedMillis( LARGE_INTEGER xTicks )
{
if ( !m_VMHPCInited )
{
VMHighPerfCounterInit();
}
LARGE_INTEGER xNowTicks = VMGetHighPerfCounterTickCount();
return( VMLargeIntGreaterThan( xNowTicks, xTicks )
? VMLargeIntDivide( VMLargeIntSubtract( xNowTicks, xTicks ),
m_VMHPCTime[ VMHPC1MSEC ] ).LowPart
: 0 );
}
/* End of function "VMGetHighPerfCounterElapsedMillis"
/*****************************************************************************/
/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -