monitor cpu usage per thread on windows mobile device - c++

Is is possible to measure CPU per thread on a windows mobile (or CE 5) device programmatically (c++)? If not, is their a utility that will monitor the CPU usage of a process?

CPU usage cannot be directly measured because, unlike an x86, the ARM processor doesn't have a register for it. You can calculate it using the Toolhelp APIs to get a list of processes and their child threads and then use GetThreadTimes to figure out how much time each thread is using.
Keep in mind that doing this calculation directly affects how much the CPU is in use.

Someone wrote a tool that looks a lot like Task Manager on the PC:
http://www.vttoth.com/LPK/taskmanager.html
As ctacke says, it does seem to use a lot of the CPU. It reports uses ~15%-30% of our CPU on our 800MHz ARM device.

Related

Limiting processor count for multi-threaded applications

I am developing a multi threaded application which ran fine on my development system which has 8 cores. When I ran it on a PC with 2 cores I encountered some synchronization issues.
Apart from turning off hyper-threading is there any way of limiting the number of cores an application can use so that I can emulate single and dual core environments for testing & debugging.
My application is written in C++ using Visual Studio 2010.
We always test in virtual machines nowadays since it's so easy to set up specific environments with given limitations.
For example, VMWare easily allows you to limit the number of processors in use, how much memory there is, hard disk sizes, the presence of USB or floppies or printers and all sorts of other wondrous things.
In fact, we have scripts which do all the work at the push of a button, from restoring the VM to a known initial state, then booting it up, installing the code over the network, running a test cycle then moving the results to an analysis machine on the network as well.
It greatly speeds up and simplifies the testing regime.
You want the SetProcessAffinityMask function or the SetThreadAffinityMask function.
The former works on the whole process and the latter on a specific thread.
You can also limit the active cores via the Windows Task Manager. Right click on process name and select "Set Affinity".

Find out the system frequency in wince 7

I have a system that runs on wince 7.
I have encountered a problem in which the system slows down after a while.
How can I find out the system frequency?
There are several methods (depending on the information you want):
You can use the toolhelp api to find how much processor time each application is using. http://www.codeproject.com/Articles/159461/Mobile-Processor-Usage
IOCTL_PROCESSOR_INFORMATION will tell you what kind of processor is in your system and what clock speed it is running at. http://www.codeproject.com/Tips/122843/What-processor-is-in-my-mobile-device
GetIdleTime() can be used to tell you how busy your processor is overall: http://www.codeproject.com/Tips/133104/Mobile-processor-usage

What is the interface that change the cpu frequency and the core voltage on the windows platform?

I want to find the interface supplied by windows to change the CPU frequency and core voltage.
Thanks!
you can change frequency by using
PowerWriteACValueIndex()/PowerWriteDCValueIndex()
when setting the same index value for both
GUID_PROCESSOR_THROTTLE_MAXIMUM | GUID_PROCESSOR_THROTTLE_MINIMUM
all the GUID description could be found in winnt.h
you cannot change CPU voltage by WINAPI. you should use the privileged commands to write to specific MSRs (see AMD/Intel docs) via system kernel driver.
you cannot change Intel CPU voltage AT ALL since Nehalem micro-architecture. Intel officially does not supply MSRs to write voltage values (VIDs) by software.
From Windows Native Processor Performance Control(document link)
Parameters to P-state policy
Several parameters to Windows processor performance state controls are configurable via registry keys. These keys are provided with the intent that OEMs and system designers may tune the performance of Windows processor power management features to best suit specific platform designs, and allow adjustment to help achieve maximum battery life and realize the best system performance.
And you have to restart to have the changes take effect.
Microsoft Windows does not have an API for overclocking / underclocking a CPU. You would have to roll your own using your assembler skills.
I can do no more than point you in the right direction. I think through Windows Management Instrumentation (WMI) you can get at a COM interface that allows modification of some sub-systems.
Hopefully that vague bit of information will set you on the right path. :-)

getting cpu usage of one process using c++ (win32)

How i get the cpu of one process (by its id or som thing like that...) using c++ lang.
One of ways: Monitoring CPU and disk utilization of a single program

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.
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.
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.
Note that when using the toolhelp APIs to calculate the CPU usage, you need to take two measurements, then calculate the difference. when doing so, you won't know how much CPU any threads that were terminated before the second sample took.
So, applications that often create short-lived threads will not be represented properly in your result.
You can look into Remote Task Monitor. It will let you get the current % CPU usage of your process (or thread), exactly what you are looking for. It also is very light weight, does not impact your device much.