1

Here i need total time of a thread,so i am using GetThreadTimes function to get thread times kernel mode as well as in user mode.

GetThreadTimes(threadHandle, &ftCreate, &ftExit, &ftKernel, &ftUser);
LARGE_INTEGER qwKernel, qwUser;
qwKernel.HighPart = ((ftKernel.dwHighDateTime));
qwKernel.LowPart = ftKernel.dwLowDateTime; 

I Can able to get the thread creation time.But i need to get the ( kernel time + user time ) total time used by this thread.

Since kernal and User time that i get from the GetthreadTimes is amount of time taken(either in Milliseconds or Seconds) , how to get those times.

I tried below code snippet. But I am getting huge numbers in the corresponding QuadParts.

qwUser.HighPart = ftUser.dwHighDateTime;
qwUser.LowPart = ftUser.dwLowDateTime;
cout << "Kernel QuadPart value :" << qwKernel.QuadPart << endl;
cout << "User QuadPart value :" << qwUser.QuadPart << endl;

I am getting the Output as :

Kernel QuadPart value :140716350575597 User QuadPart value : 739454089384

Kernel QuadPart value :-2 User QuadPart value : 739510908248

From the above output i get huge numbers. But my thread's total elapsed time is only less than 10 seconds.

Is this the correct way i am getting the Kernel and User time..?

Thanks.

Durai
  • 87
  • 12
  • 1
    It's been a long time since I programmed windows. What you are doing looks about right, but I would definitely check the return value from `GetThreadTimes` - if it returns zero, you've got a problem - and of course, if the function didn't succeed, your values out of the function are pretty much "nobody could guess". – Mats Petersson Mar 10 '17 at 07:46
  • `either in Milliseconds or Seconds` - this time in 1/10000000 part of second. kernel and user time - from begin execute. create and exit in absolute form 1601 – RbMm Mar 10 '17 at 07:53
  • @MatsPetersson The function GetThreadTimes returns a non zero value. – Durai Mar 10 '17 at 08:48
  • Then there's something else wrong, which is not apparent from what you have posted, in some way... – Mats Petersson Mar 10 '17 at 08:49
  • Did you squire the necessary rights? _"A handle to the thread whose timing information is sought. The handle must have the THREAD_QUERY_INFORMATION or THREAD_QUERY_LIMITED_INFORMATION access right."_ source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683237(v=vs.85).aspx – Richard Critten Mar 10 '17 at 08:59
  • @MatsPetersson what you said is correct, The GetThreadTimes function returns the value is 6,that indicates "ERROR_INVALID_HANDLE".Now this problem is resolved. thanks for your reply. – Durai Mar 10 '17 at 10:07
  • Keep in mind that the kernel time for a thread may include tasks that aren't related to your application, e.g., some device driver code runs on whatever thread happens to be active at the time. – Harry Johnston Mar 10 '17 at 21:04

0 Answers0