API Usage Examples
To use the API for profiling your applications
Reference the JetBrains.Profiler.Windows.Api.dll* assembly (located in the %localappdata%JetBrains\Installations\dotMemory[N] directory) from your project.
- 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. // Check IsActive only once. Do nothing // (do not throw exceptions, etc.) if IsActive is false if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations) MemoryProfiler.EnableAllocations(); // Here goes your code // ... // Get a snapshot MemoryProfiler.Dump(); }
Start profiling the application from dotMemory, and select the Control profiling via API option in the Profiler Configuration dialog.
To use the API in self-profiled applications
Download and unpack the Profiling SDK.
Reference the
JetBrains.Profiler.Windows.SelfApi
assembly from the JetBrains.Profiler.Windows.SelfApi.dll file located in the main directory of the dotTrace SDK.Supply your app with the SDK redistributables.
Initiate self-profiling somewhere in your app using the
SelfAttach
class. For example:SelfAttach.Attach(new SaveSnapshotProfilingConfig() { ProfilingControlKind = ProfilingControlKind.Api, SaveDir = "C:\\Temp", RedistDir = "C:\\ProfilerSDK", ProfilingType = ProfilingType.Memory, ListFile = "C:\\snapshot_list.xml" // the file is created automatically during profiling });
- 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) // your code