Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the cpu usage per thread on windows (win32)

Tags:

Looking for Win32 API functions, C++ or Delphi sample code that tells me the CPU usage (percent and/or total CPU time) of a thread (not the total for a process). I have the thread ID.

I know that Sysinternals Process Explorer can display this information, but I need this information inside my program.

like image 539
Dirk Paessler Avatar asked Sep 08 '09 09:09

Dirk Paessler


People also ask

How do I check my CPU percentage in Windows?

Start by pressing CTRL + Shift + Esc on your keyboard. In the following window, click Task Manager. While in Task Manager, click the Performance tab. Here in the Performance tab, you can see how much of the CPU the computer is currently using.

How do I reduce CPU thread usage?

The best solution to limiting the cpu usage for a process or thread is to make sure that the thread or process uses less cpu. That can best be done by improving the efficiency of the code, or by calling it less often. The aim is to make sure that the process doesn't continually consume all of its available time slice.


1 Answers

You must use these functions to get the cpu usage per thread and process.

GetThreadTimes (Retrieves timing information for the specified thread.)

GetProcessTimes (Retrieves timing information for the specified process.)

GetSystemTime (Retrieves the current system date and time. The system time is expressed in Coordinated Universal Time UTC)

Here a excellent article from Dr. Dobb's Win32 Performance Measurement Options

Bye.

like image 61
RRUZ Avatar answered Sep 25 '22 03:09

RRUZ