Greetings All
Forgive my ignorance, but the PDH interface documentation is very
confusing.
When I attempt to get the "System Up Time" using the PDH library and
compare what it returns to the value returned by GetTickCount(), there
is a disparity that gets larger the longer the computer is up.
Right after start-up, the disparity is between 200 and 600ms. After
the system has been up almost five days, there is a 30 second
difference (30,000ms).
I would expect a few millisecond disparity because of the intervening
code between GetTickCount() and PdhGetRawCounterValue(), but not
thirty seconds!
Does the problem have something to do with the resolution available to
GetTickCount(), or is it my code, or is it something else altogether?
Thanks
Tony
code follows
// remember to add pdh.lib to your project
// and include the platform sdk include
// directory in your include directory list
#include <windows.h>
#include <stdio.h>
#include <pdh.h>
int main( int argc, char *argv[])
{
HQUERY perfQuery;
HCOUNTER uptimeCounter;
PDH_RAW_COUNTER uptimeValue;
memset( &uptimeValue, 0, sizeof( PDH_RAW_COUNTER ) );
PdhOpenQuery( NULL, 0, &perfQuery );
PdhAddCounter( perfQuery,
"\\\\.\\System\\System Up Time", 0,
&uptimeCounter );
PdhCollectQueryData( perfQuery );
PdhGetRawCounterValue( uptimeCounter, NULL, &uptimeValue );
PdhCloseQuery( &perfQuery );
// I had to determine this formula by trial and error
// is it the correct way to get the number of ms that
// the system has been running?
__int64 tickCount64 =
(uptimeValue.SecondValue-uptimeValue.FirstValue)/10000;
DWORD tickCount32 = GetTickCount();
__int64 tempTick = 0;
tempTick = tickCount32;
__int64 tickError = tickCount64 - tempTick;
printf( "tickCount64 = %I64d, tickCount32 = %d, error = %I64d",
tickCount64, tickCount32, tickError );
return 0;
}