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?
.NET Memory performance counters will give you aggregate information, but does not include object counters. For that you will need a profiler.
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.
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.
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