1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
// //////////////////////////////////////////////////////////////////////////
// Implementation file WinNtTimer.cpp for class WinNtTimer
// (c)Copyright 2000, Baptiste Lepilleur.
// Created: 2002/04/19
// //////////////////////////////////////////////////////////////////////////
#include "WinNtTimer.h"
/*! Returns time spent in the thread.
* @param rquadTime Receive the time spent in the thread (user+kernel time)
* in unit of 100 nano-seconds.
* In pratice, the effective resolution is 10ms !!!
*
* @return \c true if sucess, \c false otherwise.
*/
static bool
GetThreadSpentTime( LONGLONG &rquadTime )
{
FILETIME timeCreation;
FILETIME timeExit;
FILETIME timeKernel;
FILETIME timeUser;
if ( !::GetThreadTimes( ::GetCurrentThread(),
&timeCreation,
&timeExit,
&timeKernel,
&timeUser) )
{
rquadTime = 0;
return false;
}
LARGE_INTEGER lintKernel;
lintKernel.LowPart = timeKernel.dwLowDateTime;
lintKernel.HighPart = timeKernel.dwHighDateTime;
LARGE_INTEGER lintUser;
lintUser.LowPart = timeUser.dwLowDateTime;
lintUser.HighPart = timeUser.dwHighDateTime;
rquadTime = lintKernel.QuadPart + lintUser.QuadPart;
return true;
}
void
WinNtTimer::start()
{
m_isValid = GetThreadSpentTime( m_beginTime );
}
void
WinNtTimer::finish()
{
LONGLONG quadTimeEnd;
LONGLONG quadProcessedElapse;
m_isValid = m_isValid && GetThreadSpentTime( quadTimeEnd );
if ( m_isValid )
{
quadProcessedElapse = quadTimeEnd - m_beginTime;
m_elapsedTime = double(quadProcessedElapse) / 10000000;
}
else
m_elapsedTime = -1;
}
double
WinNtTimer::elapsedTime() const
{
return m_elapsedTime;
}
|