Telerik® JustTrace™ by Progress

The Telerik JustTrace's Profiler API allows direct integration between your source code and the profiling sessions.

The JustTrace's Profiler API is separated in two controller classes, both coming from the same namespace (Telerik.JustTrace.Profiler.Api), the MemoryController and the PerformanceController class. The Memory Controller finds its place for optimizing the memory usage of your program or/and identifying memory leaks in it. The Performance Controller on the other hand is used for measuring how fast certain operations actually are.

Usage

Important

You need to have JustTrace installed, in order to use the profiler API

  1. First, open the project you want to profile inside Visual Studio and refer the Telerik.JustTrace.Profiler.Api.DLL in it. You will find that DLL in the JustTrace's install folder, under Libraries (by default: "C:\Program Files (x86)\Telerik\JustTrace\Libraries\Telerik.JustTrace.Profiler.Api.dll").

  2. After this, you will need to import the API to the corresponding namespaces (using Telerik.JustTrace.Profiler.Api;).

  3. Continue by adding the profiler commands from the JustTrace's Profiler API to your source code. Below, you will find a complete API reference about what can be used and where to put it.

  4. Setup your project for profiling within Visual Studio, or the JustTrace standalone client and run it with enabled profiler. While running, the execution of the application will go through the JustTrace Profiler API commands and will perform the needed actions for you.

    Note

    For performance profiling it is recommended to start the profiling sessions with the Disabled at Start option. This will avoid the gathering of unnecessary information, as the Profiler API will enable the profiler from the code when needed.

  5. Finally, examine the results in the JustTrace Session window within Visual Studio, or the standalone client.

Memory Controller

The Memory Controller allows the profiled applications to control the JustTrace Memory profiler. Using it, you will be able to get snapshots in an exact moment of your code execution.

API References:

CopyC#
namespace Telerik.JustTrace.Profiler.Api
{
  /// Allows profiled applications to control the JustTrace Memory profiler
  public static class MemoryController
  {
    /// Returns true if the JustTrace's profiling module is loaded in the current process
    public static bool IsProfilerAttached { get; }

    /// Creates a new memory snapshot.
    /// The throwOnError parameter determines whether to throw an exception if the profiler is not loaded or to silently ignore it
    /// A ProfilerNotAttachedException is thrown if the profiler is not loaded in the current process.
    public static void GetSnapshot(bool throwOnError = true) { }
  }
}

Sample code from the Demo.RayTracer project:

CopyC#
private void StopRender()
{

  // Some code here
  // .  .  .

  // Gets a snapshot right after the rendering is over
  MemoryController.GetSnapshot(true);
}
The above code shows how you can get a memory snapshot in an exact moment of your application's execution. In this case, we are getting a snapshot right after the rendering process has finished. This will show us if the memory is released as expected or there are leaks.

Performance Controller

The Performance Controller controls the JustTrace's Sampling or Tracing profiler (this can be controlled from the JustTrace's UI and depends on its current state). Currently, the controller only enables, or disables the profilers allowing you to profile an exact portion of your code with extreme accuracy.

API References:

CopyC#
namespace Telerik.JustTrace.Profiler.Api
{
  /// Allows profiled applications to control the JustTrace Sampling and Tracing profilers
  public static class PerformanceController
  {
    /// Returns true if the JustTrace's profiling module is loaded in the current process
    public static bool IsProfilerAttached { get; }

    /// Enables/Disables the performance profiler
    /// A ProfilerNotAttachedException is thrown if the profiler is not loaded in the current process
    public static bool IsProfilerEnabled { get; set; }

    /// Enables/Disables the performance profiler without throwing an exception if the profiler is not available
    public static bool IsProfilerEnabledNoThrow { get; set; }
  }
}

Sample code from the Demo.RayTracer project:

CopyC#
private void StartRender(int threadsCount)
{
  // Start the profiler.
  PerformanceController.IsProfilerEnabled = true;

  // Some code here
  // .  .  .

  // Stop the profiler.  
  PerformanceController.IsProfilerEnabled = false;
}
The above example shows how the performance profiler can be enabled only for certain piece(s) of your code. This eliminates the unnecessary parts, so that JustTrace can visualize only this and you can see the actual measurement.