Using Resource Profiler With .NET Applications

Applies to AQTime 8.81, last modified on January 18, 2022

The following sections describes how you can trace the usage of Windows resources in .NET applications:

About Tracing Windows Resources

The Resource profiler does not trace resource allocations and deallocations done with .NET objects. The profiler traces only the use of Windows resources.

There are two possible ways of working with Win32 API functions from a .NET application:
  • Calling via mscorwks.dll.

    Commonly, .NET applications work with Windows resources using the mscorwks.dll assembly that contains functions that allocate and deallocate resources. The mscorwks.dll assembly makes a call to the needed DLL for the needed function using the Import Address Table (IAT). The Resource profiler traces such calls to the Import Address Table and, thus, traces the usage of Windows resources.

    Note that to be able to trace resource allocations and deallocations, you need to add the mscorwks.dll assembly to your AQTime project (see the Preparing AQTime Project section below).

  • Calling via Platform Invocation Services.

    Another possible approach to calling native functions from the managed .NET code is using P/Invoke. When calling a method via P/Invoke, you specify an external method definition which the just-in-time compiler uses to wire managed code to an unmanaged function directly at runtime. Since the method is exported directly from a DLL, P/Invoke does not use Import Address Table. That is why, AQTime currently cannot track the use of Windows resources via P/Invoke.

You can use the Resource profiler to see how your managed (.NET-connected) application uses Windows resources. This will help you decide whether you need to optimize your application or not. For instance, if your application allocates too many GDI handles at some point of time, you may consider using other components or reducing the number of controls on forms.

Preparing AQTime Project

In .NET, the code that operates Windows resources resides in the mscorwks.dll assembly (that is, this assembly contains functions that allocate and release resources). You need to add this assembly to your AQTime project to make the profiler able to track the use of Windows resources in your application.

The assembly is part of Microsoft .NET Framework. You can find it in the <Windows>\Microsoft.NET\Framework\<framework_version> folder. If several versions of the .NET Framework are installed on your computer, add the assembly that is used by the Framework version that is appropriate for your application. For detailed instructions on adding modules to AQTime projects, see Selecting Applications and Modules to Profile.

Profiling .NET Applications

After you add the assembly, you can start the profiling. To get information on Windows resources that are used at certain point of the run, use the Get Results command. The profiler will generate results and display them in AQTime’s Report panel. Note that as mscorwks.dll does not have debug information, AQTime cannot trace the call stacks for allocated resources.

See Also

Resource Profiler
Resource Profiler - Overview
Profiling .NET Applications - Specifics

Highlight search results