Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining CPU usage in WinCE

I want to be able to get the current % CPU usage in a C++ program running under Wince.

I found this link that states where the source code is but I cannot find it in my platform builder installation - I expect this is because it isn't the Windows Automotive platform.

Does anyone know where I can find this source code or (even better) know how I can get this information directly? i.e. what DLL / function calls to make etc.

like image 889
Chris Avatar asked Dec 03 '25 19:12

Chris


2 Answers

Since GetProcessTimes doesn't exist in CE, you have to calculate this.

You have to start with the toolhelp APIs to enumerate the processes and the threads in the processes. You then call GetThreadTimes for each thread and add all that up.

Bear in mind that the act of calculating this info will affect the CPU utilization.

like image 105
ctacke Avatar answered Dec 06 '25 08:12

ctacke


I have found that GetIdleTime (or CeGetIdleTimeEx on WEC7 or newer) works well for calculating system-wide processor usage. Sample code for calculating processor idle time percentage is shown on GetIdleTime MSDN page. Obviously, processor utilization percentage can then be calculated by subtracting the idle time percentage from 100.

The MSDN page does warn that support for GetIdleTime is dependent on OAL implementation.

like image 33
Dmitriy Khodos Avatar answered Dec 06 '25 07:12

Dmitriy Khodos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!