📄 vmhighperfcounter.cpp
字号:
/*****************************************************************************/
/* SOURCE FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: High Precision Counter Tools
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/
#include "../../../stdafx.h"
#include "VMLargeIntMath.h"
#include "VMHighPerfCounter.h"
// The HPC time constant array.
//
LARGE_INTEGER m_VMHPCTime[ VMHPCTIMECOUNT ];
// The number of processor ticks in a second.
//
LARGE_INTEGER m_VMHPCTicksPerSecond = { 0, 0 };
// True if the processor module has been initialized.
//
BOOL m_VMHPCInited = FALSE;
/*****************************************************************************/
/*
FUNCTION NAME: VMHighPerfCounterInit
DESCRIPTION: Initialize the processor tick values
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMHighPerfCounterInit( void )
{
LARGE_INTEGER tps;
LARGE_INTEGER tw;
LARGE_INTEGER th;
if ( m_VMHPCInited )
{
return;
}
tps = VMGetHighPerfCounterTicksPerSecond();
tw = VMLargeIntDivide( tps, 1000000 );
m_VMHPCTime[ VMHPC1USEC ] = tw;
m_VMHPCTime[ VMHPC2USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC1USEC ], tw );
m_VMHPCTime[ VMHPC3USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC2USEC ], tw );
m_VMHPCTime[ VMHPC4USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC3USEC ], tw );
m_VMHPCTime[ VMHPC5USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC4USEC ], tw );
m_VMHPCTime[ VMHPC6USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC5USEC ], tw );
m_VMHPCTime[ VMHPC7USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC6USEC ], tw );
m_VMHPCTime[ VMHPC8USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC7USEC ], tw );
m_VMHPCTime[ VMHPC9USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC8USEC ], tw );
tw = VMLargeIntDivide( tps, 100000 );
m_VMHPCTime[ VMHPC10USEC ] = tw;
m_VMHPCTime[ VMHPC20USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC10USEC ], tw );
m_VMHPCTime[ VMHPC30USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC20USEC ], tw );
m_VMHPCTime[ VMHPC40USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC30USEC ], tw );
m_VMHPCTime[ VMHPC50USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC40USEC ], tw );
m_VMHPCTime[ VMHPC60USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC50USEC ], tw );
m_VMHPCTime[ VMHPC70USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC60USEC ], tw );
m_VMHPCTime[ VMHPC80USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC70USEC ], tw );
m_VMHPCTime[ VMHPC90USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC80USEC ], tw );
tw = VMLargeIntDivide( tps, 10000 );
m_VMHPCTime[ VMHPC100USEC ] = tw;
m_VMHPCTime[ VMHPC200USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC100USEC ], tw );
m_VMHPCTime[ VMHPC300USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC200USEC ], tw );
m_VMHPCTime[ VMHPC400USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC300USEC ], tw );
m_VMHPCTime[ VMHPC500USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC400USEC ], tw );
m_VMHPCTime[ VMHPC600USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC500USEC ], tw );
m_VMHPCTime[ VMHPC700USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC600USEC ], tw );
m_VMHPCTime[ VMHPC800USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC700USEC ], tw );
m_VMHPCTime[ VMHPC900USEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC800USEC ], tw );
tw = VMLargeIntDivide( tps, 1000 );
m_VMHPCTime[ VMHPC1MSEC ] = tw;
m_VMHPCTime[ VMHPC2MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC1MSEC ], tw );
m_VMHPCTime[ VMHPC3MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC2MSEC ], tw );
m_VMHPCTime[ VMHPC4MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC3MSEC ], tw );
m_VMHPCTime[ VMHPC5MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC4MSEC ], tw );
m_VMHPCTime[ VMHPC6MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC5MSEC ], tw );
m_VMHPCTime[ VMHPC7MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC6MSEC ], tw );
m_VMHPCTime[ VMHPC8MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC7MSEC ], tw );
m_VMHPCTime[ VMHPC9MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC8MSEC ], tw );
tw = VMLargeIntDivide( tps, 100 );
th = VMLargeIntDivide( tps, 200 );
m_VMHPCTime[ VMHPC10MSEC ] = tw;
m_VMHPCTime[ VMHPC15MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC10MSEC ], th );
m_VMHPCTime[ VMHPC20MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC10MSEC ], tw );
m_VMHPCTime[ VMHPC25MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC20MSEC ], th );
m_VMHPCTime[ VMHPC30MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC20MSEC ], tw );
m_VMHPCTime[ VMHPC35MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC30MSEC ], th );
m_VMHPCTime[ VMHPC40MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC30MSEC ], tw );
m_VMHPCTime[ VMHPC45MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC40MSEC ], th );
m_VMHPCTime[ VMHPC50MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC40MSEC ], tw );
m_VMHPCTime[ VMHPC55MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC50MSEC ], th );
m_VMHPCTime[ VMHPC60MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC50MSEC ], tw );
m_VMHPCTime[ VMHPC65MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC60MSEC ], th );
m_VMHPCTime[ VMHPC70MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC60MSEC ], tw );
m_VMHPCTime[ VMHPC75MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC70MSEC ], th );
m_VMHPCTime[ VMHPC80MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC70MSEC ], tw );
m_VMHPCTime[ VMHPC85MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC80MSEC ], th );
m_VMHPCTime[ VMHPC90MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC80MSEC ], tw );
m_VMHPCTime[ VMHPC95MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC90MSEC ], th );
tw = VMLargeIntDivide( tps, 10 );
th = VMLargeIntDivide( tps, 20 );
m_VMHPCTime[ VMHPC100MSEC ] = tw;
m_VMHPCTime[ VMHPC150MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC100MSEC ], th );
m_VMHPCTime[ VMHPC200MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC100MSEC ], tw );
m_VMHPCTime[ VMHPC250MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC200MSEC ], th );
m_VMHPCTime[ VMHPC300MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC200MSEC ], tw );
m_VMHPCTime[ VMHPC350MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC300MSEC ], th );
m_VMHPCTime[ VMHPC400MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC300MSEC ], tw );
m_VMHPCTime[ VMHPC450MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC400MSEC ], th );
m_VMHPCTime[ VMHPC500MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC400MSEC ], tw );
m_VMHPCTime[ VMHPC550MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC500MSEC ], th );
m_VMHPCTime[ VMHPC600MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC500MSEC ], tw );
m_VMHPCTime[ VMHPC650MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC600MSEC ], th );
m_VMHPCTime[ VMHPC700MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC600MSEC ], tw );
m_VMHPCTime[ VMHPC750MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC700MSEC ], th );
m_VMHPCTime[ VMHPC800MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC700MSEC ], tw );
m_VMHPCTime[ VMHPC850MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC800MSEC ], th );
m_VMHPCTime[ VMHPC900MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC800MSEC ], tw );
m_VMHPCTime[ VMHPC950MSEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC900MSEC ], th );
tw = tps;
m_VMHPCTime[ VMHPC1SEC ] = tw;
m_VMHPCTime[ VMHPC2SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC1SEC ], tw );
m_VMHPCTime[ VMHPC3SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC2SEC ], tw );
m_VMHPCTime[ VMHPC4SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC3SEC ], tw );
m_VMHPCTime[ VMHPC5SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC4SEC ], tw );
m_VMHPCTime[ VMHPC6SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC5SEC ], tw );
m_VMHPCTime[ VMHPC7SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC6SEC ], tw );
m_VMHPCTime[ VMHPC8SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC7SEC ], tw );
m_VMHPCTime[ VMHPC9SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC8SEC ], tw );
m_VMHPCTime[ VMHPC10SEC ] = VMLargeIntAdd( m_VMHPCTime[ VMHPC9SEC ], tw );
m_VMHPCInited = TRUE;
}
/* End of function "VMHighPerfCounterInit"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMGetHighPerfCounterTickCount
DESCRIPTION: Get the current processor tick count
INPUT: void
OUTPUT: none
RETURNS: LARGE_INTEGER value for the current tick count
*/
LARGE_INTEGER VMGetHighPerfCounterTickCount( void )
{
LARGE_INTEGER xResult;
__asm
{
rdtsc
mov [ xResult ].LowPart,eax
mov [ xResult ].HighPart,edx
}
return( xResult );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -