How to profile a .NET Windows Application outside of the VS.NET IDE

0 Likes

Problem:

How to profile a .NET Windows application using Coverage or Performance Analysis outside of the VS.NET IDE?

Resolution:

Unlike C and VB6 applications, the DevPartner Performance and Coverage Analysis profilers do not Instrument your code. Instead, all of the profiling is done during runtime.

This is accomplished by creating some environment variables that the Common Language Runtime (CLR) checks for when any .NET managed code process starts.

Using the values of these environment variables, the CLR creates a COM connection to our profiler. The profiler then receives notifications from the CLR each time a function is entered or exited, as well as when other events occur that are of interest.

At version 7.X - there are two ways to do this. You can...

Run your program from the Coverage or Performance Analysis stand-alone applications by following these steps:


  1. Go to Start -> Programs -> Compuware DevPartner Studio
  2. Select Coverage or Performance Analysis from the menu.
  3. Go to File -> Open
  4. Change the 'Files of Type' to 'Executable Files'
  5. Browse to your applications executable

Press F5 to start your application

- or -

You can set environment variables that will be read by the CLR. One tells the CLR that a profiler has been defined to start and the other is a GUID to a COM interface for the profiler. The CLR then uses the GUID to create the COM object.

It is important to note that if you set these as System Environment Variables, then every new .NET Process that starts will be profiled at the same time.

We recommend that you do not set these environment variables at the System Level unless you are profiling a service or Add-in. Instead we have installed a batch file named 'AnalysisCommonEnv.bat' located in a sub-folder called 'Analysis' where DevPartner Studio was installed.

To use the batch file:


  1. Open a DOS Window
  2. Execute the AnalysisCommonEnv.bat batch file to setup the environment for profiling. using one of these parameters /performance or /coverage to enable the DevPartner Profiling. (The default is Performance)

    Now start your executable from the same DOS window. By doing it from a command window the environment changes will only exist in any process that is started from that window.

    If you choose to add them to the System Environment you should follow these instructions:

There are 2 environment variables read by the CLR, they are:

COR_ENABLE_PROFILING = 1 
COR_PROFILER = {372DC2B6-0A34-4f22-BC34-BE7A18DE9137} 

And there are 2 more that our COM Component uses to decide whether we are doing Coverage or Performance Analysis.

For Coverage Analysis they are:

NM_DOING_COVERAGE = 1
NM_ANALYSIS = cov 

For Performance Analysis they are:

NM_DOING_COVERAGE = 0 
NM_ANALYSIS = perf 

For version 8.0 use the "DPAnalysis.exe" utility to profile from the command line.

DPAnalysis [/Perf|/Cov|/Mem|/Exp] [/E|/D] [/wait] [/O outputfilename] 
[/W workingdirectory] [/H hostmachine] 
[/NO_MACH5 /NM_METHOD_GRANULARITY /EXCLUDE_SYSTEM_DLLS
/NM_ALLOW_INLINING /NO_OLEHOOKS /NM_TRACK_SYSTEM_OBJECTS] 
{/P|/S} target [target arguments]

Analysis Type Switches

Sets the run-time analysis type. Optional: Performance is the default. Required to specify an analysis type other than Performance.

/Cov[erage] Sets analysis type to DevPartner Coverage Analysis

/Exp[ert] Sets analysis type to DevPartner Performance Expert

/Mem[ory] Sets analysis type to DevPartner Memory Analysis

/Perf[ormance] Sets analysis type to DevPartner Performance Analysis

Data Collection Switches

Enables or disables data collection for a given target, but does not launch the target. Optional.

/E[nable] Enables data collection for the specified process or service

/D[isable] Disables data collection for the specified process or service

Other Switches -  optional.

/wait The /wait switch enables you to control when target applications are launched when you include multiple targets in a batch file. For example:

DPAnalysis /exp /wait c:\temp\process1.exe

DPAnalysis /exp /wait c:\temp\process2.exe

DPAnalysis will not launch process2 until process1 has exited. If the /wait switches were omitted, process2 would be run immediately.

/O[utput] Specify the session file output directory or directory and name.

/W[orkingDir] Specify the working directory for the target process or service.

/H[ost] Specify target's host machine.

/NOWAIT Do not wait for process to exit, just wait for it to start.

/N[ewconsole] Run the process in its own command window.

Quoted Paths and the /O[utput] Switch

If you use a quoted path as the parameter for the output (/o) switch and you do not include the file name, you must end the path in one of the following ways:

/o "c:\test directory" End with a quote.  

/o "c:\test directory\." End with a back slash followed by a period.

/o "c:\test directory/" End with a forward slash.

AnalysisOptions - optional.

/NO_MACH5 Disables excluding time spent on other threads

/NM_METHOD_GRANULARITY Sets data collection granularity to method-level (line-level is default)

/EXCLUDE_SYSTEM_DLLS Excludes data collection for system dlls (Performance only)

/NM_ALLOW_INLINING Enable run-time instrumentation of inline methods

/NO_OLEHOOKS Disable collection of COM

/NM_TRACK_SYSTEM_OBJECTS Track system object allocation (Memory only)

Target Switch

Identifies target to follow as either a process or service. Required. Pick only one. All arguments that follow the target name or path will be arguments to the target.

/P[rocess] Specify a target process (followed by arguments to process)

/S[ervice] Specify a target service (followed by arguments to service)

/C[onfig] Path to configuration file

Old KB# 10987
Comment List
Anonymous
Related Discussions
Recommended