Diagnostic And Performance Monitoring in .Net 4.0


There are a number of tools and utilities available to monitor and tune your .Net application's performance. The .Net framework itself provides a very good infrastructure for performance monitoring and analysis.

In this article we will have a look at what is newer in .Net 4.0 to help determine the problem area or scope for improvements in your program.

Allows the user to monitor application domain level Memory and Processor usage statistics. Previous to .Net 4.0 we had limited APIs available, which can provide support for reading only the Process level memory usage and CPU usage information. In 4.0 you have access to Processor and Memory usage estimates for a given application domain.

The application domain based resource monitoring feature is available in:

  • Hosting APIs and
  • Event Tracing for Windows(ETW).

By default, application domain level resource monitoring is disabled. This feature has to be enabled in a process to get application domain level resouce consumption details within that process.
The AppDomain class has been enhanced to provide support for this new feature. A process can enable this feature using the AppDomain class's static property MonitoringIsEnabled.

(bool) AppDomain.MonitoringIsEnabled

It is a boolean property. Once this property is enabled in the process, it stays active until the process exits. You can assign only the value 'true'; even though it is a boolean property, assigning the value 'false' to this property causes an Invalid Argument exception.

The AppDomain class provides the following properties to access the Appdomain's resource usage.

AppDomain.MonitoringSurvivedMemorySize

It is a readonly instance property. Provides the number of bytes which is currently allocated by the Appdomain in the managed heap. In other words this property provides the size of memory which is survived the last cycle of garbage collection. This property is updated only after a full, blocking collection occurred.

AppDomain.MonitoringSurvivedProcessMemorySize

It is a readonly static property, provides the number of bytes currently allocated by the current process in the managed heap memory. This an equivalent of GC.GetTotalMemory property.

AppDomain.MonitoringTotalAllocatedMemorySize


This is a readonly instance property. It returns the total size, in bytes, of all memory allocations that have been made by the application domain since it was created, without subtracting memory that has been collected.

AppDomain.MonitoringTotalProcessorTime

It is a readonly instance property. Returns the total processor time utilized by the application domain since the process started. The total time reported by this property includes the time each thread in the process spent executing in that application domain.

The excution time of unmanaged calls made by an application domain, is also counted for that application domain.

The sleeping time of a thread is not counted in association with the application domain's processor usage.

Using Event Tracing for Windows (ETW)


You can now access the ETW events for diagnostic purposes to improve performance. Watch for the next article to know more.

 

Up Next
    Ebook Download
    View all
    Learn
    View all