WinCE CPU usage calculation test tool

Reprinted from
http://blog.csdn.net/janvi/article/details/8218617




The original article was thrown into the recycle bin and cannot be retrieved. Here is the resource link of the tool (code):

http://download.csdn.net/source/2305979
http://download.csdn.net/source/2420987
It has not been sorted out for a long time, and these two posts are repeated.

I haven't contacted WinCE for a long time, so here is a brief introduction to the calculation method.

There is nothing to say about memory usage fetching, ready API. However, only the global memory usage status can be obtained. There is no good way to know the memory usage of each process for the time being. Once I tried to traverse the virtual space of the process and use the block state (commit, reserve) to comprehensively calculate. Certainly not allowed, the actual data is not quite right. Remember that the task manager on Meizu's M8 can display the memory usage of each process. It should be a function when customizing the system. I don't understand the underlying things. If you have any thoughts, please send me a message, so that I can gain insight.

CPU usage, there is no ready-made API. I believe that many people also want to find a way, but no one has done it. CPU usage, to put it bluntly, is this formula: non-idle process usage time/statistical time. So we can take a statistical unit time and calculate the non-idle time. The statistical time is 1000ms, and GetIdleTime() is used to obtain the idle time, then the CPU usage is: 100 * (1000 - GetIdleTime())/1000. The first version of this tool was implemented in this way, and of course there were problems later. When some platforms are customized, GetIdleTime() is not implemented. In this case, GetIdleTime() returns 0, causing the CPU usage we calculated to be 100% all the time. Another way is to count the time of all threads (the basic CPU scheduling unit), and accumulate all the non-idle time. The implementation steps are:

1. Use tools such as CreateToolhelp32Snapshot() to traverse all threads

2. Use GetThreadTimes() to get the time of each thread

3. Accumulate the time of all threads and calculate the usage rate The

actual aggregated time has some errors, so control not to let the CPU range exceed [0- 100]. For details, see the code, the name of cpp, and the heart of the c language.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326552938&siteId=291194637