Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET : Monitoring Objects Lifetime (Birth/Death/Memory)

Tags:

c#

.net

Issue : What is the best way to have a comprehensive view of birth/death/mem usage of ALL objects created during an application lifetime? (graphic report would be better)

Why such a question : Among many others, the idea behind that, is to reveal long-living objects that may never be collected by the garbage collector or cause memory trouble (such as heap/stack issues or so), and provide valuable information to efficiently manage object lifecycles

(I actually just spent a whole night debugging a multithreaded application to finally notice that a "believed to be disposed/renewed" object was in fact still alive and smashing up the server memory.)

VS2010 Performance Wizard & Profiler might be a good starter... I stumbled upon few ways to do this programmatically but it involved wrapping up objects individually (painstaking and not code-seamless)

I'm looking for something that would look like this :

Application START[-----------------------------------------------------------]END
Object 1                [---------------------------]
Object 2                          [---------------------------]
Object 3           [-----------------------------------------------------]
like image 388
Mehdi LAMRANI Avatar asked Dec 17 '10 17:12

Mehdi LAMRANI


2 Answers

Mika,

As you noted you can use the VS2010 Profiler (if you have Visual Studio Premium or Ultimate). For more information see the MSDN page about collecting 'Object Lifetime' information.

Beware that this profiling mode is pretty heavyweight compared to other profiling modes and you may find the collected VSP file is quite large unless you have a fairly focussed scenario that you are profiling.

The profiling report will show the information in tabular form, but you can copy the data into Excel or another program of your choice for further analysis/charting.

Disclaimer: I work on the Visual Studio profiler.

like image 131
Colin Thomsen Avatar answered Oct 20 '22 14:10

Colin Thomsen


There are some tools which can do that but not as easily as graph. You will need to learn a bit on those tools.

Free: CLR Profiler http://msdn.microsoft.com/en-us/library/ff650691.aspx

WinDbg: http://www.microsoft.com/whdc/devtools/debugging/default.mspx

Use the SOS or SOSEX extension with Windbg to profile .NET code.

Commercial : Red Gate Ants Profiler: http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/

like image 30
Madhur Ahuja Avatar answered Oct 20 '22 14:10

Madhur Ahuja