dotMemory 10.0 Help

API Usage Examples

To use the API for profiling your applications:

  1. Reference the JetBrains.Profiler.Windows.Api.dll* assembly (located in the %localappdata%JetBrains\Installations\dotMemory[N] 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.CanControlAllocations) 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.

To use the API in self-profiled applications:

  1. Download and unpack the dotTrace profiling SDK.
  2. Reference the JetBrains.Profiler.Windows.SelfApi assembly from the JetBrains.Profiler.Windows.SelfApi.dll file located in the main directory of the dotTrace SDK.
  3. Supply your app with the SDK redistributables.
  4. Initiate self-profiling somewhere in your app using the SelfAttach class. For example:
    SelfAttach.Attach(new SaveSnapshotProfilingConfig() { ProfilingControlKind = ProfilingControlKind.Api, TempDir = Path.GetTempPath(), SaveDir = "C:\\Temp", RedistDir = "C:\\ProfilerSDK", ProfilingType = ProfilingType.Memory, ListFile = "C:\\snapshot_list.xml" });
  5. Insert calls to methods of the MemoryProfiler class into your code as required by your use case. If you start profiling right after the self-profiling initialization, add a short wait (the SelfAttach API requires some time to start):
    while (SelfAttach.State != SelfApiState.Active) Thread.Sleep(250); // wait until API starts if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations) MemoryProfiler.EnableAllocations(); // and so on ...

See Also

Reference:

Last modified: 13 January 2016