Monitor .NET application performance with the CLR Profiler - SOA - Techguide

Monitor .NET application performance with the CLR Profiler

 

Summary

When you notice memory issues cropping up in your .NET applications, turn to the freely available CLR Profiler. It allows you to take a peek under the hood of .NET applications and monitor the garbage collector heap.

Events

Echelon 2012
June 11 and 12, 2012

University Cultural Centre, National University of Singapore

Startup Asia Jakarta 2012
June 7 and 8, 2012

12th Floor, Annex Building, Wisma Nusantara Complex, Jl. M.H. Thamrin No. 59 Jakarta 10350, Indonesia

MMA Forum Singapore
April 23-25, 2012

Grand Hyatt Singapore

In the .NET Framework, memory management is supposed to be handled automatically by the system. This allows you to concentrate on the important issues of application design and development. Unfortunately, this utopia has not been completely realized as memory issues still appear in .NET-based applications. This article examines one tool--the CLR (Common Language Runtime) Profile--that you may use to track down memory issues.

Garbage collection
The .NET platform adopted the garbage collection approach used in Java. That is, the .NET system tracks all memory blocks allocated in an application. It knows when memory is allocated and what monitors it uses. The system also knows when it is no longer used and frees it up. The garbage collector handles these tasks, but it does not totally divorce you from understanding memory allocation.

Objects in .NET are allocated from an area of memory called the managed heap. The heap is described as managed because, after you ask it for memory, the garbage collector takes care of its cleanup.

Garbage collection begins by assuming all objects are unnecessary until proven otherwise. An object proves that it is necessary essentially by its references, or who it is referenced by. If the object is necessary, it is not part of the garbage collection cycle. On the other hand, if the object is not necessary, the object is flagged to be discarded.

While garbage collection is an automatic process, you should still be aware of how memory is utilized in an application. This allows you to decide if the application is properly using its memory and how the garbage collector is being utilized. This involves knowing the life of objects used to determine how often garbage collection is called in order for you to determine if the garbage collector is taxed.

Code profilers can help with this process by providing a peek at the inner workings of an application, allowing you to gain a better understanding of memory usage. The .NET CLR includes a profiling API that you may use to write custom profilers for managed applications. There are plenty of commercial profiler tools available, but Microsoft provides a free one called the CLR Profiler.

CLR Profiler
The download is comprised of a single installation program that places the tool on your system. In addition, extensive documentation is included. The CLR Profiler allows you to take a peek under the hood of a .NET application and see what is happening as it runs. It also lets you monitor what is happening with the garbage collector heap. By installing the CLR Profiler, you can access the following information about an application:

  • Which methods allocate which types of objects?
  • Which objects survive?
  • What is on the heap?
  • What keeps objects alive?
  • Who is calling whom how often?
  • Which methods, classes, and modules get pulled in by whom?

The data used by the CLR Profiler is stored in self-contained log files. The application provides both Windows client and command-line interfaces.

The tool does affect application performance as it churns out log data, so be careful when/if using it with applications in a production environment. In addition, the size of the log data files can become overwhelming depending on what is being logged, so be wary of disk space. Finally, the CLR Profiler starts the application it will be profiling, so you cannot attach it to currently running processes.

Running the application is easy via the Windows client interface. The simple interface allows you to start and stop profiling, as well as view the current contents of the heap. In addition, you can start and stop profiling (a good option if you're only profiling during certain operations) via a checkbox.

A log file is created once profiling has been stopped. You can see various graphs/reports called views to get an idea of memory usage by the profiled application. The views allow you to track object creation, memory consumed by objects, heap size, the type of objects created, and so forth. This is all available via graphs, so the data is friendly to the eyes (as opposed to scanning a log file).

Commercial tools
If you find that the CLR Profiler falls short in your profiling needs, there are a variety of third-party tools on the market. The following list provides a sampling of these products.

  • ANTS Profiler: It allows you to profile both desktop and Web applications, and the latest version promises Windows Vista support.
  • DevPartner Performance Analysis: It includes support for .NET as well as legacy technologies COM, COM+, and ASP.
  • NProf: An open source profiler available free of charge, but like many open source projects, the documentation is limited.

Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.

Talkback

Add your opinion

In order to post a comment, you need to be registered. (Sign In or register below)

Post your comment

ZDNet Asia Live

#radio Radio Scotland by EnjoyIT 1.0 http://t.co/gaNHe2KU

SingTel (All) SingTel acquires HungryGoWhere for $9.4M ZDNet Asia News http://t.co/QuzQio2Z

Intranets need social to survive http://t.co/pdOHvgBP #intranet #socialintranet #intranet20

Fanboys on AV for Mac: "ludicrous" "a waste of time" "The Mac will protect me" "the most secure ever" "impenetrable" http://t.co/a1o2Sz7E

RT @ameliatmy: the hottest angel investment & venture capital event in #MALAYSIA! will u be there? http://t.co/ChSjkmzu #ABAF

Singapore Game Box in the ZDnet news!
http://t.co/UuTs0SqX http://t.co/YdPKmm39

#radio Radio Bolivia by EnjoyIT 1.0 http://t.co/fdlBPOeI

RT @zdnetasia: SingTel acquires HungryGoWhere for US$9.4 million. http://t.co/Qho1REVZ

Gartner: Mobile CRM gives better ROI than social - http://t.co/s5OfTAXK #CRM

RT @zdnetasia: S'pore sets up portal to grow games sector. http://t.co/In8gtj7L

#Malaysia: 20% yoy rise in overall #wages for both direct and non-direct labor. http://t.co/5T2e0LUU

RT @mikebuetow: #Malaysia: 20% yoy rise in overall #wages for both direct and non-direct labor. http://t.co/5T2e0LUU

@88tc88 RT @KevinZDNetAsia: User experience more important to app monetization than actual content http://t.co/ogbD5wyI… #li #dm12

Dubbed the first social #Olympics, this year's summer games have some of the strictest social rules for all involved http://t.co/4HlcqhW3

Value of big data analytics largely untapped - Zd Net http://t.co/ZuhPrCN4: Pushing cloud limits for d... http://t.co/VyOU0vHz #TheBIBlog

So much as we know , MTK6575 extremely integrated frequency1GHz ARM Cortex-A9 processor, the superiority of 3G / HSPA Modem, and help the...

16 hours ago by y15822137359 on 5 SaaS adoption speed bumps to avoid

I reckon your view: "CRM is strategy, not software", if a company replicating the approach uses in ERP implementation into CRM, what they...

1 day ago by wykoong on Gartner: Mobile CRM gives better ROI than social

This video will teach you about the Excel fill handle but also provide you with a workook to download... http://www.youtube.com/watch?v=...

2 days ago by TradeBrother on A quick fill handle trick for Microsoft Excel

waiting...

4 days ago by eapete on What should count in a company's market value?

Boy, you've opened a can of worms now.

Wait for the rants & raves.

4 days ago by eapete on What should count in a company's market value?

I was puzzling before this whether to replicate the success formula we executed for a financial institute, and come out with a standard s...

4 days ago by wykoong on Drop the egos, copy ideas, then innovate