I have the following process:
public void Run()
{
ProcessStartInfo serverPInfo = new ProcessStartInfo("javaw", "-jar -Xms1024M -Xmx1024M \"C:\\Users\\David\\Documents\\Visual Studio 2012\\Projects\\ConsoleApplication8\\Debug\\craftbukkit.jar\" -o true -nojline");
serverPInfo.RedirectStandardInput = true;
serverPInfo.RedirectStandardOutput = true;
serverPInfo.RedirectStandardError = true;
serverPInfo.UseShellExecute = false;
serverP = new Process();
serverP.StartInfo = serverPInfo;
serverP.OutputDataReceived += new DataReceivedEventHandler(ServerOutputDataReceived);
serverP.ErrorDataReceived += new DataReceivedEventHandler(ServerErrorDataReceived);
serverP.Start();
serverP.BeginOutputReadLine();
serverP.BeginErrorReadLine();
serverP.WaitForExit();
}
How can I measure the process' CPU and RAM usage?
I tried serverP.WorkingSet64
, serverP.PrivateMemorySize64
and serverP.PagedMemorySize64
, but they all return constant values. None of them change (like the RAM usage meter in Task Manager).
I have no idea how to get the current CPU usage.
I looked on the internet, but most of the stuff I found was PerformanceMonitor
. I don't want to use this since there may be more instances of the "javaw" process and I just want to measure the CPU and RAM usage of the child process I created in the code above.
Any help would be appreciated.