• Print
  • Share
  • Dark
    Light

Profile Methods in Your Code

  • Updated on 02 Jul 2018
  • 2 minutes to read
  • Contributors

By default, the Retrace .NET profiler only instruments specific methods in the ASP.NET pipeline and supported 3rd party libraries. One of the key benefits of the profiler is that you may instrument tracing of how long any .NET method takes to execute and include that output in the call stack.

In deciding what to profile, keep in mind the overhead that could be incurred. For example, if you choose to use a wildcard configuration as described below, all .NET properties that have Get and Set accessors (which includes dynamic properties) will be profiled via these accessors, and can be quite high in volume.

Advanced Custom Configuration

Note: This section describes how to customize the Retrace .NET Profiler to add instrumentation. Any changes made to the configuration file must be formatted properly at the risk of causing instability.

To add custom configuration:

  • Create a configuration file named ProfileClientConfig.txt per the format described below.
  • Save to your installation folder ([Install Drive]:\Program Files (x86)\Stackify\ProfileClientConfig.txt).

In the ProfileClientConfig.txt configuration file you created, you will need to create a JSON format document that allows you to specify methods you wish to profile. The document follows this format:

[{
	"Class": "MyNamespace.MyClass",
	"Method": "MyMethod"
},
{
	"Class": "MyNamespace.MyClass2",
	"Method": "MyMethod"
}]

A wildcard of “*” may be used for both Class and Method properties. It is not recommended to use the wildcard character for a namespace, as that will key the profiler to instrument every single .NET method call. Please note that every tracked method adds overhead to your application and will slow it down slightly. Adding a few methods picked up per web request is no big deal, however, a wildcard for something like System.Data.* is a bad idea and could crash your application. Valid options are:

[{
	"Class": "MyNamespace.MyClass",
	"Method": "*"
},
{
	"Class": "MyNamespace.*",
	"Method": "*"
}]

Please ensure to follow proper JSON document formatting. Incorrect formatting will prevent the profiler from starting. Once the ProfileClientConfig.txt file is created, be sure to save the file and recycle the IIS application pool for your app.

It is also important to know that the namespaces and method names may vary from what you think they are. The actual method names used by CLR vary due to things like interfaces, private classes, compilation optimization and call tailing.

Configuring Azure App Services & WebJobs

  • The process is the same for Azure App Services, just be sure to include the ProfileClientConfig.txt file in the bin folder when you deploy your app.
  • The process for Azure WebJobs is to include the ProfileClientConfig.txt file in the same folder as the .exe that is being profiled.

For continuous web jobs:

D:\home\site\wwwroot\app_data\jobs\continuous\\[MyWebJob]\ProfileClientConfig.txt

For triggered web jobs:

D:\home\site\wwwroot\app_data\jobs\triggered\\[MyWebJob]\ProfileClientConfig.txt