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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With