// QPC_Check.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include // _kbhit() #include // Sleep() // This constant is used to check for forward jumps of the performance counter // It is dependent upon the frequency of the counter (determined via // QueryPerformanceFrequency() -- not used in this test app for brevity). #define FWD_LIMIT (0x1000000) int _tmain(int argc, _TCHAR* argv[]) { BOOL bDone = FALSE ; char cUserInput ; LARGE_INTEGER liLastCount, liNewCount ; int nBackEventTally = 0 ; int nFwdEventTally = 0 ; (void)printf("QPC Check - v1.0 Hit 'c' to display current count, 'x' to exit\n") ; // Read counter to prime the LastCount value if (TRUE != QueryPerformanceCounter ( &liLastCount )) { printf("QPC read error\n") ; bDone = TRUE ; } while (FALSE == bDone) { // Respond to user input, if any if (0 != _kbhit()) // _kbhit() returns 0 or "non-zero" { // Get the key cUserInput = _getch() ; if (('x' == cUserInput) || ('X' == cUserInput)) { printf("Exiting QPC_Check\n") ; bDone = TRUE ; } // Print status and last count else if (('c' == cUserInput) || ('C' == cUserInput)) { printf("Backward events: %d Forward events: %d", nBackEventTally, nFwdEventTally ) ; printf(" Last Count = 0x%08x:%08x\n", liLastCount.u.HighPart, liLastCount.u.LowPart ) ; } else if ('b' == cUserInput) { printf("Testing backward event...\n") ; liLastCount.QuadPart += FWD_LIMIT ; } else if ('f' == cUserInput) { printf("Testing forward event...\n") ; liLastCount.QuadPart -= (FWD_LIMIT + 1); } } // Read & check counter if (TRUE == QueryPerformanceCounter ( &liNewCount )) { // Check for new < last if (liNewCount.QuadPart < liLastCount.QuadPart) { nBackEventTally++ ; printf("Jump backward event: Last = 0x%08x:%08x, New = 0x%08x:%08x\n", liLastCount.u.HighPart, liLastCount.u.LowPart, liNewCount.u.HighPart, liNewCount.u.LowPart ) ; } // Check for new>> last if (liNewCount.QuadPart> (liLastCount.QuadPart + FWD_LIMIT)) { nFwdEventTally++ ; printf("Jump forward event: Last = 0x%08x:%08x, New = 0x%08x:%08x\n", liLastCount.u.HighPart, liLastCount.u.LowPart, liNewCount.u.HighPart, liNewCount.u.LowPart ) ; } // Update LastCount with new value liLastCount.QuadPart = liNewCount.QuadPart ; } else { printf("QPC read error\n" ) ; bDone = TRUE ; } Sleep( 50 ) ; // wait 50 millisecs then check counter again } return 0; }

AltStyle によって変換されたページ (->オリジナル) /