Using custom profiler tags with Guidewire Profiler

It is possible to profile custom code in the Server Tools Guidewire Profiler by creating your own custom profiler tags. To define a custom profiler tag, create a globally-accessible Gosu class using the Java-based PCProfilerTag class as a model. Use only your custom class to add new profiler tags.

Defining a custom profiler tag

The following sample code illustrates how to create a custom Gosu class for new profiler tags.

package gw.profiler

 uses gw.api.profiler.ProfilerTag

 class MyProfilerTags {
  public static final var MY_TEST_TAG1 = new ProfilerTag("MyTestProfiler1")
  public static final var MY_TEST_TAG2 = new ProfilerTag("MyTestProfiler2")
  public static final var MY_TEST_TAG3 = new ProfilerTag("MyTestProfiler3")
  //..

   private construct() { 
    // Do not instantiate}
  }
}

Using a custom profiler tag

To profile a block of custom code, use the following pattern to push and pop profiling information onto the profiler stack.

uses gw.api.profile.Profiler
...

ProfilerFrame frame = Profiler.push(ProfilerTag.MY_TEST_TAG1)
try {
  // CODE TO PROFILE
} finally {
  Profiler.pop(frame)
}

Notice that the frame PUSH operation is outside the try block. The POP operation occurs in the try finally code. If you include the PUSH and POP operations inside code that iterates (a for loop, for example), each iteration of the code creates a new frame.

See also