We have C#.Net windows application, from this application i need to track the memory and CPU usage details of the currently running process. I tried the below mentioned code to get memory details.
Process curProcess=Process.GetCurrentProcess();
Console.Writeline(curProcess.PrivateMemorySize64);
Console.Writeline(curProcess.VirtualMemorySize64);
Console.Writeline(curProcess.PagedMemorySize64);
Console.Writeline(curProcess.NonpagedSystemMemorySize64);
var counter = new PerformanceCounter("Process", "Working Set - Private", Process.GetCurrentProcess().ProcessName);
Console.Writeline(curProcess.PagedMemorySize64);
Console.Writeline(counter.RawValue);
All the above code give the whole process memory details, But my requirement is to get the below details,
- List of objects in memory and corresponding object's memory allocations,
- Amount of memory collected by Garbage collector,
- Un-Disposed objects count and its name,
Process threads and its relationships.
Please send me some code samples to achieve my requirement.
NOTE: I tried CLR profile and ANTS profile to get the detailed information about the memory, but i really need the sample code to achieve inside my application.
Thank you very much.