Best .Net Memory and Performance Profiler

Best .NET memory and performance profiler?

No. I have tried pretty much every .NET profiler on the market (ANTS, vTune, OptimizeIt, DevPartner, YourKit), and in my opinion dotTrace is the best of the lot. It is one of only two profilers I have used (the other being YourKit) that has low enough overhead to handle a highly CPU-intensive application.

If and only if your application is relatively light, I could recommend ANTS Profiler. Its line-by-line stats are sometimes quite useful, but they come at a price in profiling efficiency.

What Are Some Good .NET Profilers?

I have used JetBrains dotTrace and Redgate ANTS extensively. They are fairly similar in features and price. They both offer useful performance profiling and quite basic memory profiling.

dotTrace integrates with Resharper, which is really convenient, as you can profile the performance of a unit test with one click from the IDE. However, dotTrace often seems to give spurious results (e.g. saying that a method took several years to run)

I prefer the way that ANTS presents the profiling results. It shows you the source code and to the left of each line tells you how long it took to run. dotTrace just has a tree view.

EQATEC profiler is quite basic and requires you to compile special instrumented versions of your assemblies which can then be run in the EQATEC profiler. It is, however, free.

Overall I prefer ANTS for performance profiling, although if you use Resharper then the integration of dotTrace is a killer feature and means it beats ANTS in usability.

The free Microsoft CLR Profiler (.Net framework 2.0 / .Net Framework 4.0) is all you need for .NET memory profiling.

2011 Update:

The Scitech memory profiler has quite a basic UI but lots of useful information, including some information on unmanaged memory which dotTrace and ANTS lack - you might find it useful if you are doing COM interop, but I have yet to find any profiler that makes COM memory issues easy to diagnose - you usually have to break out windbg.exe.

The ANTS profiler has come on in leaps and bounds in the last few years, and its memory profiler has some truly useful features which now pushed it ahead of dotTrace as a package in my estimation. I'm lucky enough to have licenses for both, but if you are going to buy one .Net profiler for both performance and memory, make it ANTS.

.NET Memory Profiling Tools

I'm currently evaluating both the Scitech .NET Memory Profiler 3.1 and ANTS Memory Profiler 5.1. I tried the JetBrains one a year or two ago and it wasn't as good as ANTS so I haven't bothered this time. From reading the web sites it looks like it isn't as good for memory profiling as the other two.

Both ANTS and the Scitech memory profiler have features that the other doesn't, so which is best will depend upon your preferences. Generally speaking, the Scitech one provides more detailed information while the ANTS one is really incredible at identifying the leaking object. Overall, I prefer the ANTS one because it is so quick at identifying possible leaks.

Here are the main the pros and cons of each from my experience:

Common Features of ANTS and Scitech .NET Memory Profiler

  • Real-time analysis feature
  • Excellent how-to videos on their web sites
  • Easy to use
  • Reasonably performant (obviously slower than without the profiler attached, but not so much you become frustrated)
  • Show instances of leaking objects
  • Basically they both do the job pretty well

ANTS

  • One-click filters to find common leaks including: objects kept alive only by event handlers, objects that are disposed but still live and objects that are only being kept alive by a reference from a disposed object. This is probably the killer feature of ANTS - finding leaks is incredibly fast because of this. In my experience, the majority of leaks are caused by event handlers not being unhooked and ANTS just takes you straight to these objects. Awesome.
  • Object retention graph. While the same info is available in Scitech, it's much easier to interpret in ANTS.
  • Shows size with children in addition to size of the object itself (but only when an instance is selected unfortunately, not in the overall class list).
  • Better integration to Visual Studio (right-click on graph to jump to file)

Scitech .NET Memory Profiler

  • Shows stack trace when object was allocated. This is really useful for objects that are allocated in lots of different places. With ANTS it is difficult to determine exactly where the leaked object was created.
  • Shows count of disposable objects that were not disposed. While not indicative of a leak, it does identify opportunities to fix this problem and improve your application performance as a result of faster garbage collection.
  • More detailed filtering options (several columns can be filtered independently).
  • Presents info on total objects created (including those garbage collected). ANTS only shows 'live' object stats. This makes it easier to analyze and tune overall application performance (eg. identify where lots of objects being created unnecessarily that aren't necessarily leaking).

By way of summary, I think ANTS helps you find what's leaking faster while Scitech provides a bit more detail about your overall application memory performance and individual objects once you know what to look at (eg. stack trace on creation). If the stack trace and tracking of undisposed disposable objects was added to ANTS I wouldn't see the need to use anything else.

.net memory measuring and profiling

It is very hard to measure "real memory" usage on Windows if you mean physical memory. Most likley you want something else like:

  1. Amount of memory allocated for the process (see Zooba's answer)
  2. Amount of Managed memory allocated - CLR Profiler, or any other profiler listed in this one - Best .NET memory and performance profiler?
  3. What Task Manager reports for your application

Note that it is not necessary that after garbage collection is finished amount of memory allocated for your process (1) changes - GC may keep allocated memory for future managed allocations (this behavior is not specific to CLR for memory allcation - most memory allocators keep free blocks for later usage unless forced to release it by some means). The http://blogs.msdn.com/b/maoni/ blog is excelent source for details on GC/memory.

Profiling C# / .NET applications

See also this question. JetBrains dotTrace is the best .NET profiler I have found (and I have tried pretty much every one there is), because it is the only one that has low enough overhead to handle a processor-intensive application. It is also simple, accurate and well-designed - highly recommended!

Which .NET performance and/or memory profilers will allow me to profile a DLL?

.Net Memory Validator and .Net Performance Validator both allow you to profile just a dll.

You have to specify the DLLs you are interested in (or not interested in) in the "Hooked DLLs" part of the settings dialog. Then launch your application - only data from the specified DLL is collected.

Full disclosure: I am a software engineer at the company that creates these tools.

Any decent C# profilers out there?

You can try the following:

  • nprof (free but kinda old)
  • ProfileSharp (open source)
  • .Net Memory Profiler (really good for memory leaks, there's a trial version)

Edit:
Nprof has been replaced with SlimTune and works with .Net 4.0 applications



Related Topics



Leave a reply



Submit