CodeExplorer Posted July 2, 2018 Posted July 2, 2018 Looking for PreciseTimer.zip - Visual C++ https://www.codeguru.com/cpp/w-p/system/timers/article.php/c5759/Creating-a-HighPrecision-HighResolution-and-Highly-Reliable-Timer-Utilising-Minimal-CPU-Resources.htm Download links: (can't download if from any of them) http://en.pudn.com/Download/item/id/1109294.html http://www.codeforge.com/article/136174#introduction https://download.csdn.net/download/gddsky/267438 It would be great if someone would share PreciseTimer.zip!
CodeExplorer Posted July 2, 2018 Author Posted July 2, 2018 Never mind I was able to download now the file. (attached)! 701793291PreciseTimer.zip 1
CodeExplorer Posted July 2, 2018 Author Posted July 2, 2018 On the second post it was time measurement, maybe some one will need that. I've created class PreciseTimer from first post, first link (attached). And some usage here: void CAlocLogDlg::OnButton9() { // TODO: Add your control notification handler code here for (int i=0;i<2000000000;i++) { PreciseTimer* pt = new PreciseTimer(); LARGE_INTEGER iStart, iStop; QueryPerformanceCounter(&iStart); pt->Wait(5); // is there anything to wait on? ... then wait QueryPerformanceCounter(&iStop); long diference = (long)iStop.QuadPart-(long)iStart.QuadPart; if (diference>5) { int no_way = 1; } } } PreciseTimer.zip 1
CodeExplorer Posted July 2, 2018 Author Posted July 2, 2018 timeSetEvent https://msdn.microsoft.com/en-us/library/windows/desktop/dd757634(v=vs.85).aspx suppose to be precise void CALLBACK TimerFunction(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2) { char conv_str[50]; wsprintf(conv_str,"%d", GetTickCount()); // convert number to dec string InsertStringToList(conv_str); } void CAlocLogDlg::OnButton9() { // TODO: Add your control notification handler code here // https://msdn.microsoft.com/en-us/library/windows/desktop/dd757634%28v=vs.85%29.aspx MMRESULT m_idEvent = timeSetEvent(1, 0, TimerFunction, (DWORD)this, TIME_PERIODIC); } Actually is not precise at all! Still maybe someone will find the solutions posted above useful, but not me! The best solution I found so far is CreateThread on an infinite loop: DWORD dwThreadId; HANDLE hThread = CreateThread( NULL, // default security attributes 0, // use default stack size MyThreadFunction, // thread function name NULL, // argument to thread function 0, // use default creation flags &dwThreadId); // returns the thread identifier But there is a problem: to many CPU resource are consumed. I've thinked at something like if the time passed since last value found has a specific value do Sleep(1).
CodeExplorer Posted July 2, 2018 Author Posted July 2, 2018 So here is my solution: LastTimeValueFound = GetTickCount(); called twice after each variable was readed, and on the loop I do this: if (LastTimeValueFound==0||(GetTickCount()-LastTimeValueFound)>100) { Sleep(1); } CPU usage was once 20% for a short time - when Api logged, When no Api logged 0% CPU usage, tracing time 2 minutes for a nasty Asprotect unpackme.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now