Interface QueryPerformanceRecorder
- All Known Implementing Classes:
QueryPerformanceRecorderImpl
public interface QueryPerformanceRecorder
Query performance instrumentation tools. Manages a hierarchy of
QueryPerformanceNugget
instances.-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Abort a query.void
accumulate
(@NotNull QueryPerformanceRecorder subQuery) Accumulate performance information from another recorder into this one.static void
Clear any previously set callsite.boolean
endQuery()
End a query.static String
getCompilationNugget
(@NotNull String name) Create a nugget at the top of the user stack for a compilation task.This is the nugget enclosing the current operation.static QueryPerformanceRecorder
default QueryPerformanceNugget
Create a nugget at the top of the user stack.Create a nugget at the top of the user stack.This getter should be called by exclusive owners of the recorder, and never concurrently with mutators.getState()
Return the query's current stateboolean
static QueryPerformanceRecorder
newQuery
(@NotNull String description, @Nullable String sessionId, QueryPerformanceNugget.Factory nuggetFactory) Construct a QueryPerformanceRecorder for a top-level query.static QueryPerformanceRecorder
newSubQuery
(@NotNull String description, @Nullable QueryPerformanceRecorder parent, QueryPerformanceNugget.Factory nuggetFactory) Construct a QueryPerformanceRecorder for a sub-level query.static <RESULT_TYPE>
RESULT_TYPErecordPoolAllocation
(@NotNull Supplier<RESULT_TYPE> operation) Record a single-threaded operation's allocations as "pool" allocated memory attributable to the current thread.Resumes a suspend query.static boolean
Attempt to compute and set the thread local callsite so that invocations ofgetCallerLine()
will not spend time trying to recompute.static boolean
setCallsite
(@NotNull String callsite) Attempt to set the thread local callsite so that invocations ofgetCallerLine()
will not spend time trying to recompute.Starts a query.void
supplyQueryData
(@NotNull QueryPerformanceRecorder.QueryDataConsumer consumer) Provide current query data via the consumer.void
Suspends a query.static void
withNugget
(String name, long inputSize, Runnable r) Surround the given code with a Performance Nuggetstatic <T> T
withNugget
(String name, long inputSize, Supplier<T> r) Surround the given code with a Performance Nuggetstatic void
withNugget
(String name, Runnable r) Surround the given code with a Performance Nuggetstatic <T> T
withNugget
(String name, Supplier<T> r) Surround the given code with a Performance Nuggetstatic <T extends Exception>
voidwithNuggetThrowing
(String name, long inputSize, ThrowingRunnable<T> r) Surround the given code with a Performance Nuggetstatic <R,
ExceptionType extends Exception>
RwithNuggetThrowing
(String name, long inputSize, ThrowingSupplier<R, ExceptionType> r) Surround the given code with a Performance Nuggetstatic <T extends Exception>
voidwithNuggetThrowing
(String name, ThrowingRunnable<T> r) Surround the given code with a Performance Nuggetstatic <R,
ExceptionType extends Exception>
RwithNuggetThrowing
(String name, ThrowingSupplier<R, ExceptionType> r) Surround the given code with a Performance Nugget
-
Field Details
-
UNINSTRUMENTED_CODE_DESCRIPTION
- See Also:
-
-
Method Details
-
getInstance
-
getNugget
Create a nugget at the top of the user stack. May return aQueryPerformanceNugget.DUMMY_NUGGET
if no recorder is installed.- Parameters:
name
- the nugget name- Returns:
- A new QueryPerformanceNugget to encapsulate user query operations.
QueryPerformanceNugget.close()
must be called on the nugget.
-
getNugget
Create a nugget at the top of the user stack. May return aQueryPerformanceNugget.DUMMY_NUGGET
if no recorder is installed.- Parameters:
name
- the nugget nameinputSize
- the nugget's input size- Returns:
- A new QueryPerformanceNugget to encapsulate user query operations.
QueryPerformanceNugget.close()
must be called on the nugget.
-
getCompilationNugget
Create a nugget at the top of the user stack for a compilation task. May return aQueryPerformanceNugget.DUMMY_NUGGET
if no recorder is installed.- Parameters:
name
- the nugget name- Returns:
- A new QueryPerformanceNugget to encapsulate the compilation.
QueryPerformanceNugget.close()
must be called on the nugget.
-
getEnclosingNugget
QueryPerformanceNugget getEnclosingNugget()This is the nugget enclosing the current operation. It may belong to the dummy recorder, or a real one.- Returns:
- Either a "catch-all" nugget, or the top of the user nugget stack.
-
supplyQueryData
Provide current query data via the consumer.- Parameters:
consumer
- a callback to receive query data
-
getCallerLine
- Returns:
- The current callsite. This is the last set callsite or the line number of the user's detected callsite.
-
setCallsite
Attempt to set the thread local callsite so that invocations ofgetCallerLine()
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
static boolean setCallsite()Attempt to compute and set the thread local callsite so that invocations ofgetCallerLine()
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
static void clearCallsite()Clear any previously set callsite. SeesetCallsite(String)
-
newQuery
static QueryPerformanceRecorder newQuery(@NotNull @NotNull String description, @Nullable @Nullable String sessionId, @NotNull QueryPerformanceNugget.Factory nuggetFactory) Construct a QueryPerformanceRecorder for a top-level query.- Parameters:
description
- the query descriptionnuggetFactory
- the nugget factory- Returns:
- a new QueryPerformanceRecorder
-
newSubQuery
static QueryPerformanceRecorder newSubQuery(@NotNull @NotNull String description, @Nullable @Nullable QueryPerformanceRecorder parent, @NotNull QueryPerformanceNugget.Factory nuggetFactory) Construct a QueryPerformanceRecorder for a sub-level query.- Parameters:
description
- the query descriptionnuggetFactory
- the nugget factory- Returns:
- a new QueryPerformanceRecorder
-
recordPoolAllocation
static <RESULT_TYPE> RESULT_TYPE recordPoolAllocation(@NotNull @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.
-
getState
QueryState getState()Return the query's current state- Returns:
- the query's state
-
startQuery
SafeCloseable startQuery()Starts a query.A query is
RUNNING
if it has been started orresumed
without a subsequentend
,suspend
, orabort
.- Throws:
IllegalStateException
- if the query state isn'tNOT_STARTED
or another query is running on this thread
-
endQuery
boolean endQuery()End a query.A query is
RUNNING
if it has beenstarted
orresumed
without a subsequent end,suspend
, orabort
.- Returns:
- whether the query should be logged
- Throws:
IllegalStateException
- if the query state isn'tRUNNING
,INTERRUPTED
, or was not running on this thread
-
suspendQuery
void suspendQuery()Suspends a query.A query is
RUNNING
if it has beenstarted
orresumed
without a subsequentend
, suspend, orabort
.- Throws:
IllegalStateException
- if the query state isn'tRUNNING
or was not running on this thread
-
resumeQuery
SafeCloseable resumeQuery()Resumes a suspend query.A query is
RUNNING
if it has beenstarted
or resumed without a subsequentend
,suspend
, orabort
.- Throws:
IllegalStateException
- if the query state isn'tSUSPENDED
or another query is running on this thread
-
abortQuery
void abortQuery() -
getQueryLevelPerformanceData
QueryPerformanceNugget getQueryLevelPerformanceData()- Returns:
- the query level performance data
-
getOperationLevelPerformanceData
List<QueryPerformanceNugget> getOperationLevelPerformanceData()This getter should be called by exclusive owners of the recorder, and never concurrently with mutators.- Returns:
- A list of loggable operation performance data.
-
accumulate
Accumulate performance information from another recorder into this one. The provided recorder will not be mutated.- Parameters:
subQuery
- the recorder to accumulate into this
-
hasSubQueries
boolean hasSubQueries()- Returns:
- whether a sub-query was ever accumulated into this recorder
-
withNugget
Surround the given code with a Performance Nugget- Parameters:
name
- the nugget namer
- the stuff to run
-
withNugget
Surround the given code with a Performance Nugget- Parameters:
name
- the nugget namer
- the stuff to run- Returns:
- the result of the stuff to run
-
withNuggetThrowing
Surround the given code with a Performance Nugget- Parameters:
r
- the stuff to run- Throws:
T
- exception of type T
-
withNuggetThrowing
static <R,ExceptionType extends Exception> R withNuggetThrowing(String name, ThrowingSupplier<R, ExceptionType> r) throws ExceptionTypeSurround the given code with a Performance Nugget- Parameters:
name
- the nugget namer
- the stuff to run- Returns:
- the result of the stuff to run
- Throws:
ExceptionType
- exception of type ExceptionType
-
withNugget
Surround the given code with a Performance Nugget- Parameters:
name
- the nugget namer
- the stuff to run
-
withNugget
Surround the given code with a Performance Nugget- Parameters:
name
- the nugget namer
- the stuff to run- Returns:
- the result of the stuff to run
-
withNuggetThrowing
static <T extends Exception> void withNuggetThrowing(String name, long inputSize, ThrowingRunnable<T> r) throws T Surround the given code with a Performance Nugget- Parameters:
r
- the stuff to run- Throws:
T
- exception of type T
-
withNuggetThrowing
static <R,ExceptionType extends Exception> R withNuggetThrowing(String name, long inputSize, ThrowingSupplier<R, ExceptionType> r) throws ExceptionTypeSurround the given code with a Performance Nugget- Parameters:
name
- the nugget namer
- the stuff to run- Returns:
- the result of the stuff to run
- Throws:
ExceptionType
- exception of type ExceptionType
-