I'm running a test that launches two processes, using C#. I need to get the top memory and CPU used by my process. Please, someone could give me a guideline about how to do it using managed code? (I also run it on linux using mono).
The architecture is the following:
The process
test.exe
launches two processes:A.exe
andB.exe
. I need to measure meausre max memory and CPU for processes A and B, fromtest.exe
Is it possible to do? Thanks in advance
You can use the System.Diagnostics.Process
class to start the process. You can then check the UserProcessorTime
, TotalProcessorTime
, PeakWorkingSet64
and other properties to check processor usage and memory usage. Check this MSDN Article for System.Diagnostics.Process.
Try use this Get CPU Info
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
public string getCurrentCpuUsage(){
return cpuCounter.NextValue()+"%";
}
public string getAvailableRAM(){
return ramCounter.NextValue()+"MB";
}
EDIT: So you can check difference before you start your process and after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With