Class QueryPerformanceRecorder

java.lang.Object
com.illumon.iris.db.tables.utils.QueryPerformanceRecorder
All Implemented Interfaces:
Serializable

public class QueryPerformanceRecorder
extends Object
implements Serializable
Query performance instrumentation tools. Manages a hierarchy of QueryPerformanceNugget instances.

Thread-safety note: This used to be thread-safe only by virtue of using a thread-local instance. Now it's aggressively synchronized so we can abort it from outside the "owner" thread.

See Also:
Serialized Form
  • Constructor Details

  • Method Details

    • getInstance

      public static QueryPerformanceRecorder getInstance()
    • resetInstance

      public static void resetInstance()
    • startQuery

      public void startQuery​(String description, com.fishlib.auth.UserContext primaryUserContext, com.fishlib.auth.UserContext operationUserContext)
      This is for use by the RemoteQueryProcessor. It should only be used by user classes in local queries.
      Parameters:
      description - the query's Action name
      primaryUserContext - the query's user context
      operationUserContext - the client's user context
    • startQuery

      @Deprecated public void startQuery​(String description)
      Deprecated.
      startQuery for backwards-compatibility in case any customer code happens to use it
      Parameters:
      description - the query's Action name
    • abortQuery

      public void abortQuery()
      This is for use by the RemoteQueryProcessor. It should only be used by user classes in local queries.
    • getState

      public QueryState getState()
      Return the query's current state
      Returns:
      the query's state or null if it isn't initialized yet
    • endQuery

      public boolean endQuery()
      This is for use by the RemoteQueryProcessor. It should only be used by user classes in local queries.
    • getNugget

      public QueryPerformanceNugget getNugget​(String name)
      Parameters:
      name - the nugget name
      Returns:
      A new QueryPerformanceNugget to encapsulate user query operations. done() must be called on the nugget.
    • getNugget

      public QueryPerformanceNugget getNugget​(String name, long inputSize)
      Parameters:
      name - the nugget name
      inputSize - the nugget's input size
      Returns:
      A new QueryPerformanceNugget to encapsulate user query operations. done() must be called on the nugget.
    • getOuterNugget

      public QueryPerformanceNugget getOuterNugget()
    • getOuterMostNugget

      public QueryPerformanceNugget getOuterMostNugget()
    • getQueryLevelPerformanceData

      public QueryPerformanceNugget getQueryLevelPerformanceData()
    • getPrimaryUserContext

      public com.fishlib.auth.UserContext getPrimaryUserContext()
    • getOperationUserContext

      public com.fishlib.auth.UserContext getOperationUserContext()
    • getOperationLevelPerformanceData

      public List<QueryPerformanceNugget> getOperationLevelPerformanceData()
    • getTimingResultsAsTable

      public Table getTimingResultsAsTable()
    • flushLocalInstance

      @Deprecated public static void flushLocalInstance()
      Deprecated.
      No longer used.
      See Also:
      startQuery(java.lang.String, com.fishlib.auth.UserContext, com.fishlib.auth.UserContext)
    • showLineNumbers

      @Deprecated public void showLineNumbers()
      Deprecated.
      Recording the caller line is now enabled for all nuggets by default.
    • recordPoolAllocation

      public static <RESULT_TYPE> RESULT_TYPE recordPoolAllocation​(@NotNull Supplier<RESULT_TYPE> operation)
      Record a single-threaded operation's allocations as "pool" allocated memory attributable to the current thread.
      Parameters:
      operation - The operation to record allocation for
      Returns:
      The result of the operation.
    • getPoolAllocatedBytesForCurrentThread

      public static long getPoolAllocatedBytesForCurrentThread()
      Get the total bytes of pool-allocated memory attributed to this thread via recordPoolAllocation(Supplier).
      Returns:
      The total bytes of pool-allocated memory attributed to this thread.
    • recordFirstTimeDataRead

      public static void recordFirstTimeDataRead​(long durationNanos)
    • recordRepeatedDataRead

      public static void recordRepeatedDataRead​(long durationNanos)
    • getFirstTimeDataReads

      public static long getFirstTimeDataReads()
    • getFirstTimeDataReadNanos

      public static long getFirstTimeDataReadNanos()
    • getRepeatedDataReads

      public static long getRepeatedDataReads()
    • getRepeatedDataReadNanos

      public static long getRepeatedDataReadNanos()
    • getCallerLine

      public static String getCallerLine()
    • withNugget

      public static void withNugget​(String name, com.fishlib.base.Procedure.Nullary r)
      Surround the given code with a Performance Nugget
      Parameters:
      name - the nugget name
      r - the stuff to run
    • withNugget

      public static <T> T withNugget​(String name, Supplier<T> r)
      Surround the given code with a Performance Nugget
      Parameters:
      name - the nugget name
      r - the stuff to run
      Returns:
      the result of the stuff to run
    • withNuggetThrowing

      public static <T extends Exception> void withNuggetThrowing​(String name, com.fishlib.base.Procedure.ThrowingNullary<T> r) throws T extends Exception
      Surround the given code with a Performance Nugget
      Parameters:
      r - the stuff to run
      Throws:
      T - exception of type T
      T extends Exception
    • withNuggetThrowing

      public static <R,​ ExceptionType extends Exception> R withNuggetThrowing​(String name, com.fishlib.base.Function.ThrowingNullary<R,​ExceptionType> r) throws ExceptionType extends Exception
      Surround the given code with a Performance Nugget
      Parameters:
      name - the nugget name
      r - the stuff to run
      Returns:
      the result of the stuff to run
      Throws:
      ExceptionType - exception of type ExceptionType
      ExceptionType extends Exception
    • withNugget

      public static void withNugget​(String name, long inputSize, com.fishlib.base.Procedure.Nullary r)
      Surround the given code with a Performance Nugget
      Parameters:
      name - the nugget name
      r - the stuff to run
    • withNugget

      public static <T> T withNugget​(String name, long inputSize, Supplier<T> r)
      Surround the given code with a Performance Nugget
      Parameters:
      name - the nugget name
      r - the stuff to run
      Returns:
      the result of the stuff to run
    • withNuggetThrowing

      public static <T extends Exception> void withNuggetThrowing​(String name, long inputSize, com.fishlib.base.Procedure.ThrowingNullary<T> r) throws T extends Exception
      Surround the given code with a Performance Nugget
      Parameters:
      r - the stuff to run
      Throws:
      T - exception of type T
      T extends Exception
    • withNuggetThrowing

      public static <R,​ ExceptionType extends Exception> R withNuggetThrowing​(String name, long inputSize, com.fishlib.base.Function.ThrowingNullary<R,​ExceptionType> r) throws ExceptionType extends Exception
      Surround the given code with a Performance Nugget
      Parameters:
      name - the nugget name
      r - the stuff to run
      Returns:
      the result of the stuff to run
      Throws:
      ExceptionType - exception of type ExceptionType
      ExceptionType extends Exception
    • setCallsite

      public static boolean setCallsite​(String callsite)

      Attempt to set the thread local callsite so that invocations of getCallerLine() will not spend time trying to recompute.

      This method returns a boolean if the value was successfully set. In the event this returns true, it's the responsibility of the caller to invoke clearCallsite() when the operation is complete.

      It is good practice to do this with try{} finally{} block

           final boolean shouldClear = QueryPerformanceRecorder.setCallsite("CALLSITE");
           try {
               // Do work
           } finally {
               if(shouldClear) {
                   QueryPerformanceRecorder.clearCallsite();
               }
           }
       
      Parameters:
      callsite - The call site to use.
      Returns:
      true if successfully set, false otherwise/
    • setCallsite

      public static boolean setCallsite()

      Attempt to compute and set the thread local callsite so that invocations of getCallerLine() will not spend time trying to recompute.

      Users should follow the best practice as described by setCallsite(String)

      Returns:
      true if the callsite was computed and set.
    • clearCallsite

      public static void clearCallsite()
      Clear any previously set callsite. See setCallsite(String)