http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx
views:
62answers:
2
A:
I think you want Windows Management Instrumentation.
EDIT: See here:
http://stackoverflow.com/questions/1754638/measure-a-process-cpu-and-ram-usage
http://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-c
Robert Harvey
2010-08-05 04:47:10
how do you track process memory and CPU usage with WMI?
Louis Rhys
2010-08-05 04:48:17
Yeah, your right. MSDN is running me in circles. I wind up at Performance Counters again.
Robert Harvey
2010-08-05 04:57:03
Here we go. See my edit.
Robert Harvey
2010-08-05 05:01:00
+2
A:
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 Working set and Processor time.
Louis Rhys
2010-08-23 06:46:26