Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor a process's usage of each CPU core

Is there a way to query or calculate the CPU usage of a single process per each core separately?

For example,

Name - - - - Core1 - Core2 - Core3 - Core4
firefox.exe - 0.5% - - 0.1% - - 0.2% - - 0.3%

I know a program called "Process Explorer" (by Mark Russinovich) that can do this, but how can I do this in C#? I've had a look at the System.Diagnostics namespace, but I couldn't find anything fitting to my requirements.

Here's a picture of what I'm trying to achieve,

http://i.stack.imgur.com/XySpQ.png

like image 538
Joker163 Avatar asked Sep 22 '13 14:09

Joker163


People also ask

How do you check CPU utilization of individual cores?

The sar Command We can then view these stats with the help of the sar command. In most machines, sysstat comes pre-installed. However, we can also install it manually using Linux package installers like Yum and Apt. Here, ALL denotes that sar should display the CPU utilization for all cores.

Where can we see the CPU utilization of each stage in a job?

While a stage or stage instance is processing data rows, it can use a large portion of the CPU. You can use the Monitor window to check what percentage of the computer processor is being used by an active stage. To show the percentage of CPU usage, choose Show %CP from the Monitor shortcut menu.

What is CPU core usage?

Overall, cores are used to transmit information throughout your computer and allow you to make changes to files. You can speed up the processing time of your CPU by having multiple cores and tinkering with overclocking (which you can read about here).


1 Answers

There is a way to get that information, you will need to use a Kernel Debugger. My suspect were that if the Visual Studio Concurrency Visualizer can get this information to make beautiful reports and visualizations, then you can also get it from the Windows Kernel for you use.

You can see some documentation here http://msdn.microsoft.com/en-us/library/windows/hardware/ff552961(v=vs.85).aspx .

But more interesting things can be found by reversing the Microsoft.ConcurrencyVisualizer.dll that can be found on Visual Studio 2012 installation directory. I think you can also use directly this DLL on your project, although you cannot redeploy it as per http://msdn.microsoft.com/en-US/vstudio/hh857605#files. That DLL is available standalone here http://www.microsoft.com/en-us/download/details.aspx?id=41646.

The idea is to learn how this DLL uses the Kernel Trace to know what Thread was on what Core and replicate it to get accurate statistics. Also, I think that ProcessExplorer does get some stats by using the Kernel Debugger API because the Visual Studio conflicts with it when I start the Concurrency Visualizer tool.

This will be fun and hard to do.

like image 197
Luiz Felipe Avatar answered Oct 19 '22 11:10

Luiz Felipe