Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to track memory usage in a C# application without using a profiler?

I'd like to write a simple application which keeps track of its current memory usage, number of created objects etc. In C++ I'd normally override the new operator, but for obvious reasons I can't do this in C#. Is there any way to do this without using a profiler?

like image 770
Trap Avatar asked Feb 27 '09 16:02

Trap


3 Answers

.NET Memory performance counters will give you aggregate information, but does not include object counters. For that you will need a profiler.

like image 29
Richard Avatar answered Oct 14 '22 07:10

Richard


You might want to start with the Garbage Collector. MSDN has some members listed here that can show you how to do a few things, like get the total amount of memory it thinks is allocated, how many times the GC has collected. Anything more advanced than that, like getting a count of objects of your loaded assembly and you'll have to probably use a profiler or write something yourself.

like image 50
Joseph Avatar answered Oct 14 '22 07:10

Joseph


Using WMI try :

To get process usage (W2K3/2K8) :

"SELECT IDProcess, PercentPrivilegedTime, PercentProcessorTime, PercentUserTime FROM Win32_PerfFormattedData_PerfProc_Process where Name='process_name.exe'"

To identify your site use this :

"SELECT ProcessId, CommandLine, WorkingSetSize, ThreadCount, PrivatePageCount, PageFileUsage, PageFaults, HandleCount, CreationDate, Caption FROM Win32_Process where Caption='process_name.exe'"

Use this tool for WQL teste

Or use PerfMon tool.

For more information about counters see Windows System Resource Manager Accounting, at the end of doc.

Good luck.

like image 22
lsalamon Avatar answered Oct 14 '22 08:10

lsalamon