Using PerformanceCounter to track memory and CPU usage per process?

For per process data: Process p = /*get the desired process here*/; PerformanceCounter ramCounter = new PerformanceCounter(“Process”, “Working Set”, p.ProcessName); PerformanceCounter cpuCounter = new PerformanceCounter(“Process”, “% Processor Time”, p.ProcessName); while (true) { Thread.Sleep(500); double ram = ramCounter.NextValue(); double cpu = cpuCounter.NextValue(); Console.WriteLine(“RAM: “+(ram/1024/1024)+” MB; CPU: “+(cpu)+” %”); } Performance counter also has other counters than … Read more

PerformanceCounter reporting higher CPU usage than what’s observed

new PerformanceCounter(“Processor”, …); You are using the wrong counter if you insist on seeing an exact match with Task Manager or Perfmon. Use “Processor Information” instead of “Processor”. The reason these counters show different values is addressed pretty well in this blog post. Which counter is “right” is a question I wouldn’t want to touch … Read more

What is the correct Performance Counter to get CPU and Memory Usage of a Process?

From this post: To get the entire PC CPU and Memory usage: using System.Diagnostics; Then declare globally: private PerformanceCounter theCPUCounter = new PerformanceCounter(“Processor”, “% Processor Time”, “_Total”); Then to get the CPU time, simply call the NextValue() method: this.theCPUCounter.NextValue(); This will get you the CPU usage As for memory usage, same thing applies I believe: … Read more

How to measure program execution time in ARM Cortex-A8 processor?

Accessing the performance counters isn’t difficult, but you have to enable them from kernel-mode. By default the counters are disabled. In a nutshell you have to execute the following two lines inside the kernel. Either as a loadable module or just adding the two lines somewhere in the board-init will do: /* enable user-mode access … Read more