Reputation: 121
I have the processID associated with a process. I have created this process using the CreateProcess()
function. During the run of it, I want to track how many processors it runs on and how much time this executable has used on multicore machines.
I want to write C++ code for the same; can anyone help me on this?
I am using Win XP multicore machines.
Upvotes: 0
Views: 383
Reputation: 16904
You can capture this level of detail on Vista or later using Event Tracing for Windows (ETW) and the CSwitch event (which is emitted on every context switch).
Various tools (e.g. the Windows Performance Toolkit) capture and visualize this data.
However, this isn't supported on Windows XP.
If you just want know what your typical concurrency is (i.e. how many of your threads are running at a given time) you could regularly sample the perfmon Thread data (from HKEY_PERFORMANCE_DATA). The "Thread State" counter will give you the instantaneous state of every thread in your process (i.e. whether each thread is running or not). Obviously this sampling process will limit the maximum concurrency to (number of processors - 1).
But do you really need this much detail? GetProcessTimes is usually enough.
Update
You can run your app on a test machine and simply measure the utilization of each CPU using perfmon. You should also measure the CPU utilization of each process to ensure nothing else is running unexpectedly.
To capture data for a report, run perfmon as an Administrator.
And that's it.
Upvotes: 0
Reputation: 69734
Retrieves the process affinity mask for the specified process and the system affinity mask for the system.
Retrieves timing information for the specified process.
Upvotes: 1