Interface Profiler

All Known Implementing Classes:
EmptyProfiler, LoggingProfiler, ValidatingProfiler

public sealed interface Profiler permits EmptyProfiler, LoggingProfiler, ValidatingProfiler
Interface supporting profiling calls for measuring and saving runtime performance.

Operates on the idea of a "profile stack", which is just a stack of names with associated profiling metrics. For instance, the following code

 
 Profiler profiler = someProfiler();
 profiler.startTick();
 profiler.push("Hello")
 someExpensiveFunction();
 profiler.swap("World")
 someLessExpensiveFunction();
 profiler.pop();
 profiler.endTick();
 
 

will produce a profile with three sections:

A call to profiler.save() would output the performance metrics of these sections in the case of a LoggingProfiler.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called at the bottom of the main loop.
    void
    pop()
    The profile stack is popped.
    void
    push(String location)
    The profile stack is pushed with the location as its top.
    void
    Reset logger.
    void
    Write profile data to a file.
    void
    Called at the top of the main loop.
    default void
    swap(String location)
    The top of the profile stack is replaced with location.
  • Method Details

    • startTick

      void startTick()
      Called at the top of the main loop. Indicates the profiler is at "root" and records the start time. Within the main loop, no meaningful work should occur before this call.
      Throws:
      RuntimeException - if called twice without a call to endTick in between.
    • endTick

      void endTick()
      Called at the bottom of the main loop. Indicates the profiler's "root" is finished, and its time usage metrics are updated. Within the main loop, no meaningful work should occur after this call.
      Throws:
      RuntimeException - if the profile stack is not empty or startTick has not been called.
    • push

      void push(String location)
      The profile stack is pushed with the location as its top. Must be accompanied by a call to pop.
      Throws:
      RuntimeException - if startTick hasn't been called yet.
    • pop

      void pop()
      The profile stack is popped. Must be preceded (at some point) by a call to push.
      Throws:
      RuntimeException - if startTick hasn't been called yet or the profile stack is empty.
    • swap

      default void swap(String location)
      The top of the profile stack is replaced with location. This is equivalent to a call to pop followed immediately by a call to push.
      Throws:
      RuntimeException - if the profile stack is empty.
    • save

      void save()
      Write profile data to a file.
    • reset

      void reset()
      Reset logger.