dotMemory Web Help

The dotMemory API lets you control profiling directly from the code of the profiled application. By using API classes, you can configure profiling options and get memory snapshots right from your app.

The main usage scenario of the API is profiling a specific part of the code. Typically, if your app is quite huge, you don't need to profile it entirely. The main point of your interest is memory issues in a certain module, memory usage of a particular method, and so on. The dotMemory API allows you to narrow the profiling scope by getting snapshots in the exact places of your code.

This chapter is a brief overview of how the API works.

How the API Works

The following list summarizes main API profiling concepts:

  • To control the profiling process, the API uses the static MemoryProfiler class located in the JetBrains.Profiler.Windows.Api.dll assembly.
  • The MemoryProfiler.IsActive property is used to determine whether the API is enabled.
  • To enable the API, you should select the Use profiler API checkbox in the Profiler Configuration dialog box.
  • MemoryProfiler.Dump initiates snapshot generation and processing.
  • In case you attach dotMemory to an already running process, you should use MemoryProfiler.Detach for detaching from the process in the end of the profiling session.
To use the API for profiling your applications:
  1. Reference the JetBrains.Profiler.Windows.Api.dll* assembly (located in the % dotMemory % \Bin directory) from your project.
  2. Insert calls to methods of the MemoryProfiler class into your code as required by your use case. Consider the example below:
                    private void SomeMethod()
                    {
                        // Enable collecting memory allocation data
                        if (MemoryProfiler.IsActive)
                            MemoryProfiler.EnableAllocations();
    
                        // Here goes your code
                        // ...
    
                        // Get a snapshot
                        if (MemoryProfiler.IsActive)
                            MemoryProfiler.Dump();
                    }
                
  3. Start profiling the application from dotMemory, and select the Control profiling via API option in the Profiler Configuration dialog box.

Note

* JetBrains.Profiler.Core.Api.dll in dotMemory 4.1 and earlier.

Properties of the MemoryProfiler Class

Name Type Description
IsActive bool Check whether the API is enabled.
CanControlAllocations bool Check whether the recording of the creation stack trace information is turned on.
CanControlTraffic bool Check whether the recording of the traffic information is turned on.
CanDetach bool Check whether the profiler was attached to an already running application.

Methods of the MemoryProfiler Class

Name Description
Dump Get a memory snapshot.
EnableAllocations Turn on recording of the creation stack trace information.
DisableAllocations Turn off recording of the creation stack trace information.
EnableTraffic Turn on recording of the traffic information.
DisableTraffic Turn off recording of the traffic information.
Detach Detach dotMemory from the profiled process. This method is suitable only in case you attach the profiler to an already running process.

API State Machine

API_state_machine

See Also

How tos: