dotTrace Help

API Usage Examples

To use the API for performance profiling:

  1. Download and unpack the profiling SDK.
  2. Reference the JetBrains.Profiler.Windows.Api assembly from the JetBrains.Profiler.Windows.Api.dll file located in the main directory of the dotTrace SDK.
  3. Insert calls to methods of the PerformanceProfiler class into your code as required by your use case. Consider the example below:
    private void SomeMethod() { if (PerformanceProfiler.IsActive) { PerformanceProfiler.Begin(); PerformanceProfiler.Start(); } // Here goes method code if (PerformanceProfiler.IsActive) { PerformanceProfiler.Stop(); PerformanceProfiler.EndSave(); } }
  4. Start profiling the application from within dotTrace, and select the Use profiler API check box in profiler options.

To use the API for timeline profiling:

  1. Download and unpack the profiling SDK.
  2. Reference the JetBrains.Profiler.Windows.Api assembly from the JetBrains.Profiler.Windows.Api.dll file located in the main directory of the dotTrace SDK.
  3. Insert calls to methods of the TimelineProfiler class into your code as required by your use case. Consider the example below:
    private void SomeMethod() { if (TimelineProfiler.IsActive) { TimelineProfiler.Begin(); } // Here goes method code if (TimelineProfiler.IsActive) { TimelineProfiler.EndSave(); } }
  4. Start profiling the application from within dotTrace, and select the Use profiler API check box in profiler options.

To use the API in self-profiled applications:

  1. Download and unpack the 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.Performance, ListFile = "C:\\snapshot_list.xml" });
  5. Insert calls to methods of the PerformanceProfiler or TimelineProfiler 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 (PerformanceProfiler.IsActive) { PerformanceProfiler.Begin(); PerformanceProfiler.Start(); } // and so on ...

See Also

Reference:

Last modified: 1 November 2015